feat: added redis pool
This commit is contained in:
@@ -4,6 +4,7 @@ import "time"
|
||||
|
||||
type Ticket struct {
|
||||
ID int64
|
||||
PlayerID string
|
||||
Attributes map[string]float64
|
||||
Tags map[string]float64
|
||||
CreatedAt time.Time
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user