Skip to content

Add PayloadCodec hook for Redis queue payloads (#526) - #622

Open
umitunc wants to merge 1 commit into
laravel:0.xfrom
umitunc:feat/redis-queue-payload-codec
Open

umitunc wants to merge 1 commit into
laravel:0.xfrom
umitunc:feat/redis-queue-payload-codec

Conversation

@umitunc

@umitunc umitunc commented Dec 3, 2026

Copy link
Copy Markdown

Addresses #526

Summary

Adds an opt-in PayloadCodec hook on RedisQueue so applications and packages can store Redis queue payloads in compact or compressed binary formats (such as MessagePack or zstd) without replacing the built-in redis driver or adding new dependencies to the framework.

  • Config (crates/core/src/config/queue.rs):
    • Added the PayloadCodec trait (encode(&self, payload: &str) -> Result<Vec<u8>> and decode(&self, bytes: &[u8]) -> Result<String>) and RedisPayloadCodec wrapper (matching DriverSettings's Arc + ptr_eq equality pattern).
    • Added RedisQueue::codec and codec: Option<RedisPayloadCodec> (defaulting to None, preserving plain UTF-8 JSON storage).
  • Redis Driver (crates/queue/src/queue/redis.rs):
    • Updated PUSH and BULK to encode payloads into Vec<u8> via the configured codec (encoding all bulk payloads before invoking the Lua script).
    • Updated RESERVE (Option<(String, u32, Vec<u8>)>) and SIZES (Option<Vec<u8>>) to read raw bytes from Redis instead of requiring UTF-8 String, then decode through the codec back to JSON for RedisJob::payload and oldest_pending (dispatched_at).
    • Because PayloadCodec::decode receives raw &[u8], an application opting into a binary format can fall back to plain JSON for existing pending/delayed jobs during migration.

Test plan

  • cargo fmt --all -- --check — passed
  • cargo clippy --no-deps -p laravel-rust-core -- -D warnings and cargo clippy --no-deps -p laravel-rust-queue --features redis --lib --tests -- -D warnings — passed
  • cargo test -p laravel-rust-core --lib config::queue — 3 passed
  • cargo test -p laravel-rust-queue --features redis --lib redis::tests — 2 passed (covering default JSON round-trip, invalid UTF-8 rejection, non-UTF-8 binary codec round-trip, dispatched_at extraction, and legacy JSON fallback)

@umitunc

umitunc commented Dec 3, 2026

Copy link
Copy Markdown
Author
redis-payload-codec-16x9.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants