rediszset

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoSleep can be set to SubscriberConfig.NackResendSleep
	NoSleep time.Duration = -1

	DefaultBlockTime = time.Second

	DefaultRestTime = time.Millisecond * 100
)
View Source
const UUIDHeaderKey = "_watermill_message_uuid"

Variables

View Source
var DefaultConsumeRange = func(topic string) (min, max string, err error) {
	return "-inf", "+inf", nil
}

Functions

func GetScore

func GetScore(message *message.Message) (float64, error)

func NewMessage

func NewMessage(uuid string, score float64, payload message.Payload) *message.Message

Types

type BaseClient

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

func (BaseClient) Close

func (b BaseClient) Close() error

func (BaseClient) ZAdd

func (b BaseClient) ZAdd(ctx context.Context, key string, members ...redis.Z) (int64, error)

ZAdd available since 1.2.0

func (BaseClient) ZRem

func (b BaseClient) ZRem(ctx context.Context, key string, members ...interface{}) (int64, error)

ZRem available since 1.2.0

type BlockMode

type BlockMode int
const (
	Block BlockMode = iota
	NotBlock
)

type Client

type Client interface {
	ZRem(ctx context.Context, key string, members ...interface{}) (int64, error)
	ZAdd(ctx context.Context, key string, members ...redis.Z) (int64, error)

	ZPopMin(ctx context.Context, key string, count ...int64) ([]redis.Z, error)
	BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) (*redis.ZWithKey, error)

	Close() error
}

func NewClient

func NewClient(client redis.UniversalClient, version [3]int) Client

type Client2_0

type Client2_0 struct {
	BaseClient
}

func (Client2_0) BZPopMin

func (c Client2_0) BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) (*redis.ZWithKey, error)

func (Client2_0) ZPopMin

func (c Client2_0) ZPopMin(ctx context.Context, key string, count ...int64) ([]redis.Z, error)

type Client5_0

type Client5_0 struct {
	BaseClient
}

func (Client5_0) BZPopMin

func (c Client5_0) BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) (*redis.ZWithKey, error)

func (Client5_0) ZPopMin

func (c Client5_0) ZPopMin(ctx context.Context, key string, count ...int64) ([]redis.Z, error)

type ConsumeRange added in v0.0.3

type ConsumeRange func(topic string) (min, max string, err error)

type DefaultMarshallerUnmarshaller

type DefaultMarshallerUnmarshaller struct{}

func (DefaultMarshallerUnmarshaller) Marshal

func (DefaultMarshallerUnmarshaller) Unmarshal

func (DefaultMarshallerUnmarshaller) Unmarshal(values []byte) (msg *message.Message, err error)

type Locker

type Locker interface {
	Lock(ctx context.Context) (locked bool, err error)
	Unlock(ctx context.Context) error
}

type Marshaller

type Marshaller interface {
	Marshal(topic string, msg *message.Message) ([]byte, error)
}

type MarshallerUnmarshaller

type MarshallerUnmarshaller interface {
	Marshaller
	Unmarshaller
}

type Publisher

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

func NewPublisher

func NewPublisher(config PublisherConfig, logger watermill.LoggerAdapter) (*Publisher, error)

NewPublisher creates a new redis stream Publisher.

func (*Publisher) Close

func (p *Publisher) Close() error

func (*Publisher) Publish

func (p *Publisher) Publish(topic string, msgs ...*message.Message) error

Publish publishes message to redis zset

Publish is blocking and waits for redis response. When any of messages delivery fails - function is interrupted.

func (*Publisher) Remove

func (p *Publisher) Remove(topic string, msgs ...*message.Message) error

Remove message from redis zset Pay attention to Marshaller. It should not contain trace info and score. You can use WithoutScoreMarshallerUnmarshaller.

type PublisherConfig

type PublisherConfig struct {
	Client     redis.UniversalClient
	Marshaller Marshaller
}

func (*PublisherConfig) Validate

func (c *PublisherConfig) Validate() error

type StrictSubscriber

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

func NewStrictSubscriber

func NewStrictSubscriber(config StrictSubscriberConfig, locker Locker, logger watermill.LoggerAdapter) (*StrictSubscriber, error)

NewStrictSubscriber creates a new redis zset Subscriber.

func (*StrictSubscriber) Close

func (s *StrictSubscriber) Close() error

func (*StrictSubscriber) Subscribe

func (s *StrictSubscriber) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)

type StrictSubscriberConfig

type StrictSubscriberConfig struct {
	Client redis.UniversalClient

	Unmarshaller Unmarshaller

	// How long should we rest after got nothing
	RestTime time.Duration

	// After a failed consumption, the strictMessageHandler will receive a nack, and it is better to wait for some time before retrying.
	NackResendSleep time.Duration

	ConsumeRange ConsumeRange
}

func (*StrictSubscriberConfig) Validate

func (sc *StrictSubscriberConfig) Validate() error

type Subscriber

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

func NewSubscriber

func NewSubscriber(config SubscriberConfig, logger watermill.LoggerAdapter) (*Subscriber, error)

NewSubscriber creates a new redis zset Subscriber.

func (*Subscriber) Close

func (s *Subscriber) Close() error

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)

type SubscriberConfig

type SubscriberConfig struct {
	Client redis.UniversalClient

	Unmarshaller Unmarshaller

	// Block if there are no members to pop from sorted set if BlockMode is Block
	BlockMode BlockMode

	// Block to wait next redis zset message, only works while BlockMode is Block
	BlockTime time.Duration

	// How long should we rest after got nothing, only works while BlockMode is NotBlock
	RestTime time.Duration

	// After a failed consumption, the messageHandler will receive a nack, and it is better to wait for some time before retrying.
	NackResendSleep time.Duration
}

func (*SubscriberConfig) Validate

func (sc *SubscriberConfig) Validate() error

type Unmarshaller

type Unmarshaller interface {
	Unmarshal(values []byte) (msg *message.Message, err error)
}

type WithoutScoreMarshallerUnmarshaller

type WithoutScoreMarshallerUnmarshaller struct{}

func (WithoutScoreMarshallerUnmarshaller) Marshal

func (WithoutScoreMarshallerUnmarshaller) Unmarshal

func (WithoutScoreMarshallerUnmarshaller) Unmarshal(values []byte) (msg *message.Message, err error)

type WithoutTraceMarshallerUnmarshaller

type WithoutTraceMarshallerUnmarshaller struct{}

func (WithoutTraceMarshallerUnmarshaller) Marshal

func (WithoutTraceMarshallerUnmarshaller) Unmarshal

func (WithoutTraceMarshallerUnmarshaller) Unmarshal(values []byte) (msg *message.Message, err error)

Jump to

Keyboard shortcuts

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