Skip to content

feat(redis-cluster): implemented single-slot pipeline support and tests#2798

Open
ebubekiryigit wants to merge 1 commit intophpredis:developfrom
ebubekiryigit:feature/redis-cluster-pipeline-support
Open

feat(redis-cluster): implemented single-slot pipeline support and tests#2798
ebubekiryigit wants to merge 1 commit intophpredis:developfrom
ebubekiryigit:feature/redis-cluster-pipeline-support

Conversation

@ebubekiryigit
Copy link
Copy Markdown

@ebubekiryigit ebubekiryigit commented Jan 21, 2026

Summary

Add RedisCluster pipeline support restricted to a single hash slot (hash tags respected).
Enforce slot consistency at queue time; cross-slot pipelines throw RedisClusterException.
Handle pipeline exec/cleanup safely and keep MULTI behavior unchanged.
Update stubs/arginfo and cluster documentation.
Add extensive RedisCluster tests covering pipeline, multi, atomic modes, cross-slot errors, invalid operations, and recovery.

Motivation

Currently RedisCluster rejects PIPELINING entirely. Other clients (e.g. redis-py) allow pipelining for same-slot keys. This change brings PhpRedis to parity while preserving Redis Cluster safety guarantees.

Behavior

  • Pipelines are allowed if all keys resolve to the same hash slot.
  • Cross-slot pipelines throw RedisClusterException.
  • Multi-key commands validate slot consistency.
  • Existing MULTI behavior remains unchanged.

Testing

Ran tests in a container:

cd /path/to/phpredis

docker run --rm -it \
  --platform=linux/amd64 \
  -v "$PWD:/usr/src/phpredis" \
  -w /usr/src/phpredis \
  php:8.5.2-cli-trixie \
  bash

Note:

  • If you plan to build inside this container, install optional PHP extensions (igbinary, msgpack, etc.), preferably via pecl.

  • If you plan to start the test cluster inside the same container, make sure to install redis-server as well.

# 1. Build extension
cd /usr/src/phpredis
phpize && ./configure && make -j"$(nproc)" && make test && make install

# 2. Start cluster
cd tests
./make-cluster.sh -y start

# 3. Run pipeline tests
php TestRedis.php --class RedisCluster --test
# expected output: All tests passed. \o/

# 4. Stop cluster when done
./make-cluster.sh stop

Performance (local cluster)

Measured testClusterPipelineTiming before and after:

Before Pipeline Support

  • RedisCluster::multi() warned that PIPELINING was not supported
  • MGET Time: 0.000579667 seconds
  • Pipeline GET Time: 0.026290541 seconds

After Pipeline Support

  • MGET Time: 0.000635542 seconds
  • Pipeline GET Time: 0.000456541 seconds

Pipeline performance is now in line with expectations and significantly faster.

Implement RedisCluster pipeline mode with slot enforcement and queue buffering,
add pipeline exec handling, and reset logic for errors/discard. Update stubs,
arginfo, and cluster docs. Expand RedisCluster tests to cover pipeline/multi
edge cases, cross-slot errors, mode transitions, and invalid operations.
@ebubekiryigit
Copy link
Copy Markdown
Author

This change also addresses the long-standing discussion in: #1910

@michael-grunder
Copy link
Copy Markdown
Member

Hi thanks for the PR.

I'm not opposed to adding the feature by any means. I'll play around with it locally this week.

@ebubekiryigit
Copy link
Copy Markdown
Author

Hey @michael-grunder,

Thanks for the review! Let me know if there’s anything I should clarify or adjust.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants