Add TxPipeline examples.

This commit is contained in:
Vladimir Mihailenco 2016-12-22 13:14:34 +02:00
parent 754e4ed906
commit aa895c2c94
1 changed files with 42 additions and 6 deletions

View File

@ -160,20 +160,56 @@ func ExampleClient_Scan() {
func ExampleClient_Pipelined() { func ExampleClient_Pipelined() {
var incr *redis.IntCmd var incr *redis.IntCmd
_, err := client.Pipelined(func(pipe *redis.Pipeline) error { _, err := client.Pipelined(func(pipe *redis.Pipeline) error {
incr = pipe.Incr("counter1") incr = pipe.Incr("pipelined_counter")
pipe.Expire("counter1", time.Hour) pipe.Expire("pipelined_counter", time.Hour)
return nil return nil
}) })
fmt.Println(incr.Val(), err) fmt.Println(incr.Val(), err)
// Output: 1 <nil> // Output: 1 <nil>
} }
func ExamplePipeline() { func ExampleClient_Pipeline() {
pipe := client.Pipeline() pipe := client.Pipeline()
defer pipe.Close()
incr := pipe.Incr("counter2") incr := pipe.Incr("pipeline_counter")
pipe.Expire("counter2", time.Hour) 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 <nil>
}
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 <nil>
}
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() _, err := pipe.Exec()
fmt.Println(incr.Val(), err) fmt.Println(incr.Val(), err)
// Output: 1 <nil> // Output: 1 <nil>