PHP code example of easyswoole / redis-pool

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

    

easyswoole / redis-pool example snippets


//redis连接池注册(config默认为127.0.0.1,端口6379)
\EasySwoole\RedisPool\RedisPool::getInstance()->register(new \EasySwoole\Redis\Config\RedisConfig(),'redis');

//redis集群连接池注册
\EasySwoole\RedisPool\RedisPool::getInstance()->register(new \EasySwoole\Redis\Config\RedisClusterConfig([
        ['172.16.253.156', 9001],
        ['172.16.253.156', 9002],
        ['172.16.253.156', 9003],
        ['172.16.253.156', 9004],
    ]
),'redisCluster');


    $config = new Config(
        [
            'host'=>"",
            'port'=>"6300",
            'auth'=>"",
            "db"=>0
        ]
    );

    RedisPool::getInstance()->register($config);

    $client = RedisPool::defer();
    $ret = $client->get("a");
    var_dump($ret);
    $client->set("a",time());
    $ret = $client->get("a");
    var_dump($ret);
    
    RedisPool::invoke(function (Redis $redis){
        var_dump($redis->get("a"));
    });