红联Linux门户
Linux帮助

Go语言Redis客户端Go-Redis v4.1.2发布

发布时间:2016-08-11 16:28:14来源:红联作者:baihuo
Go-Redis v4.1.2 发布了,Go-Redis 是 Redis 数据库的 Google Go 语言的客户端开发包。

支持:

Redis 3 commands except QUIT, MONITOR, SLOWLOG and SYNC.

Pub/Sub.

Transactions.

Pipelining.

Scripting.

Timeouts.

Redis Sentinel.

Redis Cluster.

Ring.

Cache friendly.

Rate limiting.

Distributed Locks.

API docs: http://godoc.org/gopkg.in/redis.v4. Examples: http://godoc.org/gopkg.in/redis.v4#pkg-examples.

示例如下:[code]func ExampleNewClient() {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password setDB: 0, // use default DB
})
pong, err := client.Ping().Result()
fmt.Println(pong, err) // Output: PONG
}
func ExampleClient() {
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
}[/code]软件详情:https://github.com/alphazero/Go-Redis/

来自:开源中国社区
文章评论

共有 0 条评论