From db0cb86282becca1d38fc99efe37f5d858e3618a Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sun, 29 Sep 2013 11:48:45 +0300 Subject: [PATCH] Remove examples from godoc. --- v2/doc.go | 160 +-------------------------------------------- v2/example_test.go | 14 ++-- 2 files changed, 8 insertions(+), 166 deletions(-) diff --git a/v2/doc.go b/v2/doc.go index 18743a5..e800154 100644 --- a/v2/doc.go +++ b/v2/doc.go @@ -1,162 +1,4 @@ /* -Package github.com/vmihailenco/redis implements a Redis client. - -Let's start with connecting to Redis using TCP: - - client := redis.NewTCPClient(&redis.Options{ - Addr: "localhost:6379", - Password: "", // no password set - DB: 0, // use default DB - }) - defer client.Close() - - ping := client.Ping() - fmt.Println(ping.Err(), ping.Val()) - // Output: PONG - -or using Unix socket: - - client := redis.NewUnixClient(&redis.Options{ - Addr: "/tmp/redis.sock", - }) - defer client.Close() - - ping := client.Ping() - fmt.Println(ping.Err(), ping.Val()) - // Output: PONG - -Then we can start sending commands: - - client := redis.NewTCPClient(&redis.Options{ - Addr: ":6379", - }) - defer client.Close() - - set := client.Set("foo", "bar") - fmt.Println(set.Err(), set.Val()) - - get := client.Get("foo") - fmt.Println(get.Err(), get.Val()) - - // Output: OK - // bar - -We can also pipeline two commands together: - - client := redis.NewTCPClient(&redis.Options{ - Addr: ":6379", - }) - defer client.Close() - - cmds, err := client.Pipelined(func(c *redis.Pipeline) { - c.Set("key1", "hello1") - c.Get("key2") - }) - fmt.Println(cmds, err) - // Output: [SET key1 hello1: OK GET key2: (nil)] (nil) - -or: - - client := redis.NewTCPClient(&redis.Options{ - Addr: ":6379", - }) - defer client.Close() - - pipeline := client.Pipeline() - set := pipeline.Set("key1", "hello1") - get := pipeline.Get("key2") - cmds, err := pipeline.Exec() - fmt.Println(cmds, err) - fmt.Println(set) - fmt.Println(get) - // Output: [SET key1 hello1: OK GET key2: (nil)] (nil) - // SET key1 hello1: OK - // GET key2: (nil) - -We can also send several commands in transaction: - - incr := func(tx *redis.Multi) ([]redis.Cmder, error) { - get := tx.Get("key") - if err := get.Err(); err != nil && err != redis.Nil { - return nil, err - } - - val, _ := strconv.ParseInt(get.Val(), 10, 64) - - return tx.Exec(func() { - tx.Set("key", strconv.FormatInt(val+1, 10)) - }) - } - - client := redis.NewTCPClient(&redis.Options{ - Addr: ":6379", - }) - defer client.Close() - - client.Del("key") - - tx := client.Multi() - defer tx.Close() - - watch := tx.Watch("key") - _ = watch.Err() - - for { - cmds, err := incr(tx) - if err == redis.Nil { - // Transaction failed. Repeat. - continue - } else if err != nil { - panic(err) - } - fmt.Println(err, cmds) - break - } - - // Output: [SET key 1: OK] - -To subscribe to the channel: - - client := redis.NewTCPClient(&redis.Options{ - Addr: ":6379", - }) - defer client.Close() - - pubsub := client.PubSub() - defer pubsub.Close() - - err := pubsub.Subscribe("mychannel") - _ = err - - msg, err := pubsub.Receive() - fmt.Println(msg, err) - - pub := client.Publish("mychannel", "hello") - _ = pub.Err() - - msg, err = pubsub.Receive() - fmt.Println(msg, err) - - // Output: &{subscribe mychannel 1} - // &{mychannel hello} - -You can also write custom commands: - - func Get(client *redis.Client, key string) *redis.StringCmd { - cmd := redis.NewStringCmd("GET", key) - client.Process(cmd) - return cmd - } - - func ExampleCustomCommand() { - client := redis.NewTCPClient(&redis.Options{ - Addr: ":6379", - }) - defer client.Close() - - get := Get(client, "key_does_not_exist") - fmt.Println(get.Err(), get.Val()) - // Output: (nil) - } +Package github.com/vmihailenco/redis/v2 implements a Redis client. */ package redis diff --git a/v2/example_test.go b/v2/example_test.go index ea009f4..1a45c69 100644 --- a/v2/example_test.go +++ b/v2/example_test.go @@ -47,7 +47,7 @@ func ExampleClient() { // bar } -func ExamplePipeline2() { +func ExampleClient_Pipelined() { client := redis.NewTCPClient(&redis.Options{ Addr: ":6379", }) @@ -146,13 +146,13 @@ func ExamplePubSub() { // &{mychannel hello} } -func Get(client *redis.Client, key string) *redis.StringCmd { - cmd := redis.NewStringCmd("GET", key) - client.Process(cmd) - return cmd -} +func Example_CustomCommand() { + Get := func(client *redis.Client, key string) *redis.StringCmd { + cmd := redis.NewStringCmd("GET", key) + client.Process(cmd) + return cmd + } -func ExampleCustomCommand() { client := redis.NewTCPClient(&redis.Options{ Addr: ":6379", })