| 1 |
Description: network test may not work on buildd |
| 2 |
Author: Thorsten Alteholz <[email protected]> |
| 3 |
Index: golang-gopkg-redis.v5/main_test.go |
| 4 |
=================================================================== |
| 5 |
--- golang-gopkg-redis.v5.orig/main_test.go 2019-12-03 00:16:05.551410932 +0000 |
| 6 |
+++ golang-gopkg-redis.v5/main_test.go 2019-12-03 00:16:05.547410731 +0000 |
| 7 |
@@ -93,10 +93,10 @@ |
| 8 |
Expect(stopCluster(cluster)).NotTo(HaveOccurred()) |
| 9 |
}) |
| 10 |
|
| 11 |
-func TestGinkgoSuite(t *testing.T) { |
| 12 |
- RegisterFailHandler(Fail) |
| 13 |
- RunSpecs(t, "gopkg.in/redis.v5") |
| 14 |
-} |
| 15 |
+//func TestGinkgoSuite(t *testing.T) { |
| 16 |
+// RegisterFailHandler(Fail) |
| 17 |
+// RunSpecs(t, "gopkg.in/redis.v5") |
| 18 |
+//} |
| 19 |
|
| 20 |
//------------------------------------------------------------------------------ |
| 21 |
|
| 22 |
Index: golang-gopkg-redis.v5/example_test.go |
| 23 |
=================================================================== |
| 24 |
--- golang-gopkg-redis.v5.orig/example_test.go 2019-12-03 00:16:05.551410932 +0000 |
| 25 |
+++ golang-gopkg-redis.v5/example_test.go 2021-03-10 23:07:08.950857990 +0000 |
| 26 |
@@ -1,9 +1,9 @@ |
| 27 |
package redis_test |
| 28 |
|
| 29 |
import ( |
| 30 |
- "fmt" |
| 31 |
- "strconv" |
| 32 |
- "sync" |
| 33 |
+// "fmt" |
| 34 |
+// "strconv" |
| 35 |
+// "sync" |
| 36 |
"time" |
| 37 |
|
| 38 |
"gopkg.in/redis.v5" |
| 39 |
@@ -23,17 +23,17 @@ |
| 40 |
client.FlushDb() |
| 41 |
} |
| 42 |
|
| 43 |
-func ExampleNewClient() { |
| 44 |
- client := redis.NewClient(&redis.Options{ |
| 45 |
- Addr: "localhost:6379", |
| 46 |
- Password: "", // no password set |
| 47 |
- DB: 0, // use default DB |
| 48 |
- }) |
| 49 |
- |
| 50 |
- pong, err := client.Ping().Result() |
| 51 |
- fmt.Println(pong, err) |
| 52 |
- // Output: PONG <nil> |
| 53 |
-} |
| 54 |
+//func ExampleNewClient() { |
| 55 |
+// client := redis.NewClient(&redis.Options{ |
| 56 |
+// Addr: "localhost:6379", |
| 57 |
+// Password: "", // no password set |
| 58 |
+// DB: 0, // use default DB |
| 59 |
+// }) |
| 60 |
+// |
| 61 |
+// pong, err := client.Ping().Result() |
| 62 |
+// fmt.Println(pong, err) |
| 63 |
+// // Output: PONG <nil> |
| 64 |
+//} |
| 65 |
|
| 66 |
func ExampleNewFailoverClient() { |
| 67 |
// See http://redis.io/topics/sentinel for instructions how to |
| 68 |
@@ -65,29 +65,29 @@ |
| 69 |
client.Ping() |
| 70 |
} |
| 71 |
|
| 72 |
-func ExampleClient() { |
| 73 |
- err := client.Set("key", "value", 0).Err() |
| 74 |
- if err != nil { |
| 75 |
- panic(err) |
| 76 |
- } |
| 77 |
- |
| 78 |
- val, err := client.Get("key").Result() |
| 79 |
- if err != nil { |
| 80 |
- panic(err) |
| 81 |
- } |
| 82 |
- fmt.Println("key", val) |
| 83 |
- |
| 84 |
- val2, err := client.Get("key2").Result() |
| 85 |
- if err == redis.Nil { |
| 86 |
- fmt.Println("key2 does not exists") |
| 87 |
- } else if err != nil { |
| 88 |
- panic(err) |
| 89 |
- } else { |
| 90 |
- fmt.Println("key2", val2) |
| 91 |
- } |
| 92 |
- // Output: key value |
| 93 |
- // key2 does not exists |
| 94 |
-} |
| 95 |
+//func ExampleClient() { |
| 96 |
+// err := client.Set("key", "value", 0).Err() |
| 97 |
+// if err != nil { |
| 98 |
+// panic(err) |
| 99 |
+// } |
| 100 |
+// |
| 101 |
+// val, err := client.Get("key").Result() |
| 102 |
+// if err != nil { |
| 103 |
+// panic(err) |
| 104 |
+// } |
| 105 |
+// fmt.Println("key", val) |
| 106 |
+// |
| 107 |
+// val2, err := client.Get("key2").Result() |
| 108 |
+// if err == redis.Nil { |
| 109 |
+// fmt.Println("key2 does not exists") |
| 110 |
+// } else if err != nil { |
| 111 |
+// panic(err) |
| 112 |
+// } else { |
| 113 |
+// fmt.Println("key2", val2) |
| 114 |
+// } |
| 115 |
+// // Output: key value |
| 116 |
+// // key2 does not exists |
| 117 |
+//} |
| 118 |
|
| 119 |
func ExampleClient_Set() { |
| 120 |
// Last argument is expiration. Zero means the key has no |
| 121 |
@@ -104,266 +104,266 @@ |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
-func ExampleClient_Incr() { |
| 126 |
- if err := client.Incr("counter").Err(); err != nil { |
| 127 |
- panic(err) |
| 128 |
- } |
| 129 |
- |
| 130 |
- n, err := client.Get("counter").Int64() |
| 131 |
- fmt.Println(n, err) |
| 132 |
- // Output: 1 <nil> |
| 133 |
-} |
| 134 |
- |
| 135 |
-func ExampleClient_BLPop() { |
| 136 |
- if err := client.RPush("queue", "message").Err(); err != nil { |
| 137 |
- panic(err) |
| 138 |
- } |
| 139 |
- |
| 140 |
- // use `client.BLPop(0, "queue")` for infinite waiting time |
| 141 |
- result, err := client.BLPop(1*time.Second, "queue").Result() |
| 142 |
- if err != nil { |
| 143 |
- panic(err) |
| 144 |
- } |
| 145 |
- |
| 146 |
- fmt.Println(result[0], result[1]) |
| 147 |
- // Output: queue message |
| 148 |
-} |
| 149 |
- |
| 150 |
-func ExampleClient_Scan() { |
| 151 |
- client.FlushDb() |
| 152 |
- for i := 0; i < 33; i++ { |
| 153 |
- err := client.Set(fmt.Sprintf("key%d", i), "value", 0).Err() |
| 154 |
- if err != nil { |
| 155 |
- panic(err) |
| 156 |
- } |
| 157 |
- } |
| 158 |
- |
| 159 |
- var cursor uint64 |
| 160 |
- var n int |
| 161 |
- for { |
| 162 |
- var keys []string |
| 163 |
- var err error |
| 164 |
- keys, cursor, err = client.Scan(cursor, "", 10).Result() |
| 165 |
- if err != nil { |
| 166 |
- panic(err) |
| 167 |
- } |
| 168 |
- n += len(keys) |
| 169 |
- if cursor == 0 { |
| 170 |
- break |
| 171 |
- } |
| 172 |
- } |
| 173 |
- |
| 174 |
- fmt.Printf("found %d keys\n", n) |
| 175 |
- // Output: found 33 keys |
| 176 |
-} |
| 177 |
- |
| 178 |
-func ExampleClient_Pipelined() { |
| 179 |
- var incr *redis.IntCmd |
| 180 |
- _, err := client.Pipelined(func(pipe *redis.Pipeline) error { |
| 181 |
- incr = pipe.Incr("pipelined_counter") |
| 182 |
- pipe.Expire("pipelined_counter", time.Hour) |
| 183 |
- return nil |
| 184 |
- }) |
| 185 |
- fmt.Println(incr.Val(), err) |
| 186 |
- // Output: 1 <nil> |
| 187 |
-} |
| 188 |
- |
| 189 |
-func ExampleClient_Pipeline() { |
| 190 |
- pipe := client.Pipeline() |
| 191 |
- |
| 192 |
- incr := pipe.Incr("pipeline_counter") |
| 193 |
- pipe.Expire("pipeline_counter", time.Hour) |
| 194 |
- |
| 195 |
- // Execute |
| 196 |
- // |
| 197 |
- // INCR pipeline_counter |
| 198 |
- // EXPIRE pipeline_counts 3600 |
| 199 |
- // |
| 200 |
- // using one client-server roundtrip. |
| 201 |
- _, err := pipe.Exec() |
| 202 |
- fmt.Println(incr.Val(), err) |
| 203 |
- // Output: 1 <nil> |
| 204 |
-} |
| 205 |
- |
| 206 |
-func ExampleClient_TxPipelined() { |
| 207 |
- var incr *redis.IntCmd |
| 208 |
- _, err := client.TxPipelined(func(pipe *redis.Pipeline) error { |
| 209 |
- incr = pipe.Incr("tx_pipelined_counter") |
| 210 |
- pipe.Expire("tx_pipelined_counter", time.Hour) |
| 211 |
- return nil |
| 212 |
- }) |
| 213 |
- fmt.Println(incr.Val(), err) |
| 214 |
- // Output: 1 <nil> |
| 215 |
-} |
| 216 |
- |
| 217 |
-func ExampleClient_TxPipeline() { |
| 218 |
- pipe := client.TxPipeline() |
| 219 |
- |
| 220 |
- incr := pipe.Incr("tx_pipeline_counter") |
| 221 |
- pipe.Expire("tx_pipeline_counter", time.Hour) |
| 222 |
- |
| 223 |
- // Execute |
| 224 |
- // |
| 225 |
- // MULTI |
| 226 |
- // INCR pipeline_counter |
| 227 |
- // EXPIRE pipeline_counts 3600 |
| 228 |
- // EXEC |
| 229 |
- // |
| 230 |
- // using one client-server roundtrip. |
| 231 |
- _, err := pipe.Exec() |
| 232 |
- fmt.Println(incr.Val(), err) |
| 233 |
- // Output: 1 <nil> |
| 234 |
-} |
| 235 |
- |
| 236 |
-func ExampleClient_Watch() { |
| 237 |
- var incr func(string) error |
| 238 |
- |
| 239 |
- // Transactionally increments key using GET and SET commands. |
| 240 |
- incr = func(key string) error { |
| 241 |
- err := client.Watch(func(tx *redis.Tx) error { |
| 242 |
- n, err := tx.Get(key).Int64() |
| 243 |
- if err != nil && err != redis.Nil { |
| 244 |
- return err |
| 245 |
- } |
| 246 |
- |
| 247 |
- _, err = tx.Pipelined(func(pipe *redis.Pipeline) error { |
| 248 |
- pipe.Set(key, strconv.FormatInt(n+1, 10), 0) |
| 249 |
- return nil |
| 250 |
- }) |
| 251 |
- return err |
| 252 |
- }, key) |
| 253 |
- if err == redis.TxFailedErr { |
| 254 |
- return incr(key) |
| 255 |
- } |
| 256 |
- return err |
| 257 |
- } |
| 258 |
- |
| 259 |
- var wg sync.WaitGroup |
| 260 |
- for i := 0; i < 100; i++ { |
| 261 |
- wg.Add(1) |
| 262 |
- go func() { |
| 263 |
- defer wg.Done() |
| 264 |
- |
| 265 |
- err := incr("counter3") |
| 266 |
- if err != nil { |
| 267 |
- panic(err) |
| 268 |
- } |
| 269 |
- }() |
| 270 |
- } |
| 271 |
- wg.Wait() |
| 272 |
- |
| 273 |
- n, err := client.Get("counter3").Int64() |
| 274 |
- fmt.Println(n, err) |
| 275 |
- // Output: 100 <nil> |
| 276 |
-} |
| 277 |
- |
| 278 |
-func ExamplePubSub() { |
| 279 |
- pubsub, err := client.Subscribe("mychannel1") |
| 280 |
- if err != nil { |
| 281 |
- panic(err) |
| 282 |
- } |
| 283 |
- defer pubsub.Close() |
| 284 |
- |
| 285 |
- err = client.Publish("mychannel1", "hello").Err() |
| 286 |
- if err != nil { |
| 287 |
- panic(err) |
| 288 |
- } |
| 289 |
- |
| 290 |
- msg, err := pubsub.ReceiveMessage() |
| 291 |
- if err != nil { |
| 292 |
- panic(err) |
| 293 |
- } |
| 294 |
- |
| 295 |
- fmt.Println(msg.Channel, msg.Payload) |
| 296 |
- // Output: mychannel1 hello |
| 297 |
-} |
| 298 |
- |
| 299 |
-func ExamplePubSub_Receive() { |
| 300 |
- pubsub, err := client.Subscribe("mychannel2") |
| 301 |
- if err != nil { |
| 302 |
- panic(err) |
| 303 |
- } |
| 304 |
- defer pubsub.Close() |
| 305 |
- |
| 306 |
- n, err := client.Publish("mychannel2", "hello").Result() |
| 307 |
- if err != nil { |
| 308 |
- panic(err) |
| 309 |
- } |
| 310 |
- fmt.Println(n, "clients received message") |
| 311 |
- |
| 312 |
- for i := 0; i < 2; i++ { |
| 313 |
- // ReceiveTimeout is a low level API. Use ReceiveMessage instead. |
| 314 |
- msgi, err := pubsub.ReceiveTimeout(5 * time.Second) |
| 315 |
- if err != nil { |
| 316 |
- break |
| 317 |
- } |
| 318 |
- |
| 319 |
- switch msg := msgi.(type) { |
| 320 |
- case *redis.Subscription: |
| 321 |
- fmt.Println("subscribed to", msg.Channel) |
| 322 |
- case *redis.Message: |
| 323 |
- fmt.Println("received", msg.Payload, "from", msg.Channel) |
| 324 |
- default: |
| 325 |
- panic(fmt.Errorf("unknown message: %#v", msgi)) |
| 326 |
- } |
| 327 |
- } |
| 328 |
- |
| 329 |
- // Output: 1 clients received message |
| 330 |
- // subscribed to mychannel2 |
| 331 |
- // received hello from mychannel2 |
| 332 |
-} |
| 333 |
- |
| 334 |
-func ExampleScript() { |
| 335 |
- IncrByXX := redis.NewScript(` |
| 336 |
- if redis.call("GET", KEYS[1]) ~= false then |
| 337 |
- return redis.call("INCRBY", KEYS[1], ARGV[1]) |
| 338 |
- end |
| 339 |
- return false |
| 340 |
- `) |
| 341 |
- |
| 342 |
- n, err := IncrByXX.Run(client, []string{"xx_counter"}, 2).Result() |
| 343 |
- fmt.Println(n, err) |
| 344 |
- |
| 345 |
- err = client.Set("xx_counter", "40", 0).Err() |
| 346 |
- if err != nil { |
| 347 |
- panic(err) |
| 348 |
- } |
| 349 |
- |
| 350 |
- n, err = IncrByXX.Run(client, []string{"xx_counter"}, 2).Result() |
| 351 |
- fmt.Println(n, err) |
| 352 |
- |
| 353 |
- // Output: <nil> redis: nil |
| 354 |
- // 42 <nil> |
| 355 |
-} |
| 356 |
- |
| 357 |
-func Example_customCommand() { |
| 358 |
- Get := func(client *redis.Client, key string) *redis.StringCmd { |
| 359 |
- cmd := redis.NewStringCmd("GET", key) |
| 360 |
- client.Process(cmd) |
| 361 |
- return cmd |
| 362 |
- } |
| 363 |
- |
| 364 |
- v, err := Get(client, "key_does_not_exist").Result() |
| 365 |
- fmt.Printf("%q %s", v, err) |
| 366 |
- // Output: "" redis: nil |
| 367 |
-} |
| 368 |
- |
| 369 |
-func ExampleScanIterator() { |
| 370 |
- iter := client.Scan(0, "", 0).Iterator() |
| 371 |
- for iter.Next() { |
| 372 |
- fmt.Println(iter.Val()) |
| 373 |
- } |
| 374 |
- if err := iter.Err(); err != nil { |
| 375 |
- panic(err) |
| 376 |
- } |
| 377 |
-} |
| 378 |
- |
| 379 |
-func ExampleScanCmd_Iterator() { |
| 380 |
- iter := client.Scan(0, "", 0).Iterator() |
| 381 |
- for iter.Next() { |
| 382 |
- fmt.Println(iter.Val()) |
| 383 |
- } |
| 384 |
- if err := iter.Err(); err != nil { |
| 385 |
- panic(err) |
| 386 |
- } |
| 387 |
-} |
| 388 |
+//func ExampleClient_Incr() { |
| 389 |
+// if err := client.Incr("counter").Err(); err != nil { |
| 390 |
+// panic(err) |
| 391 |
+// } |
| 392 |
+// |
| 393 |
+// n, err := client.Get("counter").Int64() |
| 394 |
+// fmt.Println(n, err) |
| 395 |
+// / / Output: 1 <nil> |
| 396 |
+//} |
| 397 |
+// |
| 398 |
+//func ExampleClient_BLPop() { |
| 399 |
+// if err := client.RPush("queue", "message").Err(); err != nil { |
| 400 |
+// panic(err) |
| 401 |
+// } |
| 402 |
+// |
| 403 |
+// // use `client.BLPop(0, "queue")` for infinite waiting time |
| 404 |
+// result, err := client.BLPop(1*time.Second, "queue").Result() |
| 405 |
+// if err != nil { |
| 406 |
+// panic(err) |
| 407 |
+// } |
| 408 |
+// |
| 409 |
+// fmt.Println(result[0], result[1]) |
| 410 |
+// // Output: queue message |
| 411 |
+//} |
| 412 |
+// |
| 413 |
+//func ExampleClient_Scan() { |
| 414 |
+// client.FlushDb() |
| 415 |
+// for i := 0; i < 33; i++ { |
| 416 |
+// err := client.Set(fmt.Sprintf("key%d", i), "value", 0).Err() |
| 417 |
+// if err != nil { |
| 418 |
+// panic(err) |
| 419 |
+// } |
| 420 |
+// } |
| 421 |
+// |
| 422 |
+// var cursor uint64 |
| 423 |
+// var n int |
| 424 |
+// for { |
| 425 |
+// var keys []string |
| 426 |
+// var err error |
| 427 |
+// keys, cursor, err = client.Scan(cursor, "", 10).Result() |
| 428 |
+// if err != nil { |
| 429 |
+// panic(err) |
| 430 |
+// } |
| 431 |
+// n += len(keys) |
| 432 |
+// if cursor == 0 { |
| 433 |
+// break |
| 434 |
+// } |
| 435 |
+// } |
| 436 |
+// |
| 437 |
+// fmt.Printf("found %d keys\n", n) |
| 438 |
+// // Output: found 33 keys |
| 439 |
+//} |
| 440 |
+// |
| 441 |
+//func ExampleClient_Pipelined() { |
| 442 |
+// var incr *redis.IntCmd |
| 443 |
+// _, err := client.Pipelined(func(pipe *redis.Pipeline) error { |
| 444 |
+// incr = pipe.Incr("pipelined_counter") |
| 445 |
+// pipe.Expire("pipelined_counter", time.Hour) |
| 446 |
+// return nil |
| 447 |
+// }) |
| 448 |
+// fmt.Println(incr.Val(), err) |
| 449 |
+// // Output: 1 <nil> |
| 450 |
+//} |
| 451 |
+// |
| 452 |
+//func ExampleClient_Pipeline() { |
| 453 |
+// pipe := client.Pipeline() |
| 454 |
+// |
| 455 |
+// incr := pipe.Incr("pipeline_counter") |
| 456 |
+// pipe.Expire("pipeline_counter", time.Hour) |
| 457 |
+// |
| 458 |
+// // Execute |
| 459 |
+// // |
| 460 |
+// // INCR pipeline_counter |
| 461 |
+// // EXPIRE pipeline_counts 3600 |
| 462 |
+// // |
| 463 |
+// // using one client-server roundtrip. |
| 464 |
+// _, err := pipe.Exec() |
| 465 |
+// fmt.Println(incr.Val(), err) |
| 466 |
+// // Output: 1 <nil> |
| 467 |
+//} |
| 468 |
+// |
| 469 |
+//func ExampleClient_TxPipelined() { |
| 470 |
+// var incr *redis.IntCmd |
| 471 |
+// _, err := client.TxPipelined(func(pipe *redis.Pipeline) error { |
| 472 |
+// incr = pipe.Incr("tx_pipelined_counter") |
| 473 |
+// pipe.Expire("tx_pipelined_counter", time.Hour) |
| 474 |
+// return nil |
| 475 |
+// }) |
| 476 |
+// fmt.Println(incr.Val(), err) |
| 477 |
+// // Output: 1 <nil> |
| 478 |
+//} |
| 479 |
+// |
| 480 |
+//func ExampleClient_TxPipeline() { |
| 481 |
+// pipe := client.TxPipeline() |
| 482 |
+// |
| 483 |
+// incr := pipe.Incr("tx_pipeline_counter") |
| 484 |
+// pipe.Expire("tx_pipeline_counter", time.Hour) |
| 485 |
+// |
| 486 |
+// // Execute |
| 487 |
+// // |
| 488 |
+// // MULTI |
| 489 |
+// // INCR pipeline_counter |
| 490 |
+// // EXPIRE pipeline_counts 3600 |
| 491 |
+// // EXEC |
| 492 |
+// // |
| 493 |
+// // using one client-server roundtrip. |
| 494 |
+// _, err := pipe.Exec() |
| 495 |
+// fmt.Println(incr.Val(), err) |
| 496 |
+// // Output: 1 <nil> |
| 497 |
+//} |
| 498 |
+// |
| 499 |
+//func ExampleClient_Watch() { |
| 500 |
+// var incr func(string) error |
| 501 |
+// |
| 502 |
+// // Transactionally increments key using GET and SET commands. |
| 503 |
+// incr = func(key string) error { |
| 504 |
+// err := client.Watch(func(tx *redis.Tx) error { |
| 505 |
+// n, err := tx.Get(key).Int64() |
| 506 |
+// if err != nil && err != redis.Nil { |
| 507 |
+// return err |
| 508 |
+// } |
| 509 |
+// |
| 510 |
+// _, err = tx.Pipelined(func(pipe *redis.Pipeline) error { |
| 511 |
+// pipe.Set(key, strconv.FormatInt(n+1, 10), 0) |
| 512 |
+// return nil |
| 513 |
+// }) |
| 514 |
+// return err |
| 515 |
+// }, key) |
| 516 |
+// if err == redis.TxFailedErr { |
| 517 |
+// return incr(key) |
| 518 |
+// } |
| 519 |
+// return err |
| 520 |
+// } |
| 521 |
+// |
| 522 |
+// var wg sync.WaitGroup |
| 523 |
+// for i := 0; i < 100; i++ { |
| 524 |
+// wg.Add(1) |
| 525 |
+// go func() { |
| 526 |
+// defer wg.Done() |
| 527 |
+// |
| 528 |
+// err := incr("counter3") |
| 529 |
+// if err != nil { |
| 530 |
+// panic(err) |
| 531 |
+// } |
| 532 |
+// }() |
| 533 |
+// } |
| 534 |
+// wg.Wait() |
| 535 |
+// |
| 536 |
+// n, err := client.Get("counter3").Int64() |
| 537 |
+// fmt.Println(n, err) |
| 538 |
+// // Output: 100 <nil> |
| 539 |
+//} |
| 540 |
+// |
| 541 |
+//func ExamplePubSub() { |
| 542 |
+// pubsub, err := client.Subscribe("mychannel1") |
| 543 |
+// if err != nil { |
| 544 |
+// panic(err) |
| 545 |
+// } |
| 546 |
+// defer pubsub.Close() |
| 547 |
+// |
| 548 |
+// err = client.Publish("mychannel1", "hello").Err() |
| 549 |
+// if err != nil { |
| 550 |
+// panic(err) |
| 551 |
+// } |
| 552 |
+// |
| 553 |
+// msg, err := pubsub.ReceiveMessage() |
| 554 |
+// if err != nil { |
| 555 |
+// panic(err) |
| 556 |
+// } |
| 557 |
+// |
| 558 |
+// fmt.Println(msg.Channel, msg.Payload) |
| 559 |
+// // Output: mychannel1 hello |
| 560 |
+//} |
| 561 |
+// |
| 562 |
+//func ExamplePubSub_Receive() { |
| 563 |
+// pubsub, err := client.Subscribe("mychannel2") |
| 564 |
+// if err != nil { |
| 565 |
+// panic(err) |
| 566 |
+// } |
| 567 |
+// defer pubsub.Close() |
| 568 |
+// |
| 569 |
+// n, err := client.Publish("mychannel2", "hello").Result() |
| 570 |
+// if err != nil { |
| 571 |
+// panic(err) |
| 572 |
+// } |
| 573 |
+// fmt.Println(n, "clients received message") |
| 574 |
+// |
| 575 |
+// for i := 0; i < 2; i++ { |
| 576 |
+// // ReceiveTimeout is a low level API. Use ReceiveMessage instead. |
| 577 |
+// msgi, err := pubsub.ReceiveTimeout(5 * time.Second) |
| 578 |
+// if err != nil { |
| 579 |
+// break |
| 580 |
+// } |
| 581 |
+// |
| 582 |
+// switch msg := msgi.(type) { |
| 583 |
+// case *redis.Subscription: |
| 584 |
+// fmt.Println("subscribed to", msg.Channel) |
| 585 |
+// case *redis.Message: |
| 586 |
+// fmt.Println("received", msg.Payload, "from", msg.Channel) |
| 587 |
+// default: |
| 588 |
+// panic(fmt.Errorf("unknown message: %#v", msgi)) |
| 589 |
+// } |
| 590 |
+// } |
| 591 |
+// |
| 592 |
+// // Output: 1 clients received message |
| 593 |
+// // subscribed to mychannel2 |
| 594 |
+// // received hello from mychannel2 |
| 595 |
+//} |
| 596 |
+// |
| 597 |
+//func ExampleScript() { |
| 598 |
+// IncrByXX := redis.NewScript(` |
| 599 |
+// if redis.call("GET", KEYS[1]) ~= false then |
| 600 |
+// return redis.call("INCRBY", KEYS[1], ARGV[1]) |
| 601 |
+// end |
| 602 |
+// return false |
| 603 |
+// `) |
| 604 |
+// |
| 605 |
+// n, err := IncrByXX.Run(client, []string{"xx_counter"}, 2).Result() |
| 606 |
+// fmt.Println(n, err) |
| 607 |
+// |
| 608 |
+// err = client.Set("xx_counter", "40", 0).Err() |
| 609 |
+// if err != nil { |
| 610 |
+// panic(err) |
| 611 |
+// } |
| 612 |
+// |
| 613 |
+// n, err = IncrByXX.Run(client, []string{"xx_counter"}, 2).Result() |
| 614 |
+// fmt.Println(n, err) |
| 615 |
+// |
| 616 |
+// // Output: <nil> redis: nil |
| 617 |
+// // 42 <nil> |
| 618 |
+//} |
| 619 |
+// |
| 620 |
+//func Example_customCommand() { |
| 621 |
+// Get := func(client *redis.Client, key string) *redis.StringCmd { |
| 622 |
+// cmd := redis.NewStringCmd("GET", key) |
| 623 |
+// client.Process(cmd) |
| 624 |
+// return cmd |
| 625 |
+// } |
| 626 |
+// |
| 627 |
+// v, err := Get(client, "key_does_not_exist").Result() |
| 628 |
+// fmt.Printf("%q %s", v, err) |
| 629 |
+// // Output: "" redis: nil |
| 630 |
+//} |
| 631 |
+// |
| 632 |
+//func ExampleScanIterator() { |
| 633 |
+// iter := client.Scan(0, "", 0).Iterator() |
| 634 |
+// for iter.Next() { |
| 635 |
+// fmt.Println(iter.Val()) |
| 636 |
+// } |
| 637 |
+// if err := iter.Err(); err != nil { |
| 638 |
+// panic(err) |
| 639 |
+// } |
| 640 |
+//} |
| 641 |
+// |
| 642 |
+//func ExampleScanCmd_Iterator() { |
| 643 |
+// iter := client.Scan(0, "", 0).Iterator() |
| 644 |
+// for iter.Next() { |
| 645 |
+// fmt.Println(iter.Val()) |
| 646 |
+// } |
| 647 |
+// if err := iter.Err(); err != nil { |
| 648 |
+// panic(err) |
| 649 |
+// } |
| 650 |
+//} |