PHPackages                             davemodis/redis\_shards - 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. davemodis/redis\_shards

ActiveLibrary[Caching](/categories/caching)

davemodis/redis\_shards
=======================

Redis Client with sharding and support MGET, MSET, KEYS and Pipeline

095

Since Feb 22Compare

[ Source](https://github.com/davemodis/redis_shards)[ Packagist](https://packagist.org/packages/davemodis/redis_shards)[ RSS](/packages/davemodis-redis-shards/feed)WikiDiscussions Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Redis Shards Client
===================

[](#redis-shards-client)

Redis client based on Yii2 Redis Connector. Extends functional to use few redis servers as one (sharding) and support MGET, MSET, KEYS, Pipeline. From original Yii class removed events.

### How sharding works

[](#how-sharding-works)

The server (shard) is selected depending on the key. If the key contains digits at the end, they are used to select the shard, otherwise the key is converted into a number with the hash function CRC32. Then we take the remainder of dividing this number on the count of servers and get the shard index. It can be useful if you use keys like `user:[id]`. For example, if you have 3 shards and you need to know on which of them stores user 123 you can find it with `123 % 3 = 0`. 0 is index of shard.

### Features

[](#features)

**MGET, MSET, KEYS and Pipeline** works transporently: each shard will get only its keys. MGET, MSET, KEYS separates all keys on packs for their shards, and then send requests. One shard - one request.

You can delay reading response from Redis. [Learn more about Pipeline on Redis.io](https://redis.io/topics/pipelining). In sharding mode pipeline works the same as usual. When you start Pipeline mode `$redis->pipelineStart();`, client doesn't read response from Redis. When you end Pipeline mode `$redis->pipelineEnd();` client read all responses of each requests made in Pipeline mode. If you don't need to read responses (for economy reason) you can close sockets with `$redis->close();`

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

[](#installation)

### Composer installation

[](#composer-installation)

`composer require davemodis/redis_shards`

### Manually installation

[](#manually-installation)

1. Clone this repo;
2. Include code in your project.

```
include 'RedisShardsClient.php';
include 'RedisShardsException.php';

```

Configuration
-------------

[](#configuration)

### Simple configuration

[](#simple-configuration)

Create object and configure it.

```
$redis = new \davemodis\redis_shards\RedisShardsClient();
$redis->hostname = '127.0.0.1';

```

### Sharding configuration

[](#sharding-configuration)

To use sharding feature specify more than one Redis server. In this case you must specify ports, passwords and databases for each host. You will get error if miss one of them.

```
$redis->hostname = ['127.0.0.1','127.0.0.2'];
$redis->port = [6379,6379];
$redis->password = [null,'StrOngPassw0rd!!1'];
$redis->database = [0,0];

```

### Yii2 configuration

[](#yii2-configuration)

```
'components' => [
    'redis' => [
        'class'         => 'davemodis\redis_shards\RedisShardsClient',
        'hostname'      => ['127.0.0.1','127.0.0.2'],
        'port'          => [6379,6379],
        'password'      => [null,'StrOngPassw0rd!!1'],
        'database'      => [0,0],
    ],
]

```

> NOTICE: You can't use this class in Yii2 to Cache or Session. Add one more redis component in Yii2 config with yii\\redis\\Connection class to use in Cache and Session.

```
'components' => [
    'redis' => [
        'class'         => 'davemodis\redis_shards\RedisShardsClient',
        'hostname'      => ['127.0.0.1','127.0.0.2'],
        'port'          => [6379,6379],
        'password'      => [null,'StrOngPassw0rd!!1'],
        'database'      => [0,0],
    ],
    'redis_yiicache' => [
        'class'         => 'yii\redis\Connection',
        'hostname'      => '127.0.0.2',
        'port'          => 6379,
        'password'      => 'StrOngPassw0rd!!1',
        'database'      => 1,
    ],
    'cache' => [
        'class' => 'yii\redis\Cache',
        'redis' => 'redis_yiicache',
    ],
    'session' => [
        'class' => 'yii\redis\Session',
        'redis' => 'redis_yiicache',
        'timeout' => 86400*30,
    ],
]

```

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5584418?v=4)[Albert Safiiulin](/maintainers/davemodis)[@davemodis](https://github.com/davemodis)

### Embed Badge

![Health badge](/badges/davemodis-redis-shards/health.svg)

```
[![Health](https://phpackages.com/badges/davemodis-redis-shards/health.svg)](https://phpackages.com/packages/davemodis-redis-shards)
```

###  Alternatives

[beryllium/cachebundle

Provides an interface to Memcache for Symfony2 applications

32136.0k](/packages/beryllium-cachebundle)

PHPackages © 2026

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