This is a creation in Article, where the information may have evolved or changed.
Redis is a very popular memory cache, known for its rich data structure and high performance. This article describes the Golang client Go-redis that uses Redis in Golang.
At present, the better client has Go-redis and Redigo.
Introduction to use
Installation
go get -u github.com/go-redis/redis
Example
...import "github.com/go-redis/redis"...client := redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", // no password set DB: 0, // use default DB})pong, err := client.Ping().Result()fmt.Println(pong, err)// Output: PONG <nil>err := client.Set("key", "value", 0).Err()if err != nil { panic(err)}val, err := client.Get("key").Result()if err != nil { panic(err)}fmt.Println("key", val)val2, err := client.Get("key2").Result()if err == redis.Nil { fmt.Println("key2 does not exists")} else if err != nil { panic(err)} else { fmt.Println("key2", val2)}// Output: key value// key2 does not exists
Description
Create Client
client = redis.NewClient(&redis.Options{})
Executing commands and Results
A variety of REDIS commands can be consulted Http://godoc.org/github.com/go-redis/redis
Client. Get ("key")//Return is a command. Result ()//returns VAL, Errcommand. ERR ()//returns ERR