Redis(十)[client-Golang]

在這裏插入圖片描述
redis官方地址:

https://redis.io/

redis中文官方地址:

http://redis.cn/

redis文檔地址:

http://redis.cn/documentation.html

官方參考client-golang地址:

http://redis.cn/clients.html#go

redigo的github地址:

https://github.com/gomodule/redigo

redigo的API參考地址:

https://godoc.org/github.com/gomodule/redigo/redis

使用golang實現redis的客戶端

1.下載

go get -u -v github.com/gomodule/redigo

2.入門

1.創建項目

mkdir -p $GOPATH/src/redisClient && cd $_
go mod init redisClient 
touch main.go
tee $GOPATH/src/redisClient/main.go<<-'EOF'
package main

import "github.com/gomodule/redigo/redis"

func main(){
  conn,_ := redis.Dial("tcp", "127.0.0.1:6379")
  defer conn.Close()
  conn.Do("set", "hello", "world")
}
EOF
go run main.go

在這裏插入圖片描述

2.在redis-cli中查詢

get hello

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章