From: 2weiEmu Date: Thu, 12 Mar 2026 00:32:58 +0000 (+0100) Subject: updated: some handling, can count songs and makefile better X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=8d8b2058fba17e5ee5660b7aaa0de7da2c92b6cb;p=binbsis50-sm.git updated: some handling, can count songs and makefile better --- diff --git a/Makefile b/Makefile index 073dee5..a9aceee 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,12 @@ default: . # first we must setup the test database - sudo docker stop redis || true - sudo docker rm redis || true sudo docker run -d --name redis -p 6379:6379 redis:latest python3 ./testing/dummy_testing_data.py # now we can run the main app with the right arguments go build . - ./songmanager -port 8000 -binb_location="" -songs_location="" -redis_location="localhost:6379" -container_name="" + ./songmanager -port 8000 -binb_location="" -songs_location="" -redis_location="localhost:6379" -container_name="" || true + + docker stop redis || true + docker rm redis || true diff --git a/pkg/dbhandling/dbhandling.go b/pkg/dbhandling/dbhandling.go index bf16812..9111ba9 100644 --- a/pkg/dbhandling/dbhandling.go +++ b/pkg/dbhandling/dbhandling.go @@ -2,12 +2,16 @@ package dbhandling import ( "context" - "fmt" + "encoding/json" "net/http" "github.com/redis/go-redis/v9" ) +type DBStatusMessage struct { + TotalSongCount int +} + type DBWrapper struct { RedisDb *redis.Client ctx context.Context @@ -31,5 +35,19 @@ func (dbw *DBWrapper) GetDBStatus(w http.ResponseWriter, r *http.Request) { return } - fmt.Println(dbw.RedisDb.Keys(dbw.ctx, "song")) + keys, err := dbw.RedisDb.Keys(dbw.ctx, "song:*").Result() + if err != nil { + panic(err) + } + key_count := len(keys) + + m := DBStatusMessage{ + TotalSongCount: key_count, + } + b, err := json.Marshal(m) + if err != nil { + panic(err) + } + + w.Write(b) } diff --git a/songmanager b/songmanager index a163903..0796529 100755 Binary files a/songmanager and b/songmanager differ diff --git a/testing/dummy_testing_data.py b/testing/dummy_testing_data.py index 82c80a8..3dd24c2 100644 --- a/testing/dummy_testing_data.py +++ b/testing/dummy_testing_data.py @@ -1,5 +1,6 @@ import redis + def main(): r = redis.Redis(host="localhost", port="6379", decode_responses=True) @@ -8,9 +9,7 @@ def main(): "artistNames": "firstartist, secondartist", "songNames": "firstsongname, secondsongname" }) - r.zadd("hits", { i: i } ) - - + r.zadd("hits", {i: i}) if __name__ == "__main__":