golang 使用redis

package model

import (
	"github.com/go-redis/redis"
	"log"
	"time"
)

var RedisClient *redis.Client

func InitRedis() {
	RedisClient = redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})
	_, redisErr := RedisClient.Ping().Result()
	if redisErr != nil {
		log.Println("redis 连接失败")
	} else {
		log.Println("Init Redis Successful")
	}
	//RedisClient := model.RedisClient
	//二十五小时过期
	RedisClient.Set("app:hb:hk:01", time.Now().Unix(), 1000000000*60*60*25)

}

  

 

posted @ 2020-04-28 11:44  小酥肉是我  阅读(312)  评论(0编辑  收藏  举报