forked from mirror/redis
Merge pull request #114 from go-redis/fix/use-v3-in-readme
Update readme for v3.
This commit is contained in:
commit
1eb3e076ed
69
README.md
69
README.md
|
@ -3,32 +3,79 @@ Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.pn
|
||||||
|
|
||||||
Supports:
|
Supports:
|
||||||
|
|
||||||
- Redis 2.8 commands except QUIT, MONITOR, SLOWLOG and SYNC.
|
- Redis 3 commands except QUIT, MONITOR, SLOWLOG and SYNC.
|
||||||
- Pub/sub.
|
- Pub/Sub.
|
||||||
- Transactions.
|
- Transactions.
|
||||||
- Pipelining.
|
- Pipelines.
|
||||||
- Connection pool.
|
- Connection pool. Client can be safely used from multiple goroutines.
|
||||||
- TLS connections.
|
|
||||||
- Thread safety.
|
|
||||||
- Timeouts.
|
- Timeouts.
|
||||||
- Redis Sentinel.
|
- [Redis Sentinel](http://godoc.org/gopkg.in/redis.v3#NewFailoverClient).
|
||||||
- Redis Cluster: https://github.com/bsm/redis-cluster.
|
- [Redis Cluster](http://godoc.org/gopkg.in/redis.v3#NewClusterClient).
|
||||||
|
|
||||||
API docs: http://godoc.org/gopkg.in/redis.v2.
|
API docs: http://godoc.org/gopkg.in/redis.v3.
|
||||||
Examples: http://godoc.org/gopkg.in/redis.v2#pkg-examples.
|
Examples: http://godoc.org/gopkg.in/redis.v3#pkg-examples.
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Install:
|
Install:
|
||||||
|
|
||||||
go get gopkg.in/redis.v2
|
go get gopkg.in/redis.v3
|
||||||
|
|
||||||
|
Quickstart
|
||||||
|
----------
|
||||||
|
|
||||||
|
```go
|
||||||
|
func ExampleNewClient() {
|
||||||
|
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>
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Howto
|
||||||
|
-----
|
||||||
|
|
||||||
|
Please go through [examples](http://godoc.org/gopkg.in/redis.v3#pkg-examples) to get an idea how to use this package.
|
||||||
|
|
||||||
Look and feel
|
Look and feel
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Some corner cases:
|
Some corner cases:
|
||||||
|
|
||||||
|
SET key value EX 10 NX
|
||||||
|
set, err := client.SetNX("key", "value", 10*time.Second).Result()
|
||||||
|
|
||||||
SORT list LIMIT 0 2 ASC
|
SORT list LIMIT 0 2 ASC
|
||||||
vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
|
vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
|
||||||
|
|
||||||
|
|
2
error.go
2
error.go
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Redis nil reply.
|
// Redis nil reply, .e.g. when key does not exist.
|
||||||
var Nil = errorf("redis: nil")
|
var Nil = errorf("redis: nil")
|
||||||
|
|
||||||
// Redis transaction failed.
|
// Redis transaction failed.
|
||||||
|
|
|
@ -38,13 +38,27 @@ func ExampleNewFailoverClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleClient() {
|
func ExampleClient() {
|
||||||
if err := client.Set("foo", "bar", 0).Err(); err != nil {
|
err := client.Set("key", "value", 0).Err()
|
||||||
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err := client.Get("hello").Result()
|
val, err := client.Get("key").Result()
|
||||||
fmt.Printf("%q %q %v", v, err, err == redis.Nil)
|
if err != nil {
|
||||||
// Output: "" "redis: nil" true
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleClient_Incr() {
|
func ExampleClient_Incr() {
|
||||||
|
|
Loading…
Reference in New Issue