Pub/Sub, Transactions, Lua and Streams

Harry · 13 Sep 2026 · 1 views

Pub/Sub

SUBSCRIBE news          # subscriber
PUBLISH news "hello"    # publisher

Channels fan out messages to subscribers; use it for notifications, not for durable queues - missed messages are gone.

Transactions (MULTI/EXEC)

MULTI
INCR counter
LSET log 0 "updated"
EXEC

MULTI queues commands and runs them atomically on EXEC. Partial failures still execute the rest; combined with WATCH, it gives optimistic CAS behavior.

Lua Scripts

Atomic custom logic runs server-side:

EVAL "return redis.call('INCR', KEYS[1])" 1 visits

Scripts execute without interleaving, ideal for rate limits and inventory guards.

Streams

XADD events * user 42 action view
XREAD COUNT 5 STREAMS events 0      # read history
XGROUP CREATE events group-id 0     # consumer groups

Streams add durable, grouped message delivery - the modern Redis answer to queues and event logs.

Key Points

  • Pub/Sub is ephemeral; Streams add durability.
  • MULTI/WATCH give atomicity and optimistic control.
  • Lua scripts enforce custom atomic rules.
  • Streams bring consumer groups to Redis.
Share this post:

Comments (0)

Please login or register to comment.