2023-06-22 06:53:38 +00:00
|
|
|
package redis
|
|
|
|
|
|
|
|
/*
|
|
|
|
used for state management between shard and login servers
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-12-03 04:09:11 +00:00
|
|
|
"github.com/CPunch/gopenfusion/internal/config"
|
2023-06-22 06:53:38 +00:00
|
|
|
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RedisHandler struct {
|
|
|
|
client *redis.Client
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func OpenRedis(addr string) (*RedisHandler, error) {
|
|
|
|
client := redis.NewClient(&redis.Options{
|
|
|
|
Addr: addr,
|
|
|
|
CredentialsProvider: config.GetRedisCredentials(),
|
|
|
|
})
|
|
|
|
|
|
|
|
_, err := client.Ping(context.Background()).Result()
|
|
|
|
return &RedisHandler{client: client, ctx: context.Background()}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RedisHandler) Close() error {
|
|
|
|
return r.client.Close()
|
|
|
|
}
|