Skip to content

Commit 36fcbb1

Browse files
committed
Update readme for v3.
1 parent 1d02fa8 commit 36fcbb1

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

README.md

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,79 @@ Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.pn
33

44
Supports:
55

6-
- Redis 2.8 commands except QUIT, MONITOR, SLOWLOG and SYNC.
7-
- Pub/sub.
6+
- Redis 3 commands except QUIT, MONITOR, SLOWLOG and SYNC.
7+
- Pub/Sub.
88
- Transactions.
9-
- Pipelining.
10-
- Connection pool.
11-
- TLS connections.
12-
- Thread safety.
9+
- Pipelines.
10+
- Connection pool. Client can be safely used from multiple goroutines.
1311
- Timeouts.
14-
- Redis Sentinel.
15-
- Redis Cluster: https://github.com/bsm/redis-cluster.
12+
- [Redis Sentinel](http://godoc.org/gopkg.in/redis.v3#NewFailoverClient).
13+
- [Redis Cluster](http://godoc.org/gopkg.in/redis.v3#NewClusterClient).
1614

17-
API docs: http://godoc.org/gopkg.in/redis.v2.
18-
Examples: http://godoc.org/gopkg.in/redis.v2#pkg-examples.
15+
API docs: http://godoc.org/gopkg.in/redis.v3.
16+
Examples: http://godoc.org/gopkg.in/redis.v3#pkg-examples.
1917

2018
Installation
2119
------------
2220

2321
Install:
2422

25-
go get gopkg.in/redis.v2
23+
go get gopkg.in/redis.v3
24+
25+
Quickstart
26+
----------
27+
28+
```go
29+
func ExampleNewClient() {
30+
client := redis.NewClient(&redis.Options{
31+
Addr: "localhost:6379",
32+
Password: "", // no password set
33+
DB: 0, // use default DB
34+
})
35+
36+
pong, err := client.Ping().Result()
37+
fmt.Println(pong, err)
38+
// Output: PONG <nil>
39+
}
40+
41+
func ExampleClient() {
42+
err := client.Set("key", "value", 0).Err()
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
val, err := client.Get("key").Result()
48+
if err != nil {
49+
panic(err)
50+
}
51+
fmt.Println("key", val)
52+
53+
val2, err := client.Get("key2").Result()
54+
if err == redis.Nil {
55+
fmt.Println("key2 does not exists")
56+
} else if err != nil {
57+
panic(err)
58+
} else {
59+
fmt.Println("key2", val2)
60+
}
61+
// Output: key value
62+
// key2 does not exists
63+
}
64+
```
65+
66+
Howto
67+
-----
68+
69+
Please go through [examples](http://godoc.org/gopkg.in/redis.v3#pkg-examples) to get an idea how to use this package.
2670

2771
Look and feel
2872
-------------
2973

3074
Some corner cases:
3175

76+
SET key value EX 10 NX
77+
set, err := client.SetNX("key", "value", 10*time.Second).Result()
78+
3279
SORT list LIMIT 0 2 ASC
3380
vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
3481

error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strings"
88
)
99

10-
// Redis nil reply.
10+
// Redis nil reply, .e.g. when key does not exist.
1111
var Nil = errorf("redis: nil")
1212

1313
// Redis transaction failed.

example_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,27 @@ func ExampleNewFailoverClient() {
3838
}
3939

4040
func ExampleClient() {
41-
if err := client.Set("foo", "bar", 0).Err(); err != nil {
41+
err := client.Set("key", "value", 0).Err()
42+
if err != nil {
4243
panic(err)
4344
}
4445

45-
v, err := client.Get("hello").Result()
46-
fmt.Printf("%q %q %v", v, err, err == redis.Nil)
47-
// Output: "" "redis: nil" true
46+
val, err := client.Get("key").Result()
47+
if err != nil {
48+
panic(err)
49+
}
50+
fmt.Println("key", val)
51+
52+
val2, err := client.Get("key2").Result()
53+
if err == redis.Nil {
54+
fmt.Println("key2 does not exists")
55+
} else if err != nil {
56+
panic(err)
57+
} else {
58+
fmt.Println("key2", val2)
59+
}
60+
// Output: key value
61+
// key2 does not exists
4862
}
4963

5064
func ExampleClient_Incr() {

0 commit comments

Comments
 (0)