Documentation ¶
Overview ¶
Package redispubsub provides an implementation of pubsub for Redis. It requires a minimum Redis version of 6.x for Streams support.
redispubsub does not support Message.Nack; Message.Nackable will return false, and Message.Nack will panic if called.
URLs ¶
For pubsub.OpenTopic and pubsub.OpenSubscription, redispubsub registers for the scheme "redis". The default URL opener will connect to a Redis Server based on the environment variable "REDIS_URL", expected to server address like "redis://<user>:<pass>@localhost:6379/<db>". To customize the URL opener, or for more details on the URL format, see URLOpener. See https://gocloud.dev/concepts/urls/ for background information.
Escaping ¶
Go CDK supports all UTF-8 strings. No escaping is required for Redis.
Index ¶
Constants ¶
const Scheme = "redis"
Scheme is the URL scheme that redispubsub registers its URLOpeners under on pubsub.DefaultMux.
Variables ¶
This section is empty.
Functions ¶
func OpenSubscription ¶
func OpenSubscription(broker *redis.Client, group, topic string, opts *SubscriptionOptions) (*pubsub.Subscription, error)
OpenSubscription creates a pubsub.Subscription that joins group, receiving messages from topics.
Types ¶
type SubscriptionOptions ¶
type SubscriptionOptions struct { From string // starting id ($ after tail of stream), 0 by default (from head of stream) Consumer string // unique consumer name NoAck bool AutoClaimIdleTime time.Duration }
SubscriptionOptions contains configuration for subscriptions.
type TopicOptions ¶
type TopicOptions struct { // BatcherOptions adds constraints to the default batching done for sends. BatcherOptions batcher.Options MaxLen int64 }
TopicOptions contains configuration options for topics.
type URLOpener ¶
type URLOpener struct { // Broker is the Redis parsed URL like "redis://<user>:<pass>@localhost:6379/<db>" with options. Broker *redis.Client // TopicOptions specifies the options to pass to OpenTopic. TopicOptions TopicOptions // SubscriptionOptions specifies the options to pass to OpenSubscription. SubscriptionOptions SubscriptionOptions }
URLOpener opens Redis URLs like "redis://mytopic" for topics and "redis://group?topic=mytopic" for subscriptions.
For topics, the URL's host+path is used as the topic name.
For subscriptions, the URL's host+path is used as the group name, and the "topic" query parameter(s) are used as the set of topics to subscribe to. The "offset" parameter is available to subscribers to set the Redis Streams consumer's initial offset. Where "oldest" starts consuming from the oldest offset of the consumer group and "newest" starts consuming from the most recent offset on the topic.
func (*URLOpener) OpenSubscriptionURL ¶
func (o *URLOpener) OpenSubscriptionURL(ctx context.Context, u *url.URL) (*pubsub.Subscription, error)
OpenSubscriptionURL opens a pubsub.Subscription based on u.