Update readme for v3.

This commit is contained in:
Vladimir Mihailenco 2015-05-23 14:33:33 +03:00
parent 1d02fa85a9
commit 36fcbb1f94
3 changed files with 77 additions and 16 deletions

View File

@ -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()

View File

@ -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.

View File

@ -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() {