PHPackages                             cheprasov/php-redis-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. cheprasov/php-redis-client

ActiveLibrary[Caching](/categories/caching)

cheprasov/php-redis-client
==========================

Php client for Redis. It is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from 2.6 to 6.0

1.10.0(5y ago)1281.2M—5.4%41[2 PRs](https://github.com/cheprasov/php-redis-client/pulls)19MITPHPPHP &gt;=5.5CI failing

Since Jan 24Pushed 3y ago16 watchersCompare

[ Source](https://github.com/cheprasov/php-redis-client)[ Packagist](https://packagist.org/packages/cheprasov/php-redis-client)[ Docs](http://github.com/cheprasov/php-redis-client)[ RSS](/packages/cheprasov-php-redis-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (21)Used By (19)

[![MIT license](https://camo.githubusercontent.com/4661abfe916186acde514558e7f040833cb63ba7098401a51ce339cbb2b4cf9e/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](http://opensource.org/licenses/MIT)[![Latest Stable Version](https://camo.githubusercontent.com/835f5b2cdd1d4ed2864f1bf522604fc61328821f154abc137613d74fdc67792c/68747470733a2f2f706f7365722e707567782e6f72672f636865707261736f762f7068702d72656469732d636c69656e742f762f737461626c65)](https://packagist.org/packages/cheprasov/php-redis-client)[![Total Downloads](https://camo.githubusercontent.com/601b214927cfe5b132576270f59217e7a5c058ad2049920dc741e0c5e08f34a5/68747470733a2f2f706f7365722e707567782e6f72672f636865707261736f762f7068702d72656469732d636c69656e742f646f776e6c6f616473)](https://packagist.org/packages/cheprasov/php-redis-client)

RedisClient v1.10.0 for PHP &gt;= 5.5
=====================================

[](#redisclient-v1100-for-php--55)

About
-----

[](#about)

RedisClient is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports the latest versions of Redis starting from **2.6** to **6.0**

Main features
-------------

[](#main-features)

- Support Redis versions from **2.6.x** to **6.0.x**.
- Support **TCP/IP** and **UNIX** sockets.
- Support **PubSub** and **Monitor** functionallity.
- Support **Pipeline** and **Transactions**.
- Support **Redis Cluster**.
- Support **RAW** commands as arrays `['SET', 'foo', 'bar']`.
- Connections to Redis are established lazily by the client upon the first command.
- Easy to use with IDE, client has PHPDocs for all supported versions.
- By default, the client works with the latest stable version of Redis (6.0).
- The client was tested on the next latest versions of Redis: `6.0.5`, `5.0.5`, `4.0.14`, `3.2.8`, `3.0.7`, `2.8.24`, `2.6.17`.
- Also, the client was tested on PHP `7.4`, `7.3`, `7.2`, `7.1`, `7.0`, `5.6`, `5.5`, `HHVM`.

Redis Commands
--------------

[](#redis-commands)

Please see list of commands here [./COMMANDS.md](https://github.com/cheprasov/php-redis-client/tree/master/COMMANDS.md)

Usage
-----

[](#usage)

### Config

[](#config)

```
$config = [
    // Optional. Default = '127.0.0.1:6379'. You can use 'unix:///tmp/redis.sock'
    'server' => '127.0.0.1:6379',

    // Optional. Default = 1
    // The timeout for reading/writing data over the socket
    'timeout' => 2,

    // Optional. Default = null
    // See more here: http://php.net/manual/en/function.stream-socket-client.php
    'connection' => [
        // Optional. Default = ini_get("default_socket_timeout")
        // The timeout only applies while making connecting the socket
        'timeout' => 2,

        // Optional. Default = STREAM_CLIENT_CONNECT
        // Bitmask field which may be set to any combination of connection flags.
        // Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default),
        // STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT.
        'flags' => STREAM_CLIENT_CONNECT
    ],

    // Optional. Specify version to avoid some unexpected errors.
    'version' => '4.0.10',

    // Optional. Use it only if Redis server requires password (AUTH)
    'password' => 'some-password',

    // Optional. Use it, if you want to select not default db (db != 0) on connect
    'database' => 1,

    // Optional. Array with configs for RedisCluster support
    'cluster' => [
        'enabled' => false,

        // Optional. Default = []. Map of cluster slots and servers
        // array(max_slot => server [, ...])
        // Examples for Cluster with 3 Nodes:
        'clusters' => [
            5460  => '127.0.0.1:7001', // slots from 0 to 5460
            10922 => '127.0.0.1:7002', // slots from 5461 to 10922
            16383 => '127.0.0.1:7003', // slots from 10923 to 16383
        ],

        // Optional. Default = false.
        // Use the param to update cluster slot map below on init RedisClient.
        // RedisClient will execute command CLUSTER SLOTS to get map.
        'init_on_start' => false,

        // Optional. Default = false.
        // If Redis returns error -MOVED then RedisClient will execute
        // command CLUSTER SLOTS to update cluster slot map
        'init_on_error_moved' => true,

        // Optional. Defatult = 0.05 sec. It is timeout before next attempt on TRYAGAIN error.
        'timeout_on_error_tryagain' => 0.25, // sec
    ]
];
```

### Create a new instance of RedisClient

[](#create-a-new-instance-of-redisclient)

```
