PHP code example of comoyi / redis

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

    

comoyi / redis example snippets




use Comoyi\Redis\RedisClient;

$config = [
    'type' => 'direct', // direct: 直连, sentinel: 由sentinel决定host与port
    'password' => 'redispassword', // redis auth 密码
    'master_name' => 'mymaster', // master name
    'direct' => [
        'masters' => [
            [
                'host' => '127.0.0.1',
                'port' => '6379',
            ],
        ],
        'slaves' => [
            [
                'host' => '127.0.0.1',
                'port' => '6381',
            ],
            [
                'host' => '127.0.0.1',
                'port' => '6382',
            ],
        ],
    ],
    'sentinel' => [
        'sentinels' => [
            [
                'host' => '127.0.0.1',
                'port' => '5000',
            ],
            [
                'host' => '127.0.0.1',
                'port' => '5001',
            ],
        ],
    ],
];

$redis = new RedisClient($config);
$key = 'just-for-test';
$redis->set($key, 'test data');
$data = $redis->get($key);
var_dump($data);