From aa895c2c94662537dc982815a391b4d9dd6db641 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 22 Dec 2016 13:14:34 +0200 Subject: [PATCH] Add TxPipeline examples. --- example_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/example_test.go b/example_test.go index 0769aa05..45be0439 100644 --- a/example_test.go +++ b/example_test.go @@ -160,20 +160,56 @@ func ExampleClient_Scan() { func ExampleClient_Pipelined() { var incr *redis.IntCmd _, err := client.Pipelined(func(pipe *redis.Pipeline) error { - incr = pipe.Incr("counter1") - pipe.Expire("counter1", time.Hour) + incr = pipe.Incr("pipelined_counter") + pipe.Expire("pipelined_counter", time.Hour) return nil }) fmt.Println(incr.Val(), err) // Output: 1 } -func ExamplePipeline() { +func ExampleClient_Pipeline() { pipe := client.Pipeline() - defer pipe.Close() - incr := pipe.Incr("counter2") - pipe.Expire("counter2", time.Hour) + incr := pipe.Incr("pipeline_counter") + pipe.Expire("pipeline_counter", time.Hour) + + // Execute + // + // INCR pipeline_counter + // EXPIRE pipeline_counts 3600 + // + // using one client-server roundtrip. + _, err := pipe.Exec() + fmt.Println(incr.Val(), err) + // Output: 1 +} + +func ExampleClient_TxPipelined() { + var incr *redis.IntCmd + _, err := client.TxPipelined(func(pipe *redis.Pipeline) error { + incr = pipe.Incr("tx_pipelined_counter") + pipe.Expire("tx_pipelined_counter", time.Hour) + return nil + }) + fmt.Println(incr.Val(), err) + // Output: 1 +} + +func ExampleClient_TxPipeline() { + pipe := client.TxPipeline() + + incr := pipe.Incr("tx_pipeline_counter") + pipe.Expire("tx_pipeline_counter", time.Hour) + + // Execute + // + // MULTI + // INCR pipeline_counter + // EXPIRE pipeline_counts 3600 + // EXEC + // + // using one client-server roundtrip. _, err := pipe.Exec() fmt.Println(incr.Val(), err) // Output: 1