(ctx context.Context, cn *pool.Conn, reply interface{})
| 420 | } |
| 421 | |
| 422 | func (c *PubSub) newMessage(ctx context.Context, cn *pool.Conn, reply interface{}) (interface{}, error) { |
| 423 | switch reply := reply.(type) { |
| 424 | case string: |
| 425 | return &Pong{ |
| 426 | Payload: reply, |
| 427 | }, nil |
| 428 | case []interface{}: |
| 429 | switch kind := reply[0].(string); kind { |
| 430 | case "subscribe", "unsubscribe", "psubscribe", "punsubscribe", "ssubscribe", "sunsubscribe": |
| 431 | // Can be nil in case of "unsubscribe". |
| 432 | channel, _ := reply[1].(string) |
| 433 | return &Subscription{ |
| 434 | Kind: kind, |
| 435 | Channel: channel, |
| 436 | Count: int(reply[2].(int64)), |
| 437 | }, nil |
| 438 | case "message", "smessage": |
| 439 | channel := reply[1].(string) |
| 440 | sharded := kind == "smessage" |
| 441 | switch payload := reply[2].(type) { |
| 442 | case string: |
| 443 | msg := &Message{ |
| 444 | Channel: channel, |
| 445 | Payload: payload, |
| 446 | } |
| 447 | // Record PubSub message received |
| 448 | otel.RecordPubSubMessage(ctx, cn, "received", channel, sharded) |
| 449 | return msg, nil |
| 450 | case []interface{}: |
| 451 | ss := make([]string, len(payload)) |
| 452 | for i, s := range payload { |
| 453 | ss[i] = s.(string) |
| 454 | } |
| 455 | msg := &Message{ |
| 456 | Channel: channel, |
| 457 | PayloadSlice: ss, |
| 458 | } |
| 459 | // Record PubSub message received |
| 460 | otel.RecordPubSubMessage(ctx, cn, "received", channel, sharded) |
| 461 | return msg, nil |
| 462 | default: |
| 463 | return nil, fmt.Errorf("redis: unsupported pubsub message payload: %T", payload) |
| 464 | } |
| 465 | case "pmessage": |
| 466 | channel := reply[2].(string) |
| 467 | msg := &Message{ |
| 468 | Pattern: reply[1].(string), |
| 469 | Channel: channel, |
| 470 | Payload: reply[3].(string), |
| 471 | } |
| 472 | // Record PubSub message received (pattern message, not sharded) |
| 473 | otel.RecordPubSubMessage(ctx, cn, "received", channel, false) |
| 474 | return msg, nil |
| 475 | case "pong": |
| 476 | return &Pong{ |
| 477 | Payload: reply[1].(string), |
| 478 | }, nil |
| 479 | default: |
no test coverage detected