ReceiveMessage returns a Message or error ignoring Subscription and Pong messages. This is low-level API and in most cases Channel should be used instead.
(ctx context.Context)
| 533 | // messages. This is low-level API and in most cases Channel should be used |
| 534 | // instead. |
| 535 | func (c *PubSub) ReceiveMessage(ctx context.Context) (*Message, error) { |
| 536 | for { |
| 537 | msg, err := c.Receive(ctx) |
| 538 | if err != nil { |
| 539 | return nil, err |
| 540 | } |
| 541 | |
| 542 | switch msg := msg.(type) { |
| 543 | case *Subscription: |
| 544 | // Ignore. |
| 545 | case *Pong: |
| 546 | // Ignore. |
| 547 | case *Message: |
| 548 | return msg, nil |
| 549 | default: |
| 550 | err := fmt.Errorf("redis: unknown message: %T", msg) |
| 551 | return nil, err |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | func (c *PubSub) getContext() context.Context { |
| 557 | if c.cmd != nil { |
no test coverage detected