feat: added redis pool

This commit is contained in:
Darwin Cereska
2026-03-19 15:09:37 +01:00
parent d8eec0d056
commit 114a36bd20
4 changed files with 38 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import "time"
type Ticket struct {
ID int64
PlayerID string
Attributes map[string]float64
Tags map[string]float64
CreatedAt time.Time

View File

@@ -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()
}