From 114a36bd200fe6205a5befc7b1e49594b8323204 Mon Sep 17 00:00:00 2001 From: Darwin Cereska Date: Thu, 19 Mar 2026 15:09:37 +0100 Subject: [PATCH] feat: added redis pool --- go.mod | 7 +++++++ go.sum | 8 ++++++++ internal/models/models.go | 1 + internal/redis/redis.go | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 go.sum diff --git a/go.mod b/go.mod index fe845b1..18d829a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module git.darwincereska.dev/darwincereska/meld go 1.26.1 + +require ( + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/redis/go-redis/v9 v9.18.0 // indirect + go.uber.org/atomic v1.11.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a547197 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +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/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs= +github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= diff --git a/internal/models/models.go b/internal/models/models.go index 76fc6f4..fb4ac64 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -4,6 +4,7 @@ import "time" type Ticket struct { ID int64 + PlayerID string Attributes map[string]float64 Tags map[string]float64 CreatedAt time.Time diff --git a/internal/redis/redis.go b/internal/redis/redis.go index 3af71a0..2c2d17e 100644 --- a/internal/redis/redis.go +++ b/internal/redis/redis.go @@ -1,4 +1,26 @@ package redis +import ( + "context" + + "git.darwincereska.dev/darwincereska/meld/internal/models" + "github.com/redis/go-redis/v9" +) + type Pool struct { + client *redis.Client +} + +// Create a new Redis client +func InitRedis(address string, poolSize int) *Pool { + rdb := redis.NewClient(&redis.Options{ + Addr: address, + PoolSize: poolSize, + }) + + return &Pool{client: rdb} +} + +func (p *Pool) Add(ctx context.Context, key string, ticket models.Ticket) error { + return p.client.ZAdd(ctx, "matchmaking:"+key, redis.Z{Member: ticket.PlayerID}).Err() }