go-redis/redis · error

redis: Channel can't be called after ChannelWithSubscription

Error message

redis: Channel can't be called after ChannelWithSubscriptions

What it means

Error "redis: Channel can't be called after ChannelWithSubscriptions" thrown in go-redis/redis.

Source

Thrown at pubsub.go:578

	return context.Background()
}

//------------------------------------------------------------------------------

// Channel returns a Go channel for concurrently receiving messages.
// The channel is closed together with the PubSub. If the Go channel
// is blocked full for 1 minute the message is dropped.
// Receive* APIs can not be used after channel is created.
//
// go-redis periodically sends ping messages to test connection health
// and re-subscribes if ping can not received for 1 minute.
func (c *PubSub) Channel(opts ...ChannelOption) <-chan *Message {
	c.chOnce.Do(func() {
		c.msgCh = newChannel(c, opts...)
		c.msgCh.initMsgChan()
	})
	if c.msgCh == nil {
		err := fmt.Errorf("redis: Channel can't be called after ChannelWithSubscriptions")
		panic(err)
	}
	return c.msgCh.msgCh
}

// ChannelSize is like Channel, but creates a Go channel
// with specified buffer size.
//
// Deprecated: use Channel(WithChannelSize(size)), remove in v9.
func (c *PubSub) ChannelSize(size int) <-chan *Message {
	return c.Channel(WithChannelSize(size))
}

// ChannelWithSubscriptions is like Channel, but message type can be either
// *Subscription or *Message. Subscription messages can be used to detect
// reconnections.
//
// ChannelWithSubscriptions can not be used together with Channel or ChannelSize.

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Use only ChannelWithSubscriptions on this PubSub instance once it has been called
  2. Create a new PubSub if you need the Channel API

When it happens

Trigger: Thrown at pubsub.go:578 when the library encounters an invalid state.

Common situations: Pick one consumption API per PubSub instance and stick to it.


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/11ddeaf868afae3a.json. Report an issue: GitHub.