mirror of
https://github.com/go-eagle/eagle.git
synced 2025-10-27 02:41:36 +08:00
32 lines
742 B
Go
32 lines
742 B
Go
package redis
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/go-redis/redis"
|
|
"github.com/lexkong/log"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var Client *redis.Client
|
|
|
|
func Init() {
|
|
Client = redis.NewClient(&redis.Options{
|
|
Addr: viper.GetString("redis.addr"),
|
|
Password: viper.GetString("redis.password"),
|
|
DB: viper.GetInt("redis.db"),
|
|
DialTimeout: viper.GetDuration("redis.dial_timeout"),
|
|
ReadTimeout: viper.GetDuration("redis.read_timeout"),
|
|
WriteTimeout: viper.GetDuration("redis.write_timeout"),
|
|
PoolSize: viper.GetInt("redis.pool_size"),
|
|
})
|
|
|
|
fmt.Println("redis addr:", viper.GetString("redis.addr"))
|
|
|
|
_, err := Client.Ping().Result()
|
|
if err != nil {
|
|
log.Errorf(err, "[redis] redis ping err: %+v")
|
|
panic(err)
|
|
}
|
|
}
|