PHP code example of lamoda / redis-sentinel
1. Go to this page and download the library: Download lamoda/redis-sentinel library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lamoda / redis-sentinel example snippets
use Lamoda\RedisSentinel\RedisLocator;
$redisLocator = new RedisLocator(
// plain redis:
[
'protocol' => 'tcp',
'host' => 'redis-host',
'port' => 6379,
'dbindex' => 0,
'connectionName' => uniqid('client-app', true),
],
// redis sentinel:
[
'url' => 'redis-sentinel1:26379; redis-sentinel2:26379',
'redisName' => 'mastername',
]
);
// Discover current sentinel master:
$redisConfig = $redisLocator->getRedisConfig();
$redis = new \Redis();
$redis->connect($redisConfig->getHost(), $redisConfig->getPort());
$redis->client('setname', $redisConfig->getConnectionName());
$redis->select($redisConfig->getDbIndex());
$redisLocator = new RedisLocator(
// plain redis:
[
'protocol' => 'tcp',
'host' => 'redis-host',
'port' => 6379,
'dbindex' => 0,
'connectionName' => uniqid('client-app', true),
],
// redis sentinel:
[
'url' => '',
'redisName' => 'mastername',
]
);
// Return plain redis config:
$redisConfig = $redisLocator->getRedisConfig();