Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: allow creating PRedis with a client #1389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Iandenh wants to merge 1 commit into php-enqueue:master
base: master
Choose a base branch
Loading
from Iandenh:create-predis-with-client

Conversation

@Iandenh
Copy link

@Iandenh Iandenh commented May 19, 2025

This pull request introduces the ability to create a PRedis instance using an already initialized Predis\Client. A new static method createWithClient has been added to facilitate this functionality.

Use Case
If a user already has a configured Predis\Client instance, they can now pass it directly to the PRedis class. This avoids the need to reconfigure the client or duplicate configuration logic. For example, I want to pass through enqueue because I have a predis client configured with Sentinel.

Changes

  1. Added a check in the constructor to accept a client key in the configuration array. If provided, it validates that the value is an instance of Predis\Client and uses it directly.
  2. Added a static method createWithClient(Client $client): self to simplify the creation of a PRedis instance with an existing Predis\Client.

Example Usage

use Predis\Client;
use Enqueue\Redis\PRedis;
$predisClient = new Client(['host' => '127.0.0.1', 'port' => 6379]);
$predis = PRedis::createWithClient($predisClient);
// Pass the PRedis instance to the RedisConnectionFactory
$connectionFactory = new RedisConnectionFactory($predis);
// Get the RedisContext
$redisContext = $connectionFactory->createContext();

@Iandenh Iandenh force-pushed the create-predis-with-client branch from 0335653 to 9f502fc Compare May 20, 2025 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /