@@ -79,8 +79,63 @@ To work with values in a more efficient manner, batch operations should be used:
7979
8080This package can be used as a cache handler for the [ Yii Caching Library] ( https://github.com/yiisoft/cache ) .
8181
82+ ## Redis cluster supported
83+
84+ The package implements [ Redis cluster] ( https://redis.io/docs/management/scaling/ ) support via ` Predis ` package.
85+
86+ For example, if your cluster configuration has three master nodes and three slave nodes, your client configuration might look like this:
87+
88+ ``` php
89+ $client = new \Predis\Client([
90+ ['host' => 'redis-node-1', 'port' => 'redis-node-port-1',],
91+ ['host' => 'redis-node-2', 'port' => 'redis-node-port-2',],
92+ ['host' => 'redis-node-3', 'port' => 'redis-node-port-3',],
93+ ['host' => 'redis-node-4', 'port' => 'redis-node-port-4',],
94+ ['host' => 'redis-node-5', 'port' => 'redis-node-port-5',],
95+ ['host' => 'redis-node-6', 'port' => 'redis-node-port-6',],
96+ ],
97+ [
98+ 'cluster' => 'redis',
99+ 'parameters' => [
100+ 'password' => 'Password',
101+ ],
102+ ]
103+ );
104+ $cache = new \Yiisoft\Cache\Redis\RedisCache($client);
105+ ```
106+ Predis will route commands on its own when specifying Redis nodes in the cluster to the appropriate nodes depending on the keys that are specified in the commands.
107+
108+ You can implement ` \Predis\Distribution\DistributorInterface ` to create their own distributors used by the client to distribute keys among a cluster of servers.
109+
110+ Then your config might look like this:
111+
112+ ``` php
113+ $client = new \Predis\Client([
114+ ['host' => 'redis-node-1', 'port' => 'redis-node-port-1',],
115+ ['host' => 'redis-node-2', 'port' => 'redis-node-port-2',],
116+ ['host' => 'redis-node-3', 'port' => 'redis-node-port-3',],
117+ ['host' => 'redis-node-4', 'port' => 'redis-node-port-4',],
118+ ['host' => 'redis-node-5', 'port' => 'redis-node-port-5',],
119+ ['host' => 'redis-node-6', 'port' => 'redis-node-port-6',],
120+ ],
121+ [
122+ 'cluster' => static function () {
123+ $distributor = new \CustomDistributor(); // Your custom distributor
124+ $strategy = new \Predis\Cluster\PredisStrategy($distributor);
125+
126+ return new \Predis\Connection\Cluster\PredisCluster($strategy);
127+ },
128+ 'parameters' => [
129+ 'password' => 'Password',
130+ ],
131+ ]
132+ );
133+ ```
134+
82135## Testing
83136
137+ > The tests use a connection to a running Redis cluster. If you are not using Docker, you must start the cluster yourself before running the tests.
138+
84139### Unit testing
85140
86141The package is tested with [ PHPUnit] ( https://phpunit.de/ ) . To run tests:
@@ -106,6 +161,29 @@ The code is statically analyzed with [Psalm](https://psalm.dev/). To run static
106161./vendor/bin/psalm
107162```
108163
164+ ## Testing in Docker
165+
166+ ### Prepare
167+
168+ ``` bash
169+ # {{ v }} = 8.0, 8.1, 8.2. Default PHP 8.1
170+ make build v=8.1
171+ ```
172+
173+ ### Unit testing
174+
175+ ``` bash
176+ # {{ v }} = 8.0, 8.1, 8.2. Default PHP 8.1
177+ make test v=8.1
178+ ```
179+
180+ ### Mutation testing
181+
182+ ``` bash
183+ # {{ v }} = 8.0, 8.1, 8.2. Default PHP 8.1
184+ make mutation-test v=8.0
185+ ```
186+
109187## License
110188
111189The Yii Caching Library - Redis Handler is free software. It is released under the terms of the BSD License.
0 commit comments