Skip to content

Commit

Permalink
Update readme for v3.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed May 23, 2015
1 parent 1d02fa8 commit 36fcbb1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 16 deletions.
69 changes: 58 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,79 @@ Redis client for Golang [![Build Status](https://travis-ci.org/go-redis/redis.pn

Supports:

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

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

Installation
------------

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

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
vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()

Expand Down
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
)

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

// Redis transaction failed.
Expand Down
22 changes: 18 additions & 4 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,27 @@ func ExampleNewFailoverClient() {
}

func ExampleClient() {
if err := client.Set("foo", "bar", 0).Err(); err != nil {
err := client.Set("key", "value", 0).Err()
if err != nil {
panic(err)
}

v, err := client.Get("hello").Result()
fmt.Printf("%q %q %v", v, err, err == redis.Nil)
// Output: "" "redis: nil" true
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
}

func ExampleClient_Incr() {
Expand Down

0 comments on commit 36fcbb1

Please sign in to comment.