redis

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	App       string // app namespace prefix
	Namespace string

	HealthInterval time.Duration
	SendTimeout    time.Duration
	ChannelSize    int
}

type Option

type Option interface {
	Apply(*Config)
}

An Option configures a pubsub instance.

func WithApp

func WithApp(value string) Option

WithApp returns an option that set config app name.

func WithHealthCheckInterval

func WithHealthCheckInterval(value time.Duration) Option

WithHealthCheckInterval specifies the config health check interval. PubSub will ping Server if it does not receive any messages within the interval (redis, ...). To disable health check, use zero interval.

func WithNamespace

func WithNamespace(value string) Option

WithNamespace returns an option that set config namespace.

func WithSendTimeout

func WithSendTimeout(value time.Duration) Option

WithSendTimeout specifies the pubsub send timeout after which the message is dropped.

func WithSize

func WithSize(value int) Option

WithSize specifies the Go chan size in config that is used to buffer incoming messages.

type OptionFunc

type OptionFunc func(*Config)

OptionFunc is a function that configures a pubsub config.

func (OptionFunc) Apply

func (f OptionFunc) Apply(config *Config)

Apply calls f(config).

type PubSub

type PubSub struct {
	// contains filtered or unexported fields
}

func New

func New(client redis.UniversalClient, options ...Option) *PubSub

NewRedis create an instance of redis PubSub implementation.

func (*PubSub) Close

func (r *PubSub) Close(_ context.Context) error

func (*PubSub) Publish

func (ps *PubSub) Publish(ctx context.Context, topic string, payload []byte, opts ...pubsub.PublishOption) error

Publish event topic to message broker with payload.

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(
	ctx context.Context,
	topic string,
	handler func(msg *pubsub.Msg) error,
	options ...pubsub.SubscribeOption,
) pubsub.Consumer

Subscribe consumer to process the event with payload.

func (*PubSub) SubscribeChan added in v0.4.0

func (ps *PubSub) SubscribeChan(
	ctx context.Context,
	topic string,
	options ...pubsub.SubscribeOption,
) (pubsub.Consumer, <-chan *pubsub.Msg)

type RedisPubSub

type RedisPubSub interface {
}

type SubscribeConfig

type SubscribeConfig struct {
	// contains filtered or unexported fields
}

type SubscribeOption

type SubscribeOption interface {
	Apply(*SubscribeConfig)
}

SubscribeOption configures a subscription config.

func WithChannelHealthCheckInterval

func WithChannelHealthCheckInterval(value time.Duration) SubscribeOption

WithChannelHealthCheckInterval specifies the channel health check interval. PubSub will ping Server if it does not receive any messages within the interval. To disable health check, use zero interval.

func WithChannelNamespace

func WithChannelNamespace(value string) SubscribeOption

WithNamespace returns an channel option that configures namespace.

func WithChannelSendTimeout

func WithChannelSendTimeout(value time.Duration) SubscribeOption

WithChannelSendTimeout specifies the channel send timeout after which the message is dropped.

func WithChannelSize

func WithChannelSize(value int) SubscribeOption

WithChannelSize specifies the Go chan size that is used to buffer incoming messages for subscriber.

func WithTopics

func WithTopics(topics ...string) SubscribeOption

WithTopics specifies the topics to subsribe.

type SubscribeOptionFunc

type SubscribeOptionFunc func(*SubscribeConfig)

SubscribeOptionFunc is a function that configures a subscription config.

func (SubscribeOptionFunc) Apply

func (f SubscribeOptionFunc) Apply(config *SubscribeConfig)

Apply calls f(subscribeConfig).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL