2021-03-23 00:55:26 +08:00
|
|
|
/*
|
|
|
|
* @Date: 2021-03-22 10:12:42
|
|
|
|
* @LastEditors: viletyy
|
2021-03-24 11:28:57 +08:00
|
|
|
* @LastEditTime: 2021-03-23 09:26:11
|
2021-03-23 00:55:26 +08:00
|
|
|
* @FilePath: /potato/initialize/redis.go
|
|
|
|
*/
|
|
|
|
package initialize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/go-redis/redis"
|
|
|
|
"github.com/viletyy/potato/global"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Redis() *redis.Client {
|
|
|
|
rdb := redis.NewClient(&redis.Options{
|
2021-03-24 11:28:57 +08:00
|
|
|
Addr: fmt.Sprintf("%s:%d", global.GO_CONFIG.Redis.Host, global.GO_CONFIG.Redis.Port),
|
|
|
|
Password: global.GO_CONFIG.Redis.Password,
|
|
|
|
DB: int(global.GO_CONFIG.Redis.Db),
|
2021-03-23 00:55:26 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
RedisSet(rdb)
|
|
|
|
return rdb
|
|
|
|
}
|
|
|
|
|
|
|
|
func RedisSet(rdb *redis.Client) {
|
|
|
|
_, pingErr := rdb.Ping().Result()
|
|
|
|
if pingErr != nil {
|
|
|
|
global.GO_LOG.Error(fmt.Sprintf("Redis Connection Error: %v", pingErr))
|
|
|
|
}
|
|
|
|
}
|