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.

37 lines
714 B

package RedisUtil
import (
"dsSdsf/Utils/ConfigUtil"
"github.com/go-redis/redis"
"time"
)
var (
RedisClient *redis.Client
RedisHost string
RedisDb int
)
func init() {
// 从配置文件获取redis的ip以及db
RedisHost = ConfigUtil.RedisIp + ":" + ConfigUtil.RedisPort
RedisClient = redis.NewClient(&redis.Options{
Addr: RedisHost,
DB: 0, // use default DB
})
}
func SET(key string, value string, expiration time.Duration) {
RedisClient.Set(key, value, expiration*time.Second)
}
func GET(key string) (string, error) {
val, err := RedisClient.Get(key).Result()
return val, err
}
func EXPIRE(key string, expiration time.Duration) {
RedisClient.Expire(key, expiration*time.Second)
}