redis

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetChannelNameForApplication

func GetChannelNameForApplication(baseChannelName string, applicationId string) string

GetChannelNameForApplication returns the Redis channel name for the given application ID.

func GetResponseKeyForMessage

func GetResponseKeyForMessage(baseChannelName string, messageId string) string

GetResponseKeyForMessage returns the Redis key for the response of a message

func IsNoHandlerFound added in v0.3.0

func IsNoHandlerFound(err error, resp *funcie.Response) bool

IsNoHandlerFound returns true if the given error is a ErrNoHandlerFound, or if the given response is a NoHandlerFound response.

func NewConsumer

func NewConsumer(redisClient *redis.Client, baseChannelName string, router utils.ClientHandlerRouter) funcie.Consumer

NewConsumer creates a new RedisConsumer that consumes messages from channels starting with the given base name. This implementation takes in a *redis.Client instead of a RedisConsumeClient so that it can be used with a real Redis client.

func NewConsumerWithClient

func NewConsumerWithClient(redisClient ConsumeClient, baseChannelName string, router utils.ClientHandlerRouter) funcie.Consumer

NewConsumerWithClient creates a new RedisConsumer that consumes messages from channels starting with the given base name.

func NewPublisher

func NewPublisher(redisClient PublishClient, baseChannelName string) funcie.Publisher

NewPublisher creates a new RedisPublisher that publishes messages to the given channel.

Types

type ConsumeClient

type ConsumeClient interface {
	Subscribe(ctx context.Context, channels ...string) PubSub
	RPush(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
	Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd
}

ConsumeClient is the interface that wraps the redis client methods used by the consumer.

type Consumer

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

Consumer represents a consumer that consumes messages from a Redis channel.

func (*Consumer) Connect

func (c *Consumer) Connect(ctx context.Context) error

func (*Consumer) Consume

func (c *Consumer) Consume(ctx context.Context) error

func (*Consumer) Subscribe

func (c *Consumer) Subscribe(ctx context.Context, applicationId string, handler funcie.Handler) error

func (*Consumer) Unsubscribe

func (c *Consumer) Unsubscribe(ctx context.Context, applicationId string) error

type PubSub

type PubSub interface {
	Channel(opts ...redis.ChannelOption) <-chan *redis.Message
	Subscribe(ctx context.Context, channels ...string) error
	Unsubscribe(ctx context.Context, channels ...string) error
	Receive(ctx context.Context) (interface{}, error)
	Close() error
}

PubSub is the interface that wraps the redis PubSub methods used by the consumer.

type PublishClient

type PublishClient interface {
	Publish(ctx context.Context, channel string, message interface{}) *redis.IntCmd
	BRPop(ctx context.Context, timeout time.Duration, keys ...string) *redis.StringSliceCmd
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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