Update README to enable syntax highlighting

This commit is contained in:
Graham McIntire 2013-09-13 22:03:56 -05:00
parent cc74e79eb7
commit 6d4e46078e
1 changed files with 105 additions and 90 deletions

View File

@ -25,6 +25,7 @@ Getting started
Let's start with connecting to Redis using TCP:
```go
password := "" // no password set
db := int64(-1) // use default DB
client := redis.NewTCPClient("localhost:6379", password, db)
@ -33,18 +34,20 @@ Let's start with connecting to Redis using TCP:
ping := client.Ping()
fmt.Println(ping.Err(), ping.Val())
// Output: <nil> PONG
```
or using Unix socket:
```go
client := redis.NewUnixClient("/tmp/redis.sock", "", -1)
defer client.Close()
ping := client.Ping()
fmt.Println(ping.Err(), ping.Val())
// Output: <nil> PONG
```
Then we can start sending commands:
```go
set := client.Set("foo", "bar")
fmt.Println(set.Err(), set.Val())
@ -53,9 +56,11 @@ Then we can start sending commands:
// Output: <nil> OK
// <nil> bar
```
We can also pipeline two commands together:
```go
var set *redis.StatusReq
var get *redis.StringReq
reqs, err := client.Pipelined(func(c *redis.PipelineClient) {
@ -68,9 +73,10 @@ We can also pipeline two commands together:
// Output: <nil> [SET key1 hello1: OK GET key2: (nil)]
// SET key1 hello1: OK
// GET key2: (nil)
```
or:
```go
var set *redis.StatusReq
var get *redis.StringReq
reqs, err := client.Pipelined(func(c *redis.PipelineClient) {
@ -83,9 +89,11 @@ or:
// Output: <nil> [SET key1 hello1 GET key2]
// SET key1 hello1
// GET key2
```
We can also send several commands in transaction:
```go
func transaction(multi *redis.MultiClient) ([]redis.Req, error) {
get := multi.Get("key")
if err := get.Err(); err != nil && err != redis.Nil {
@ -115,9 +123,11 @@ We can also send several commands in transaction:
fmt.Println(err, reqs)
// Output: <nil> [SET key 1: OK]
```
To subscribe to the channel:
```go
pubsub, err := client.PubSubClient()
defer pubsub.Close()
@ -135,9 +145,11 @@ To subscribe to the channel:
// Output: <nil> subscribe
// <nil> hello
```
You can also write custom commands:
```go
func Get(client *redis.Client, key string) *redis.StringReq {
req := redis.NewStringReq("GET", key)
client.Process(req)
@ -147,10 +159,13 @@ You can also write custom commands:
get := Get(client, "key_does_not_exist")
fmt.Println(get.Err(), get.Val())
// Output: (nil)
```
Client uses connection pool to send commands. You can change maximum number of connections with:
```go
client.ConnPool.(*redis.MultiConnPool).MaxCap = 1
```
Look and feel
-------------