Documentation
¶
Index ¶
- Variables
- func Call[Req, Resp any](c *Client, channel string, req Req, timeout time.Duration) (Resp, error)
- func CallMethod[Req, Resp any](c *Client, channel, method string, req Req, timeout time.Duration) (Resp, error)
- func IsCallError(err error) bool
- func PublishRouted[T any](c *Client, channel, msgType string, data T) error
- func PublishTyped[T any](c *Client, channel string, message T, opts ...SetOption) error
- func RegisterCall[Req, Resp any](s *CallServer, method string, handler func(Req) (Resp, error))
- func SendRequest[T any](c *Client, queue string, message T) error
- func StreamAdd[T any](sp *StreamPublisher, msg T) (string, error)
- type CallError
- type CallHandler
- type CallHandlerOption
- type CallServer
- type CallServerOption
- type Client
- func (c *Client) BLPop(timeout time.Duration, keys ...string) ([]string, error)
- func (c *Client) BRPop(timeout time.Duration, keys ...string) ([]string, error)
- func (c *Client) Close() error
- func (c *Client) CloseWithTimeout(timeout time.Duration) error
- func (c *Client) Codec() Codec
- func (c *Client) Connected() bool
- func (c *Client) Context() context.Context
- func (c *Client) Decr(key string) (int64, error)
- func (c *Client) Del(keys ...string) (int64, error)
- func (c *Client) Do(cmd string, args ...interface{}) (interface{}, error)
- func (c *Client) Exists(keys ...string) (int64, error)
- func (c *Client) Expire(key string, expiration time.Duration) (bool, error)
- func (c *Client) Get(key string) (string, error)
- func (c *Client) HGet(key, field string) (string, error)
- func (c *Client) HGetAll(key string) (map[string]string, error)
- func (c *Client) HSet(key, field string, value interface{}) error
- func (c *Client) Hash(name string) *HashPublisher
- func (c *Client) Incr(key string) (int64, error)
- func (c *Client) LPop(key string) (string, error)
- func (c *Client) LPush(key string, values ...interface{}) (int64, error)
- func (c *Client) Logger() *slog.Logger
- func (c *Client) NewFaultReporter(group string, opts ...FaultReporterOption) *FaultReporter
- func (c *Client) NewFaultSet(setKey, channel, payload string) *FaultSet
- func (c *Client) NewHashPublisher(hash string) *HashPublisher
- func (c *Client) NewHashPublisherWithChannel(hash, channel string) *HashPublisher
- func (c *Client) NewHashWatcher(hash string) *HashWatcher
- func (c *Client) NewHashWatcherWithChannel(hash, channel string) *HashWatcher
- func (c *Client) NewRouter(channel string) *Router
- func (c *Client) NewStreamConsumer(stream string, opts ...StreamConsumerOption) *StreamConsumer
- func (c *Client) NewStreamPublisher(stream string, opts ...StreamPublisherOption) *StreamPublisher
- func (c *Client) NewTx() *Tx
- func (c *Client) NewTxGroup() *TxGroup
- func (c *Client) NewTxWithContext(ctx context.Context) *Tx
- func (c *Client) Ping() error
- func (c *Client) Publish(channel string, message interface{}, opts ...SetOption) (int64, error)
- func (c *Client) RPop(key string) (string, error)
- func (c *Client) RPush(key string, values ...interface{}) (int64, error)
- func (c *Client) Raw() *redis.Client
- func (c *Client) Set(key string, value interface{}, expiration time.Duration) error
- func (c *Client) WithContext(ctx context.Context) *ContextClient
- type Codec
- type ContextClient
- type Envelope
- type FaultReporter
- type FaultReporterOption
- type FaultSetdeprecated
- type HashPublisher
- func (hp *HashPublisher) Channel() string
- func (hp *HashPublisher) Clear(opts ...SetOption) error
- func (hp *HashPublisher) Delete(field string, opts ...SetOption) error
- func (hp *HashPublisher) Get(field string) (string, error)
- func (hp *HashPublisher) GetAll() (map[string]string, error)
- func (hp *HashPublisher) Hash() string
- func (hp *HashPublisher) ReplaceAll(fields map[string]any, opts ...SetOption) error
- func (hp *HashPublisher) Set(field string, value any, opts ...SetOption) error
- func (hp *HashPublisher) SetIfChanged(field string, value any) (bool, error)
- func (hp *HashPublisher) SetMany(fields map[string]any, opts ...SetOption) error
- func (hp *HashPublisher) SetManyIfChanged(fields map[string]any) ([]string, error)
- func (hp *HashPublisher) SetManyPublishOne(fields map[string]any, notification string, opts ...SetOption) error
- func (hp *HashPublisher) SetWithTimestamp(field string, value any, opts ...SetOption) error
- type HashWatcher
- func (hw *HashWatcher) Fetch(field string) (string, error)
- func (hw *HashWatcher) FetchAll() (map[string]string, error)
- func (hw *HashWatcher) OnAny(handler func(field, value string) error) *HashWatcher
- func (hw *HashWatcher) OnEvent(event string, handler func() error) *HashWatcher
- func (hw *HashWatcher) OnField(field string, handler func(value string) error) *HashWatcher
- func (hw *HashWatcher) SetDebounce(d time.Duration) *HashWatcher
- func (hw *HashWatcher) Start() error
- func (hw *HashWatcher) StartWithSync() error
- func (hw *HashWatcher) Stop() error
- type JSONCodec
- type Option
- func WithAddress(addr string) Option
- func WithCodec(codec Codec) Option
- func WithDialTimeout(d time.Duration) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMaxRetries(n int) Option
- func WithOnConnect(fn func()) Option
- func WithOnDisconnect(fn func(error)) Option
- func WithPoolSize(n int) Option
- func WithPort(port int) Option
- func WithRetryInterval(d time.Duration) Option
- func WithURL(rawURL string) Option
- type QueueHandler
- type Router
- type SetOption
- type StreamConsumer
- type StreamConsumerOption
- type StreamPublisher
- type StreamPublisherOption
- type StringCodec
- type Subscription
- type Tx
- func (tx *Tx) Exec() error
- func (tx *Tx) FaultAdd(fs *FaultSet, code int)
- func (tx *Tx) FaultRemove(fs *FaultSet, code int)
- func (tx *Tx) FaultUpdate(fs *FaultSet, adds, removes []int)
- func (tx *Tx) HashSetManyIfChanged(hp *HashPublisher, fields map[string]any) []string
- func (tx *Tx) StreamAdd(sp *StreamPublisher, values map[string]any)
- type TxGroup
Constants ¶
This section is empty.
Variables ¶
var ErrCallTimeout = errors.New("redis-ipc: call timed out")
ErrCallTimeout is returned by Call when no response arrives within the caller-specified timeout.
var ErrClientClosed = fmt.Errorf("redis-ipc: client is closed")
ErrClientClosed is returned when registering a consumer on a client that is shutting down.
var ErrNil = redis.Nil
ErrNil is returned when a key or field does not exist in Redis.
var ErrUnknownMethod = errors.New("unknown method")
ErrUnknownMethod is returned (server-side) when a request arrives for a method that has no registered handler. The caller receives a *CallError whose Msg is "unknown method: X".
Functions ¶
func Call ¶ added in v0.12.0
Call sends a typed request to a Redis list-backed RPC channel and blocks until the response arrives or the timeout elapses. Returns ErrCallTimeout on timeout, *CallError on a server-side handler error, or a wrapped error for transport / decode failures.
func CallMethod ¶ added in v0.13.0
func CallMethod[Req, Resp any](c *Client, channel, method string, req Req, timeout time.Duration) (Resp, error)
CallMethod sends a typed request to a CallServer's per-service channel, addressed to a specific method. Same semantics as Call (sub-second timeouts, ErrCallTimeout / *CallError discrimination), just with an extra method field on the wire so a single channel can host many RPCs.
func IsCallError ¶ added in v0.12.0
IsCallError reports whether err originated as a server-side handler error.
func PublishRouted ¶
PublishRouted publishes a message with type routing
func PublishTyped ¶
PublishTyped publishes a typed message using the client's codec. By default async; use Sync() for synchronous operation.
func RegisterCall ¶ added in v0.13.0
func RegisterCall[Req, Resp any](s *CallServer, method string, handler func(Req) (Resp, error))
RegisterCall attaches a typed handler for one method. Must be called before Start. Re-registering the same method panics — that's a clear programmer error rather than a silent override.
func SendRequest ¶
SendRequest sends a typed message to a queue
Types ¶
type CallError ¶ added in v0.12.0
type CallError struct{ Msg string }
CallError wraps an error returned by a HandleCalls handler.
type CallHandler ¶ added in v0.12.0
type CallHandler[Req, Resp any] struct { // contains filtered or unexported fields }
CallHandler is the server side of a Call channel. Stop() drains in-flight handlers before returning.
func HandleCalls ¶ added in v0.12.0
func HandleCalls[Req, Resp any](c *Client, channel string, handler func(Req) (Resp, error), opts ...CallHandlerOption) *CallHandler[Req, Resp]
HandleCalls registers a typed RPC handler. The request channel joins the client's shared BRPOP loop; each incoming request is dispatched to a goroutine bounded by the concurrency option.
func (*CallHandler[Req, Resp]) Stop ¶ added in v0.12.0
func (h *CallHandler[Req, Resp]) Stop()
Stop signals the handler to stop accepting new requests and waits for in-flight handlers to finish.
type CallHandlerOption ¶ added in v0.12.0
type CallHandlerOption func(*callHandlerOpts)
CallHandlerOption configures a CallHandler.
func WithCallConcurrency ¶ added in v0.12.0
func WithCallConcurrency(n int) CallHandlerOption
WithCallConcurrency caps the number of in-flight handler invocations. Defaults to 4.
type CallServer ¶ added in v0.13.0
type CallServer struct {
// contains filtered or unexported fields
}
CallServer is the multi-method RPC server. One BRPOP loop, one concurrency-bounded dispatcher, many registered handlers.
func NewCallServer ¶ added in v0.13.0
func NewCallServer(c *Client, channel string, opts ...CallServerOption) *CallServer
NewCallServer returns a CallServer bound to a per-service request channel (e.g. "motion:rpc"). Use RegisterCall to attach typed handlers, then Start to begin processing requests.
func (*CallServer) Start ¶ added in v0.13.0
func (s *CallServer) Start()
Start joins the request channel to the client's shared BRPOP loop. Idempotent: repeated calls are no-ops.
func (*CallServer) Stop ¶ added in v0.13.0
func (s *CallServer) Stop()
Stop signals the server to stop accepting new requests and waits for in-flight handlers to finish.
type CallServerOption ¶ added in v0.13.0
type CallServerOption func(*callServerOpts)
CallServerOption configures a CallServer.
func WithCallServerConcurrency ¶ added in v0.13.0
func WithCallServerConcurrency(n int) CallServerOption
WithCallServerConcurrency caps in-flight handler invocations across all methods on this server. Default 4.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main Redis IPC client
func (*Client) CloseWithTimeout ¶
CloseWithTimeout shuts down the client with a maximum wait time
func (*Client) Hash ¶ added in v0.6.0
func (c *Client) Hash(name string) *HashPublisher
Hash returns a cached HashPublisher for the given hash name. Publishers are created on first access and reused thereafter. This is more ergonomic than NewHashPublisher when you don't need to store the publisher in a struct field.
func (*Client) NewFaultReporter ¶ added in v0.14.0
func (c *Client) NewFaultReporter(group string, opts ...FaultReporterOption) *FaultReporter
NewFaultReporter creates a FaultReporter for the given group. Defaults follow the Librescoot convention:
set key: "<group>:fault" channel: "<group>" payload: "fault" stream: "events:faults" MAXLEN: ~1000
func (*Client) NewFaultSet ¶
NewFaultSet creates a fault set manager. Example: NewFaultSet("battery:0:fault", "battery:0", "fault")
func (*Client) NewHashPublisher ¶
func (c *Client) NewHashPublisher(hash string) *HashPublisher
NewHashPublisher creates a publisher for a hash. By convention, the channel name equals the hash name.
func (*Client) NewHashPublisherWithChannel ¶
func (c *Client) NewHashPublisherWithChannel(hash, channel string) *HashPublisher
NewHashPublisherWithChannel creates a publisher with a custom channel name.
func (*Client) NewHashWatcher ¶
func (c *Client) NewHashWatcher(hash string) *HashWatcher
NewHashWatcher creates a watcher for a hash. By convention, the channel name equals the hash name.
func (*Client) NewHashWatcherWithChannel ¶
func (c *Client) NewHashWatcherWithChannel(hash, channel string) *HashWatcher
NewHashWatcherWithChannel creates a watcher with a custom channel name.
func (*Client) NewStreamConsumer ¶
func (c *Client) NewStreamConsumer(stream string, opts ...StreamConsumerOption) *StreamConsumer
NewStreamConsumer creates a consumer for a Redis stream.
func (*Client) NewStreamPublisher ¶
func (c *Client) NewStreamPublisher(stream string, opts ...StreamPublisherOption) *StreamPublisher
NewStreamPublisher creates a publisher for a Redis stream.
func (*Client) NewTxGroup ¶
NewTxGroup creates a new transaction group
func (*Client) NewTxWithContext ¶ added in v0.11.0
NewTxWithContext creates a new transaction with a specific context.
func (*Client) Publish ¶
Publish publishes a message to a channel. By default, this is async (fire-and-forget) for performance. Use Sync() option when you need to confirm the publish succeeded or need the subscriber count.
func (*Client) WithContext ¶ added in v0.7.0
func (c *Client) WithContext(ctx context.Context) *ContextClient
WithContext returns a context-scoped client wrapper. Use this when you need a custom context (e.g., with timeout) for operations.
type ContextClient ¶ added in v0.7.0
type ContextClient struct {
*Client
// contains filtered or unexported fields
}
ContextClient wraps a Client with a specific context for operations.
func (*ContextClient) Context ¶ added in v0.7.0
func (cc *ContextClient) Context() context.Context
Context returns the custom context for this wrapper.
type Envelope ¶
type Envelope struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
Envelope is the standard message format for routed messages
type FaultReporter ¶ added in v0.14.0
type FaultReporter struct {
// contains filtered or unexported fields
}
FaultReporter couples a fault set, the events:faults stream, and the per-group pubsub notification into a single primitive. Raise and Clear run as a server-side EVAL transaction: SADD/SREM, branch on the change count, and only emit XADD + PUBLISH on a real state transition. Set and stream cannot drift, even across process restarts or crashing callers.
func (*FaultReporter) All ¶ added in v0.14.0
func (fr *FaultReporter) All() ([]int, error)
All returns all fault codes currently in the set, parsed as ints. Returns an error if any member can't be parsed as an integer.
func (*FaultReporter) Clear ¶ added in v0.14.0
func (fr *FaultReporter) Clear(code int) error
Clear marks code as absent. Idempotent: returns nil and emits no stream entry if the code is not in the set.
func (*FaultReporter) Group ¶ added in v0.14.0
func (fr *FaultReporter) Group() string
Group returns the group name.
type FaultReporterOption ¶ added in v0.14.0
type FaultReporterOption func(*faultReporterOptions)
FaultReporterOption configures a FaultReporter.
func WithFaultChannel ¶ added in v0.14.0
func WithFaultChannel(ch string) FaultReporterOption
WithFaultChannel overrides the pubsub channel. Default: "<group>".
func WithFaultMaxLen ¶ added in v0.14.0
func WithFaultMaxLen(n int64) FaultReporterOption
WithFaultMaxLen overrides the stream MAXLEN. Default: 1000 (approximate).
func WithFaultPayload ¶ added in v0.14.0
func WithFaultPayload(p string) FaultReporterOption
WithFaultPayload overrides the pubsub payload. Default: "fault".
func WithFaultSetKey ¶ added in v0.14.0
func WithFaultSetKey(key string) FaultReporterOption
WithFaultSetKey overrides the fault set key. Default: "<group>:fault".
func WithFaultStream ¶ added in v0.14.0
func WithFaultStream(s string) FaultReporterOption
WithFaultStream overrides the events stream name. Default: "events:faults".
type FaultSet
deprecated
type FaultSet struct {
// contains filtered or unexported fields
}
FaultSet manages a Redis set of fault codes with pub/sub notification.
Deprecated: prefer FaultReporter, which couples the set, the events:faults stream, and the pubsub notification into one primitive so the stream and set cannot drift. FaultSet stays for callers that don't need the stream.
type HashPublisher ¶
type HashPublisher struct {
// contains filtered or unexported fields
}
HashPublisher provides atomic HSET + PUBLISH with change detection. This matches the Librescoot pattern where: - State is stored in a Redis hash - Changes are notified via pub/sub with the field name as payload - Consumers fetch the value using HGET
func (*HashPublisher) Channel ¶
func (hp *HashPublisher) Channel() string
Channel returns the channel name.
func (*HashPublisher) Clear ¶ added in v0.4.0
func (hp *HashPublisher) Clear(opts ...SetOption) error
Clear deletes the entire hash and publishes "cleared". By default, this is async (fire-and-forget). Use Sync() for confirmation. Use NoPublish() to skip publishing.
func (*HashPublisher) Delete ¶ added in v0.4.0
func (hp *HashPublisher) Delete(field string, opts ...SetOption) error
Delete removes a field from the hash and publishes the field name. By default, this is async (fire-and-forget). Use Sync() for confirmation. Use NoPublish() to skip publishing — useful when retiring a field that no consumer should be woken for.
func (*HashPublisher) Get ¶
func (hp *HashPublisher) Get(field string) (string, error)
Get retrieves a field value from the hash.
func (*HashPublisher) GetAll ¶
func (hp *HashPublisher) GetAll() (map[string]string, error)
GetAll retrieves all fields from the hash.
func (*HashPublisher) ReplaceAll ¶ added in v0.4.0
func (hp *HashPublisher) ReplaceAll(fields map[string]any, opts ...SetOption) error
ReplaceAll atomically deletes all fields and sets new ones. This solves the race condition in DEL + HMSET + PUBLISH patterns. Publishes "replaced", or "cleared" if fields is nil or empty. By default, this is async (fire-and-forget). Use Sync() for confirmation. Use NoPublish() to skip publishing.
func (*HashPublisher) Set ¶
func (hp *HashPublisher) Set(field string, value any, opts ...SetOption) error
Set atomically sets a hash field and publishes the field name. By default, this is async (fire-and-forget) for performance. Use Sync() option to wait for Redis confirmation. Use NoPublish() to skip publishing.
func (*HashPublisher) SetIfChanged ¶
func (hp *HashPublisher) SetIfChanged(field string, value any) (bool, error)
SetIfChanged atomically sets a hash field and publishes only if the value changed. Returns true if the value was changed and published.
func (*HashPublisher) SetMany ¶
func (hp *HashPublisher) SetMany(fields map[string]any, opts ...SetOption) error
SetMany atomically sets multiple fields and publishes each one. By default, this is async (fire-and-forget) for performance. Use Sync() option to wait for Redis confirmation. Use NoPublish() to skip publishing.
func (*HashPublisher) SetManyIfChanged ¶
func (hp *HashPublisher) SetManyIfChanged(fields map[string]any) ([]string, error)
SetManyIfChanged atomically sets multiple fields, publishing only changed ones. Returns the list of fields that were actually changed.
func (*HashPublisher) SetManyPublishOne ¶ added in v0.5.0
func (hp *HashPublisher) SetManyPublishOne(fields map[string]any, notification string, opts ...SetOption) error
SetManyPublishOne sets multiple fields but publishes only a single notification. Useful for batch updates where you only want one notification at the end. The notification parameter is published as the message payload. By default, this is async (fire-and-forget). Use Sync() for confirmation. Use NoPublish() to skip the notification.
func (*HashPublisher) SetWithTimestamp ¶
func (hp *HashPublisher) SetWithTimestamp(field string, value any, opts ...SetOption) error
SetWithTimestamp atomically sets a field, its timestamp, and publishes. By default, this is async (fire-and-forget). Use Sync() for confirmation. Use NoPublish() to skip publishing.
type HashWatcher ¶
type HashWatcher struct {
// contains filtered or unexported fields
}
HashWatcher subscribes to a channel and fetches hash values on notification. This matches the Librescoot consumer pattern.
func OnFieldTyped ¶
func OnFieldTyped[T any](hw *HashWatcher, field string, handler func(T) error) *HashWatcher
OnFieldTyped registers a typed handler for a specific field. The value is JSON-decoded into the type T.
func (*HashWatcher) Fetch ¶
func (hw *HashWatcher) Fetch(field string) (string, error)
Fetch retrieves a specific field from the hash.
func (*HashWatcher) FetchAll ¶
func (hw *HashWatcher) FetchAll() (map[string]string, error)
FetchAll retrieves all current values from the hash. Useful for initial state sync.
func (*HashWatcher) OnAny ¶
func (hw *HashWatcher) OnAny(handler func(field, value string) error) *HashWatcher
OnAny registers a catch-all handler for any field not explicitly handled.
func (*HashWatcher) OnEvent ¶ added in v0.8.0
func (hw *HashWatcher) OnEvent(event string, handler func() error) *HashWatcher
OnEvent registers a handler for an event-only message. Unlike OnField, this does not fetch from the hash - it fires immediately when the message is received. Use for notifications that don't have corresponding hash state.
func (*HashWatcher) OnField ¶
func (hw *HashWatcher) OnField(field string, handler func(value string) error) *HashWatcher
OnField registers a handler for a specific field. When a message is received with this field name, the handler is called with the fetched value from the hash.
func (*HashWatcher) SetDebounce ¶
func (hw *HashWatcher) SetDebounce(d time.Duration) *HashWatcher
SetDebounce sets a debounce duration for handler calls. When set, rapid updates to the same field are coalesced - only the last value is passed to the handler after the quiet period expires.
func (*HashWatcher) Start ¶
func (hw *HashWatcher) Start() error
Start begins listening for messages and fetching values.
func (*HashWatcher) StartWithSync ¶
func (hw *HashWatcher) StartWithSync() error
StartWithSync subscribes, fetches current state, calls handlers, then processes messages. This ensures no messages are missed between initial fetch and subscribe. Order: Subscribe (messages buffer) → HGETALL → call handlers → process buffered messages
The subscription rides the client's shared pub/sub connection, but the ordering guarantee is unchanged and in fact stricter: subscribe() returns only once Redis has confirmed the SUBSCRIBE, and the gated subscriber buffers everything that arrives until release() below.
func (*HashWatcher) Stop ¶
func (hw *HashWatcher) Stop() error
Stop stops the watcher. The underlying channel stays subscribed on the shared connection if another watcher in this process still wants it.
type Option ¶
type Option func(*options)
Option configures the client
func WithDialTimeout ¶
WithDialTimeout sets the connection timeout
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of retries for commands
func WithOnConnect ¶
func WithOnConnect(fn func()) Option
WithOnConnect sets a callback invoked when connection is established
func WithOnDisconnect ¶
WithOnDisconnect sets a callback invoked when connection is lost
func WithRetryInterval ¶
WithRetryInterval sets the connection monitoring interval
type QueueHandler ¶
type QueueHandler[T any] struct { // contains filtered or unexported fields }
QueueHandler processes messages from a Redis list
func HandleRequests ¶
func HandleRequests[T any](c *Client, queue string, handler func(T) error) *QueueHandler[T]
HandleRequests creates a typed queue handler. The queue joins the client's shared BRPOP loop: every queue in the process is served by one blocking connection, with a dedicated goroutine per queue so a slow handler only stalls its own queue.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router provides message-type based routing for a channel
type SetOption ¶ added in v0.5.0
type SetOption func(*setConfig)
SetOption configures Set/SetMany behavior
type StreamConsumer ¶
type StreamConsumer struct {
// contains filtered or unexported fields
}
StreamConsumer consumes messages from a Redis stream using XREAD.
func StreamHandle ¶
func StreamHandle[T any](sc *StreamConsumer, handler func(id string, msg T) error) *StreamConsumer
StreamHandle registers a typed handler for stream messages.
func (*StreamConsumer) Handle ¶
func (sc *StreamConsumer) Handle(handler func(id string, values map[string]string) error) *StreamConsumer
Handle sets the message handler function.
func (*StreamConsumer) Running ¶
func (sc *StreamConsumer) Running() bool
Running returns whether the consumer is currently running.
func (*StreamConsumer) Start ¶
func (sc *StreamConsumer) Start(startID string) error
Start begins consuming messages from the stream. startID can be:
- "$" to read only new messages
- "0" to read from the beginning
- A specific message ID to read after that ID
- ">" for consumer groups (only undelivered messages)
func (*StreamConsumer) Stop ¶
func (sc *StreamConsumer) Stop()
Stop stops the consumer (by cancelling the context passed to Start). Note: The consumer stops when the context passed to Start is cancelled.
type StreamConsumerOption ¶
type StreamConsumerOption func(*streamConsumerOptions)
StreamConsumerOption configures a StreamConsumer
func WithBlockTimeout ¶
func WithBlockTimeout(d time.Duration) StreamConsumerOption
WithBlockTimeout sets the XREAD block timeout
func WithConsumerGroup ¶
func WithConsumerGroup(group, consumer string) StreamConsumerOption
WithConsumerGroup configures consumer group mode (XREADGROUP)
type StreamPublisher ¶
type StreamPublisher struct {
// contains filtered or unexported fields
}
StreamPublisher publishes messages to a Redis stream using XADD.
func (*StreamPublisher) Add ¶
func (sp *StreamPublisher) Add(values map[string]any) (string, error)
Add publishes a message to the stream with auto-generated ID. Returns the generated message ID.
func (*StreamPublisher) Stream ¶
func (sp *StreamPublisher) Stream() string
Stream returns the stream name.
type StreamPublisherOption ¶
type StreamPublisherOption func(*streamPublisherOptions)
StreamPublisherOption configures a StreamPublisher
func WithMaxLen ¶
func WithMaxLen(n int64) StreamPublisherOption
WithMaxLen sets the maximum stream length (MAXLEN option)
type Subscription ¶
type Subscription[T any] struct { // contains filtered or unexported fields }
Subscription is a typed channel subscription
func (*Subscription[T]) Unsubscribe ¶
func (s *Subscription[T]) Unsubscribe() error
Unsubscribe stops the subscription
type Tx ¶ added in v0.11.0
type Tx struct {
// contains filtered or unexported fields
}
Tx groups operations from multiple redis-ipc types into one atomic pipeline (MULTI/EXEC). Cache updates are deferred and only applied after a successful Exec.
func (*Tx) Exec ¶ added in v0.11.0
Exec executes all queued operations atomically via MULTI/EXEC. On success, applies deferred cache updates. On failure, the cache is unchanged.
func (*Tx) FaultRemove ¶ added in v0.11.0
FaultRemove queues SREM and PUBLISH for a fault code.
func (*Tx) FaultUpdate ¶ added in v0.11.0
FaultUpdate queues a batch of adds and removes with a single PUBLISH.
func (*Tx) HashSetManyIfChanged ¶ added in v0.11.0
func (tx *Tx) HashSetManyIfChanged(hp *HashPublisher, fields map[string]any) []string
HashSetManyIfChanged queues HSET for all fields and PUBLISH for each changed field. Returns the list of fields that differ from the cached state. The cache is only updated if Exec succeeds.
