Sunbeam Studios

Our open-source projects, here for you!

wfe-valkey (1.4.0)

Published 2026-03-27 00:32:28 +00:00 by siennathesane

Installation

[registry]
default = "gitea"

[registries.gitea]
index = "sparse+" # Sparse index
# index = "" # Git

[net]
git-fetch-with-cli = true
cargo add wfe-valkey@1.4.0

About this package

Valkey/Redis provider for distributed locking, queues, and lifecycle events in WFE

wfe-valkey

Valkey (Redis-compatible) provider for distributed locking, queues, and lifecycle events in WFE.

What it does

Provides three provider implementations backed by Valkey (or any Redis-compatible server) using the redis crate with multiplexed async connections. Handles distributed lock coordination across multiple WFE host instances, work queue distribution for workflows/events/indexing, and pub/sub lifecycle event broadcasting.

Quick start

use wfe_valkey::{ValkeyLockProvider, ValkeyQueueProvider, ValkeyLifecyclePublisher};

let redis_url = "redis://127.0.0.1:6379";
let prefix = "wfe"; // key prefix for namespacing

let locks = ValkeyLockProvider::new(redis_url, prefix).await?;
let queues = ValkeyQueueProvider::new(redis_url, prefix).await?;
let lifecycle = ValkeyLifecyclePublisher::new(redis_url, prefix).await?;

Custom lock duration (default is 30 seconds):

use std::time::Duration;

let locks = ValkeyLockProvider::new(redis_url, prefix).await?
    .with_lock_duration(Duration::from_secs(10));

API

Type Trait Purpose
ValkeyLockProvider DistributedLockProvider Distributed mutex via SET NX EX. Release uses a Lua script to ensure only the holder can unlock.
ValkeyQueueProvider QueueProvider FIFO work queues via LPUSH/RPOP. Separate queues for Workflow, Event, and Index work types.
ValkeyLifecyclePublisher LifecyclePublisher Pub/sub lifecycle events. Publishes to both an instance-specific channel and a global all channel.

Key layout

All keys are prefixed with the configured prefix (e.g., wfe):

Pattern Usage
{prefix}:lock:{resource} Distributed lock for a resource
{prefix}:queue:workflow Workflow processing queue
{prefix}:queue:event Event processing queue
{prefix}:queue:index Index update queue
{prefix}:lifecycle:{workflow_id} Lifecycle events for a specific workflow
{prefix}:lifecycle:all All lifecycle events

Configuration

Connection string is a standard Redis URI:

redis://127.0.0.1:6379
redis://:password@host:6379/0

Each provider creates its own multiplexed connection. The prefix parameter namespaces all keys, so multiple WFE deployments can share a single Valkey instance.

Testing

Requires a running Valkey instance. Use the project docker-compose:

docker compose up -d valkey
cargo test -p wfe-valkey

Default test connection: redis://127.0.0.1:6379

License

MIT

Dependencies

ID Version
async-trait ^0.1
redis ^0.27
serde ^1
serde_json ^1
thiserror ^2
tokio ^1
tracing ^0.1
uuid ^1
wfe-core ^1.4.0
pretty_assertions ^1
rstest ^0.23
tokio ^1
tokio-stream ^0.1
uuid ^1
wfe-core ^1.4.0
Details
Cargo
2026-03-27 00:32:28 +00:00
0
MIT
15 KiB
Assets (1)
Versions (2) View all
1.4.0 2026-03-27
1.0.0 2026-03-26