PHPackages                             jamescauwelier/psredis - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. jamescauwelier/psredis

ActiveLibrary[Caching](/categories/caching)

jamescauwelier/psredis
======================

Sentinel client for the popular php redis client

1.1.1(9y ago)77392.9k—0%35[2 issues](https://github.com/jamescauwelier/PSRedis/issues)5MITPHPPHP &gt;=5.4CI failing

Since Jul 13Pushed 5y ago10 watchersCompare

[ Source](https://github.com/jamescauwelier/PSRedis)[ Packagist](https://packagist.org/packages/jamescauwelier/psredis)[ RSS](/packages/jamescauwelier-psredis/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (18)Used By (5)

PSRedis - Sentinel wrapper for PHP redis clients
================================================

[](#psredis---sentinel-wrapper-for-php-redis-clients)

**NOTE: I am no longer actively maintaining this project and I'm looking for another maintainer to take over from me.**

A PHP client for redis sentinel connections as a wrapper on other redis clients. The name stands for *P*HP *S*entinel client for *R*edis. I am sure other would be more creative in coming up with a name.

Installation
------------

[](#installation)

The easiest way to install is by using composer. The package is available on [packagist](https://packagist.org/packages/sparkcentral/predis-sentinel) so installing should be as easy as putting the following in your composer file:

```
"require": {
    "jamescauwelier/psredis": "~1.1"
},

```

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

The most basic example makes use of the Predis adapter by default. This is the least amount of code needed to get going with PSRedis, although we are making plans to make the configuration more concise in the future.

```
// configure where to find the sentinel nodes

$sentinel1 = new Client('192.168.50.40', '26379');
$sentinel2 = new Client('192.168.50.41', '26379');
$sentinel3 = new Client('192.168.50.30', '26379');

// now we can configure the master name and the sentinel nodes

$masterDiscovery = new MasterDiscovery('integrationtests');
$masterDiscovery->addSentinel($sentinel1);
$masterDiscovery->addSentinel($sentinel2);
$masterDiscovery->addSentinel($sentinel3);

// discover where the master is

$master = $masterDiscovery->getMaster();
```

### Auto failover

[](#auto-failover)

You have the option of letting the library handle the failover. That means that in case of connection errors, the library will select the new master or reconnect to the existing ones depending of what the sentinels decide is the proper action. After this reconnection, the command will be re-tried, but only once. No option for backoff exists here.

```
// configuration of $masterDiscovery
$masterDiscovery = ...

// using the $masterDiscovery as a dependency in an Highly Available Client (HAClient)
$HAClient = new HAClient($masterDiscovery);
$HAClient->set('test', 'ok');
$test = $HAClient->get('test');
```

### Customizing the adapter

[](#customizing-the-adapter)

You can choose what kind of client adapter to use or even write your own. If you write your own you need to make sure you implement the **\\PSRedis\\Client\\ClientAdapter** interface.

```
// we need a factory to create the clients
$clientFactory = new PredisClientCreator();

// we need an adapter for each sentinel client too!

$clientAdapter = new PredisClientAdapter($clientFactory, Client::TYPE_SENTINEL);
$sentinel1 = new Client('192.168.50.40', '26379', $clientAdapter);

$clientAdapter = new PredisClientAdapter($clientFactory, Client::TYPE_SENTINEL);
$sentinel2 = new Client('192.168.50.41', '26379', $clientAdapter);

$clientAdapter = new PredisClientAdapter($clientFactory, Client::TYPE_SENTINEL);
$sentinel3 = new Client('192.168.50.30', '26379', $clientAdapter);

// now we can configure the master name and the sentinel nodes

$masterDiscovery = new MasterDiscovery('integrationtests');
$masterDiscovery->addSentinel($sentinel1);
$masterDiscovery->addSentinel($sentinel2);
$masterDiscovery->addSentinel($sentinel3);

// discover where the master is

$master = $masterDiscovery->getMaster();
```

### Configuring backoff

[](#configuring-backoff)

When we fail to discover the location of the master, we need to back off and try again. The back off mechanism is configurable and you can implement your own by implementing the **\\PSRedis\\Client\\BackoffStrategy**

Here is an example using the incremental backoff strategy:

```
$sentinel = new Client('192.168.50.40', '26379');
$masterDiscovery = new MasterDiscovery('integrationtests');
$masterDiscovery->addSentinel($sentinel);

// create a backoff strategy (half a second initially and increment with half of the backoff on each succesive try)
$incrementalBackoff = new Incremental(500, 1.5);
$incrementalBackoff->setMaxAttempts(10);

// configure the master discovery with this backoff strategy
$masterDiscovery->setBackoffStrategy($incrementalBackoff);

// try to discover the master
$master = $masterDiscovery->getMaster();
```

Testing
-------

[](#testing)

*Note:* For testing, we still use PHPUnit 3.7 due to a bug in PhpStorm not allowing us to run unit tests from our IDE. See

### Unit testing

[](#unit-testing)

We use [PHPUnit](https://github.com/sebastianbergmann/phpunit) for unit testing and [Phake](https://github.com/mlively/Phake) for mocking. Both are installed using composer. Running the unit tests can be done using the following command:

```
./vendor/bin/phpunit -c ./phpunit.xml --bootstrap ./tests/bootstrap.php

```

### Integration testing

[](#integration-testing)

#### Prerequisites

[](#prerequisites)

Make sure you have installed these on your machine before running the tests:

- [Vagrant](http://www.vagrantup.com)
- [VirtualBox](https://www.virtualbox.org)
- [Ansible](http://docs.ansible.com/intro_installation.html)

#### Running the tests

[](#running-the-tests)

Before running the tests you need to setup the VM to run the tests on. Use the following command to bring the box up:

```
vagrant up

```

After that, run the integration tests with

```
./vendor/bin/phpunit -c ./phpunit.int.xml --bootstrap ./tests/bootstrap.int.php

```

You will see some warnings that need to be fixed, but the tests themselves should all pass. The warnings are a result of the reset of the environment just before every integration test.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~80 days

Total

13

Last Release

3625d ago

Major Versions

0.2.7-alpha → 1.02015-07-26

0.2.8-alpha → 1.0.12015-08-07

PHP version history (3 changes)0.1-alphaPHP &gt;=5.3.2

0.2.5-alphaPHP ~5.4

0.2.7-alphaPHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/014c8a6931f7dd84e566889de879e8fc176cb57edc8a21da13922afa85271c1e?d=identicon)[jamescauwelier](/maintainers/jamescauwelier)

---

Top Contributors

[![jamescauwelier](https://avatars.githubusercontent.com/u/1190043?v=4)](https://github.com/jamescauwelier "jamescauwelier (97 commits)")[![advisory-board-company](https://avatars.githubusercontent.com/u/8183996?v=4)](https://github.com/advisory-board-company "advisory-board-company (1 commits)")[![geniuslinchao](https://avatars.githubusercontent.com/u/1555953?v=4)](https://github.com/geniuslinchao "geniuslinchao (1 commits)")

---

Tags

redisnosqlpredissentinel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jamescauwelier-psredis/health.svg)

```
[![Health](https://phpackages.com/badges/jamescauwelier-psredis/health.svg)](https://phpackages.com/packages/jamescauwelier-psredis)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[predis/predis-async

Asynchronous version of Predis

366348.4k](/packages/predis-predis-async)[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103830.5k](/packages/monospice-laravel-redis-sentinel-drivers)[predis/service-provider

Predis service provider for the Silex microframework

68546.6k1](/packages/predis-service-provider)[cache/predis-adapter

A PSR-6 cache implementation using Redis (Predis). This implementation supports tags

272.6M13](/packages/cache-predis-adapter)[symfony-bundles/redis-bundle

Symfony Redis Bundle

271.1M5](/packages/symfony-bundles-redis-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
