golang连接redis
一、搭建redis-server
https://www.cnblogs.com/amuge/articles/16215516.html
二、golang支持redis的驱动有以下几个
及
github.com/astaxie/redisgo
三、简单实现连接goredis
3.1 安装
go mod init main.go
go get -u github.com/astaxie/goredis
3.2 操作代码:
package main
import (
"fmt"
"log"
"github.com/astaxie/goredis"
)
func main() {
var client goredis.Client
client.Addr = "ip:port"
client.Db = 13
client.Password = "密码"
err := client.Set("a", []byte("hello world"))
if err != nil {
log.Fatal(err)
}
val, _ := client.Get("a")
fmt.Println(string(val))
}