shibuya-redis-adapter: Redis Streams adapter for Shibuya

[ concurrency, database, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

Connect Shibuya processors to Redis Streams using either an independent ordered reader with checkpoints or a consumer-group worker with fenced pending-entry recovery. Both modes support dead-lettering and OpenTelemetry trace correlation.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
examples

Build the reader and worker example programs.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies async (>=2.2 && <2.3), base (>=4.21 && <4.22), bytestring (>=0.12 && <0.13), containers (>=0.7 && <0.8), directory (>=1.3 && <1.4), effectful-core (>=2.6.1 && <2.7 || >=2.7.1.1 && <2.8), entropy (>=0.4.1 && <0.5), filepath (>=1.5 && <1.6), hedis (>=0.16.4 && <0.17), hs-opentelemetry-api (>=1.0 && <1.1), shibuya-core (>=0.13.0.1 && <0.14), shibuya-redis-adapter, stm (>=2.5 && <2.6), streamly-core (>=0.3 && <0.4), temporary (>=1.3 && <1.4), text (>=2.1 && <2.2), unordered-containers (>=0.2 && <0.3) [details]
Tested with ghc ==9.12.4
License MIT
Copyright 2026 Nadeem Bitar
Author Nadeem Bitar
Maintainer nadeem@gmail.com
Uploaded by shinzui at 2026-11-25T14:45:45Z
Category Concurrency, Database
Home page https://github.com/shinzui/shibuya-redis-adapter
Bug tracker https://github.com/shinzui/shibuya-redis-adapter/issues
Source repo head: git clone https://github.com/shinzui/shibuya-redis-adapter.git
Distributions
Executables worker-example, reader-example
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for shibuya-redis-adapter-0.1.0.0

[back to package description]

Shibuya Redis Streams adapter

This Haskell library connects Shibuya processors to one Redis Stream per adapter on a single primary.

Use case Constructor Progress
A projection or live subscriber needs its own ordered copy newReader and readerProcessor Completed cursor with optional application-managed checkpoint
Workers share jobs and recover abandoned assignments newGroupWorker and groupProcessor Redis group position, pending entries and fenced attempt state

Both constructors accept a raw binary entry or a typed decoder. They preserve field order and duplicate names. The envelope's stable message ID is an application idempotency key. Commit external effects with that key in durable application storage when they must survive replay.

See the adapter guides and reference for integration details and the capability catalog for the behavior and limits of each feature.

Run both examples

The package builds its library by default. The repository's cabal.project and Nix build enable the examples flag. Use -fexamples when building from the source archive.

Start the project-local Redis service in one terminal. Stop it with Ctrl-C after the demo.

nix develop
process-compose -U up -t=false

In another terminal, start from the repository root. Use a fresh stream and checkpoint file.

nix develop
stream="shibuya-demo-$(date +%s)"
checkpoint=".dev/${stream}.cursor"
redis-cli -s "$REDIS_SOCKET" XADD "$stream" 1-0 item first
cabal run reader-example -- "$REDIS_SOCKET" "$stream" "$checkpoint" 1
cabal run worker-example -- "$REDIS_SOCKET" "$stream" thumbnails earliest 1

redis-cli -s "$REDIS_SOCKET" XADD "$stream" 2-0 item second
cabal run reader-example -- "$REDIS_SOCKET" "$stream" "$checkpoint" 1
cabal run worker-example -- "$REDIS_SOCKET" "$stream" thumbnails attach 1

Both examples print entry 1-0 on their first invocation and 2-0 on their second, followed by the stable message ID. Each exits after processing the requested number of entries. The reader replaces its checkpoint file atomically and expects a single owner. The worker generates a new consumer name each time it starts. Use tail to create a missing group at the current end of its stream.

Integrate with an application

Use withRedisRuntime around processor construction, runApp, and the complete shutdown. Each runtime reserves one dedicated read connection alongside an owned or caller-borrowed command pool. Keep the borrowed pool open until finalizers drain.

Readers can start at Earliest, After checkpoint, or Live. A saved checkpoint takes precedence. Store the completed ID and any producer continuity evidence together under the reader's logical name and source identity. When attaching after a snapshot, pass the snapshot cursor and evidence to After, then check the next entry's generation or predecessor with checkContinuity. Use onReaderGap to stop, request a resnapshot, or accept the discontinuity explicitly.

Workers use explicit group creation or attachment and unique per-instance consumer names. Call the optional message lease's leaseExtend before a long-running handler becomes eligible for recovery. A worker can reclaim its own retried entry after the requested delay. A stale finalizer cannot acknowledge or modify a newer attempt. A stale handler may still finish an external effect, so transactionally deduplicate effects that must apply once.

On retry exhaustion, either mode writes a MaxRetriesExceeded record and advances when a dead-letter hash is configured. Without a hash, the processor stops with the reader checkpoint before the entry or the worker entry still pending.

The processor helpers set compatible Shibuya policies. Readers use strict serial processing, and workers use unordered processing up to the configured group capacity. A reader cannot supply a batch that waits for several unfinalized entries. Attach each processor to its own runtime. A second attachment fails with RuntimeAlreadyAttached. Import adapter constructors and configuration from Shibuya.Adapter.Redis. The Internal module exposes implementation helpers without a compatibility guarantee.

For OpenTelemetry correlation, producers can write W3C traceparent and optional tracestate as stream fields. Readers default to LinkOnly, which starts a linked trace for each delivery. Group workers default to ParentAndLink, which joins the producer trace and also links to its span. Set the mode configuration’s telemetry field to override the policy or use its trace-context extractor to read a custom field convention. Rejections from a traced finalizer retain the consumer span’s W3C context.

See compatibility and operations for tested versions, Redis permissions and recovery behavior.