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.
39 lines
677 B
39 lines
677 B
/**
|
|
* Created by GoLand.
|
|
* User: link1st
|
|
* Date: 2019-07-25
|
|
* Time: 14:18
|
|
*/
|
|
|
|
package redislib
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/go-redis/redis"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var (
|
|
client *redis.Client
|
|
)
|
|
|
|
func ExampleNewClient() {
|
|
|
|
client = redis.NewClient(&redis.Options{
|
|
Addr: viper.GetString("redis.addr"),
|
|
Password: viper.GetString("redis.password"),
|
|
DB: viper.GetInt("redis.DB"),
|
|
PoolSize: viper.GetInt("redis.poolSize"),
|
|
MinIdleConns: viper.GetInt("redis.minIdleConns"),
|
|
})
|
|
|
|
pong, err := client.Ping().Result()
|
|
fmt.Println("初始化redis:", pong, err)
|
|
// Output: PONG <nil>
|
|
}
|
|
|
|
func GetClient() (c *redis.Client) {
|
|
|
|
return client
|
|
}
|