()
| 560 | } |
| 561 | |
| 562 | func ExamplePubSub_Receive() { |
| 563 | pubsub := rdb.Subscribe(ctx, "mychannel2") |
| 564 | defer pubsub.Close() |
| 565 | |
| 566 | for i := 0; i < 2; i++ { |
| 567 | // ReceiveTimeout is a low level API. Use ReceiveMessage instead. |
| 568 | msgi, err := pubsub.ReceiveTimeout(ctx, time.Second) |
| 569 | if err != nil { |
| 570 | break |
| 571 | } |
| 572 | |
| 573 | switch msg := msgi.(type) { |
| 574 | case *redis.Subscription: |
| 575 | fmt.Println("subscribed to", msg.Channel) |
| 576 | |
| 577 | _, err := rdb.Publish(ctx, "mychannel2", "hello").Result() |
| 578 | if err != nil { |
| 579 | panic(err) |
| 580 | } |
| 581 | case *redis.Message: |
| 582 | fmt.Println("received", msg.Payload, "from", msg.Channel) |
| 583 | default: |
| 584 | panic("unreached") |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | // sent message to 1 rdb |
| 589 | // received hello from mychannel2 |
| 590 | } |
| 591 | |
| 592 | func ExampleScript() { |
| 593 | IncrByXX := redis.NewScript(` |
nothing calls this directly
no test coverage detected