PHP code example of dwaysinc / redis-cluster

1. Go to this page and download the library: Download dwaysinc/redis-cluster 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/ */

    

dwaysinc / redis-cluster example snippets




use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Amp\Redis\Config;
use Amp\Redis\Redis;
use Amp\Redis\RemoteExecutor;
use Monolog\Logger;
use function Amp\ByteStream\getStdout;

Amp\Loop::run(static function () {
    $handler = new StreamHandler(getStdout());
    $handler->setFormatter(new ConsoleFormatter);

    $logger = new Logger('example');
    $logger->pushHandler($handler);

    $redisCluster = new DwaysInc\RedisCluster\RedisCluster(...[
        new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-0:6379?password=bitnami',))),
        new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-1:6379?password=bitnami',))),
        new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-2:6379?password=bitnami',))),
        new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-3:6379?password=bitnami',))),
        new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-4:6379?password=bitnami',))),
        new Redis(new RemoteExecutor(Config::fromUri('tcp://redis-node-5:6379?password=bitnami',))),
    ]);

    $redisCluster->setLogger($logger);

    $key = 12345678;

    yield $redisCluster->set($key, 12);

    $value = yield $redisCluster->get($key); // (int) 12

    $logger->info(sprintf('Got value by key %s - %s', $key, $value));
});