You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
581 B
35 lines
581 B
3 years ago
|
package redis_helper
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/go-redis/redis/v8"
|
||
|
)
|
||
|
|
||
|
var redisInstance *redis.ClusterClient
|
||
|
|
||
|
// Init used to init redis instance in tikv mode
|
||
|
func Init(serverAddr []string) error {
|
||
|
option := &redis.ClusterOptions{
|
||
|
Addrs: serverAddr,
|
||
|
PoolSize: 2,
|
||
|
}
|
||
|
|
||
|
rdb := redis.NewClusterClient(option)
|
||
|
err := rdb.Ping(context.Background()).Err()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
redisInstance = rdb
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// Close disconnect redis instance in tikv mode
|
||
|
func Close() error {
|
||
|
if redisInstance != nil {
|
||
|
return redisInstance.Close()
|
||
|
}
|
||
|
return nil
|
||
|
}
|