feat: added redis pool
This commit is contained in:
7
go.mod
7
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
|
||||
)
|
||||
|
||||
8
go.sum
Normal file
8
go.sum
Normal file
@@ -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=
|
||||
@@ -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