This repository has been archived on 2026-01-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Game/Server/common/db/redis/client.go

35 lines
503 B
Go

package redis
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
var (
cli *redis.Client
Nil = redis.Nil
)
func Init(host string, port int, password string, db int) error {
cli = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", host, port),
Password: password,
DB: db,
})
_, err := cli.Ping(context.Background()).Result()
return err
}
func Client() *redis.Client {
return cli
}
func Close() error {
if cli != nil {
return cli.Close()
}
return nil
}