redis

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec[T any] interface {
	Marshal(v T) ([]byte, error)
	Unmarshal(data []byte, v *T) error
}

Codec 定义信号编解码能力。

type ErrorLogger

type ErrorLogger interface {
	Error(args ...any)
}

ErrorLogger 适配具备 Error 方法的日志实现。

type JSONCodec

type JSONCodec[T any] struct{}

JSONCodec 使用 JSON 编解码信号。

func (JSONCodec[T]) Marshal

func (JSONCodec[T]) Marshal(v T) ([]byte, error)

func (JSONCodec[T]) Unmarshal

func (JSONCodec[T]) Unmarshal(data []byte, v *T) error

type Options

type Options struct {
	// Prefix 与 signal_name 组成 channel:{prefix}:{signal_name}。
	Prefix string
	// Channel 显式指定 channel,优先级高于 Prefix + SignalName。
	Channel string
	// BufferSize 为 Pub/Sub channel 缓冲区大小。
	BufferSize int
	// ReadTimeout 保留字段,用于后续扩展读取超时策略。
	ReadTimeout time.Duration
	// ErrorHandler 处理监听中的非致命错误(如 decode 失败)。
	ErrorHandler func(error)
}

Options 定义 Redis signaling 行为。

func DefaultOptions

func DefaultOptions() Options

DefaultOptions 返回默认配置。

type Signaler

type Signaler[T signaling.Signal] struct {
	// contains filtered or unexported fields
}

Signaler 实现 signaling.Notifier 与 signaling.Watcher。

func NewSignaler

func NewSignaler[T signaling.Signal](client goredis.UniversalClient, opts Options) *Signaler[T]

NewSignaler 创建 Redis signaling 实现。

func NewSignalerWithCodec

func NewSignalerWithCodec[T signaling.Signal](client goredis.UniversalClient, opts Options, codec Codec[T]) *Signaler[T]

NewSignalerWithCodec 使用自定义 codec 创建 Signaler。

func (*Signaler[T]) Notify

func (s *Signaler[T]) Notify(ctx context.Context, signal T) error

Notify 发布一个信号(best-effort)。

func (*Signaler[T]) Watch

func (s *Signaler[T]) Watch(ctx context.Context, handler signaling.Handler[T]) error

Watch 监听信号并交给 handler 处理。

Jump to

Keyboard shortcuts

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