diff --git a/database/db.go b/database/db.go index 3da0b5a..911d995 100644 --- a/database/db.go +++ b/database/db.go @@ -358,8 +358,28 @@ func (db *Instance) DecrementConcurrency(m3uIndex int) error { } func (db *Instance) ClearConcurrencies() error { - if err := db.Redis.Del(db.Ctx, "concurrency:*").Err(); err != nil { - return fmt.Errorf("error clear concurrencies from Redis: %v", err) + var cursor uint64 + var err error + var keys []string + + for { + var scanKeys []string + scanKeys, cursor, err = db.Redis.Scan(db.Ctx, cursor, "concurrency:*", 0).Result() + if err != nil { + return fmt.Errorf("error scanning keys from Redis: %v", err) + } + keys = append(keys, scanKeys...) + if cursor == 0 { + break + } + } + + if len(keys) == 0 { + return nil + } + + if err := db.Redis.Del(db.Ctx, keys...).Err(); err != nil { + return fmt.Errorf("error deleting keys from Redis: %v", err) } return nil diff --git a/stream_handler.go b/stream_handler.go index fe9543e..16436e1 100644 --- a/stream_handler.go +++ b/stream_handler.go @@ -205,6 +205,12 @@ func proxyStream(ctx context.Context, m3uIndex int, resp *http.Response, r *http func streamHandler(w http.ResponseWriter, r *http.Request, db *database.Instance) { debug := os.Getenv("DEBUG") == "true" + if r.Method != http.MethodGet { + w.WriteHeader(http.StatusMethodNotAllowed) + _, _ = w.Write([]byte(fmt.Sprintf("HTTP method %q not allowed", r.Method))) + return + } + ctx, cancel := context.WithCancel(r.Context()) defer cancel()