diff --git a/go.mod b/go.mod index 7c45191..e8268b5 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,13 @@ toolchain go1.24.12 require ( github.com/lib/pq v1.11.1 + github.com/redis/go-redis/v9 v9.17.3 modernc.org/sqlite v1.44.3 ) require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect diff --git a/go.sum b/go.sum index 96d44c3..3cab3f0 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,11 @@ +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= @@ -12,6 +20,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/redis/go-redis/v9 v9.17.3 h1:fN29NdNrE17KttK5Ndf20buqfDZwGNgoUr9qjl1DQx4= +github.com/redis/go-redis/v9 v9.17.3/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY= diff --git a/src/config.go b/src/config.go index 38bdb72..b26f0b7 100644 --- a/src/config.go +++ b/src/config.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" "os" + + valkey "github.com/redis/go-redis/v9" ) type Config struct { @@ -11,6 +13,8 @@ type Config struct { ConnectionDriver string `json:"CONNECTION_DRIVER"` ConnectionString string `json:"CONNECTION_STRING"` db DB + KeyValueURL string `json:"KEY_VALUE_URL"` + keyValue *valkey.Client } func NewConfig(ctx context.Context) (Config, error) { @@ -19,8 +23,20 @@ func NewConfig(ctx context.Context) (Config, error) { return config, err } + opt, err := valkey.ParseURL(config.KeyValueURL) + if err != nil { + return config, err + } + client := valkey.NewClient(opt) + if err := client.Ping(ctx).Err(); err != nil { + client.Close() + return config, err + } + config.keyValue = client + db, err := NewDB(ctx, config.ConnectionDriver, config.ConnectionString) if err != nil { + client.Close() return config, err } config.db = db @@ -33,6 +49,7 @@ func newConfig() (Config, error) { Listen: ":10000", ConnectionDriver: "sqlite", ConnectionString: "/tmp/red-apter.db", + KeyValueURL: "redis://localhost:6379", } b, _ := json.Marshal(config) var m map[string]any diff --git a/src/main.go b/src/main.go index 5601a06..3d4bd3c 100644 --- a/src/main.go +++ b/src/main.go @@ -10,6 +10,7 @@ func Main(ctx context.Context) error { return err } defer config.db.Close() + defer config.keyValue.Close() if err := listen(ctx, config); err != nil && ctx.Err() == nil { return err