Redis Connection Pool

Notice: ext-swoole is supported until v4.7.1, use ext-openswoole >= v4.7.1. Latest version: pecl install openswoole-4.10.0

This is a Redis implementaion of ConnectionPool.

Connection pool is used to reduce the TCP reconnect overhead, can be used to increase the application performance.

You can use the build-in RedisPool to manage a pool of connection to database servers or remote services.


  • Swoole\Database\RedisPool->__construct
  • Swoole\Database\RedisPool->make
  • Swoole\Database\RedisPool->fill
  • Swoole\Database\RedisPool->get
  • Swoole\Database\RedisPool->put
  • Swoole\Database\RedisPool->close

    Redis Connection Pool Config

  • Swoole\Database\RedisConfig


    use Swoole\Database\RedisConfig;
    use Swoole\Database\RedisPool;
    use Swoole\Runtime;
    const N = 10;
    Co\run(function () {
        $pool = new RedisPool((new RedisConfig)
        for ($n = N; $n--;) {
            go(function () use ($pool) {
                $redis = $pool->get();
                $result = $redis->set('foo', 'bar');
                if (!$result) {
                    throw new RuntimeException('Set failed');
                $result = $redis->get('foo');
                if ($result !== 'bar') {
                    throw new RuntimeException('Get failed');