go 连接redis

2022-12-29 18:13:49 浏览数 (1)

代码语言:javascript复制
package main

import (
	"fmt"
	"github.com/garyburd/redigo/redis"
)

func main() {
	c, err := redis.Dial("tcp", "localhost:6379")
	if err != nil {
		fmt.Println("conn redis failed,", err)
		return
	}
	c.Do("set","gin_demo","test_gin", "ex",10*60)

	fmt.Println("redis conn success")

//这里必须使用redis.String() 
//c.Do("Get","gin_demo") 获取到的是地址空间
	redisGets,val := redis.String(c.Do("Get","gin_demo"))
	if val == nil {
		fmt.Println(redisGets)
	}

	defer c.Close()
}

0 人点赞