Documentation
¶
Overview ¶
Package redisstreams is RunStreams over Redis Streams, shared by the Redis and Upstash adapters. Each stream is two keys in one hash slot: a hash with who it belongs to, whether it is closed and its end event, and the Redis Stream itself, one entry per event. The offset is the entry id. Every write is one Lua script, so a close can never slip between an append's check and its XADD. The TS adapters run the same scripts on the same keys (src/adapters/stream-scripts.ts).
Index ¶
- Constants
- func CompareIDs(a, b string) int
- func Key(streamID string) string
- func MetaKey(streamID string) string
- func Sleep(ctx context.Context, d time.Duration)
- type RunScript
- type Streams
- func (s *Streams) Append(ctx context.Context, streamID string, events []ports.StreamEvent) ([]string, error)
- func (s *Streams) Close(ctx context.Context, streamID string, end ports.StreamEnd, grace time.Duration) error
- func (s *Streams) Delete(ctx context.Context, streamID string) error
- func (s *Streams) Open(ctx context.Context, streamID string, meta ports.StreamMeta, ttl time.Duration) error
- func (s *Streams) Read(ctx context.Context, streamID, after string) iter.Seq2[ports.StreamItem, error]
- func (s *Streams) Snapshot(ctx context.Context, streamID, after string) (*ports.StreamSnapshot, error)
- type WaitForNews
Constants ¶
const AppendScript = `` /* 323-byte string literal not displayed */
AppendScript: KEYS meta, stream. ARGV one event JSON each. The entry ids, or -1 gone, -2 closed. The stream key takes the meta key's expiry.
const CloseScript = `` /* 315-byte string literal not displayed */
CloseScript: KEYS meta, stream. ARGV end JSON, graceMs. 1 closed, 0 already closed, -1 gone.
const DeleteScript = `redis.call('DEL', KEYS[1], KEYS[2]) return 1`
DeleteScript: KEYS meta, stream.
const OpenScript = `` /* 186-byte string literal not displayed */
OpenScript: KEYS meta, stream. ARGV threadId, runId, ttlMs. 1 opened, 0 already open.
const ReadScript = `` /* 210-byte string literal not displayed */
ReadScript: KEYS meta, stream. ARGV the XRANGE start ('-', or '(' + an entry id). -1 gone, else { threadId, runId, closed, the end JSON or an empty string, entries }.
Variables ¶
This section is empty.
Functions ¶
func CompareIDs ¶
CompareIDs compares two entry ids ("<ms>-<seq>").
Types ¶
type RunScript ¶
RunScript runs a script: the one thing the Redis and Upstash clients differ in. The reply uses Go's plain types: string, int64 (or a JSON number), []any.
type Streams ¶
type Streams struct {
Run RunScript
Wait WaitForNews
// Poll is the longest a reader waits before reading again, news or
// not: the floor under a missed wake-up.
Poll time.Duration
}
Streams implements ports.RunStreams over the scripts.