https://github.com/lulco/redis-proxy
Library for creating redis instance depends on application / server possibilities
https://github.com/lulco/redis-proxy
predis proxy redis
Last synced: about 1 year ago
JSON representation
Library for creating redis instance depends on application / server possibilities
- Host: GitHub
- URL: https://github.com/lulco/redis-proxy
- Owner: lulco
- License: mit
- Created: 2016-04-22T14:13:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2025-03-08T12:20:38.000Z (over 1 year ago)
- Last Synced: 2025-03-08T13:18:09.189Z (over 1 year ago)
- Topics: predis, proxy, redis
- Language: PHP
- Size: 88.9 KB
- Stars: 2
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Redis proxy
Library for creating redis instance depends on application / server possibilities
[](https://travis-ci.org/lulco/redis-proxy)
[](https://scrutinizer-ci.com/g/lulco/redis-proxy/?branch=master)
[](https://scrutinizer-ci.com/g/lulco/redis-proxy/?branch=master)
[](https://insight.sensiolabs.com/projects/614109c1-261a-432a-9a32-50d7138b00c4)
[](https://packagist.org/packages/lulco/redis-proxy)
[](https://packagist.org/packages/lulco/redis-proxy)
[](https://travis-ci.org/lulco/redis-proxy)
## Installation
### Composer
The fastest way to install Redis proxy is to add it to your project using Composer (http://getcomposer.org/).
1. Install Composer:
```
curl -sS https://getcomposer.org/installer | php
```
1. Require Redis proxy as a dependency using Composer:
```
php composer.phar require lulco/redis-proxy
```
1. Install Redis proxy:
```
php composer.phar update
```
## Usage
### Single redis node
```php
$redis = new \RedisProxy\RedisProxy($host, $port);
// Call redis methods
$redis->select($database);
$redis->hset($key, $field, $value);
$redis->hlen($key);
$redis->hget($key, $field);
$redis->hgetall($key);
...
```
### Sentinel
```php
$sentinels = [
['host' => '172.19.0.5', 'port' => 26379],
['host' => '172.19.0.6', 'port' => 26379],
['host' => '172.19.0.7', 'port' => 26379],
];
$clusterId = 'mymaster';
$redis = new \RedisProxy\RedisProxy();
$redis->setSentinelConnectionPool($sentinels, $clusterId, $database);
// Call redis methods
$redis->hset($key, $field, $value);
$redis->hlen($key);
$redis->hget($key, $field);
$redis->hgetall($key);
```
### Multi read connection
Read from multiple redis nodes
Write to one master redis node
```php
$master = ['host' => '172.19.0.5', 'port' => 26379];
$slaves = [
['host' => '172.19.0.5', 'port' => 26379],
['host' => '172.19.0.6', 'port' => 26379],
['host' => '172.19.0.7', 'port' => 26379],
];
$clusterId = 'mymaster';
$redis = new \RedisProxy\RedisProxy();
$redis->setMultiConnectionPool($master, $slaves);
```
### Multi write connection
Write to multiple master redis nodes
Optionally read from multiple redis nodes
```php
$masters = [
['host' => '172.19.0.5', 'port' => 26379],
['host' => '172.19.0.6', 'port' => 26379],
['host' => '172.19.0.7', 'port' => 26379],
];
$slaves = [
['host' => '172.19.0.5', 'port' => 26379],
['host' => '172.19.0.6', 'port' => 26379],
['host' => '172.19.0.7', 'port' => 26379],
];
$clusterId = 'mymaster';
$redis = new \RedisProxy\RedisProxy();
$redis->setMultiWriteConnectionPool($masters, $slaves);
```