2017 © Pedro Peláez
 

library 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 4.0

image

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 4.0

  • Tuesday, July 3, 2018
  • by cheprasov
  • Repository
  • 8 Watchers
  • 52 Stars
  • 59,173 Installations
  • PHP
  • 14 Dependents
  • 0 Suggesters
  • 19 Forks
  • 1 Open issues
  • 18 Versions
  • 25 % Grown

The README.md

MIT license Latest Stable Version Total Downloads, (*1)

RedisClient v1.10.0 for PHP >= 5.5

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, (*2)

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

Please see list of commands here ./COMMANDS.md, (*3)

Usage

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

<?php
namespace Examples;

require (dirname(__DIR__).'/vendor/autoload.php');
// or require (dirname(__DIR__).'/src/autoloader.php');

use RedisClient\RedisClient;
use RedisClient\Client\Version\RedisClient2x6;
use RedisClient\ClientFactory;

// Example 1. Create new Instance for Redis version 6.0.x with config via factory
$Redis = ClientFactory::create([
    'server' => '127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
    'timeout' => 2,
    'version' => '6.0'
]);

echo 'RedisClient: '. $Redis->getSupportedVersion() . PHP_EOL; // RedisClient: 2.8


// Example 2. Create new Instance without config. Client will use default config.
$Redis = new RedisClient();
// By default, the client works with the latest stable version of Redis.
echo 'RedisClient: '. $Redis->getSupportedVersion() . PHP_EOL; // RedisClient: 3.2
echo 'Redis: '. $Redis->info('Server')['redis_version'] . PHP_EOL; // Redis: 3.0.3


// Example 3. Create new Instance with config
// By default, the client works with the latest stable version of Redis.
$Redis = new RedisClient([
    'server' => '127.0.0.1:6387', // or 'unix:///tmp/redis.sock'
    'timeout' => 2
]);

echo 'RedisClient: '. $Redis->getSupportedVersion() . PHP_EOL; // RedisClient: 3.2
echo 'Redis: '. $Redis->info('Server')['redis_version'] . PHP_EOL; // Redis: 3.2.0


// Example 4. Create new Instance for Redis version 2.6.x with config
$Redis = new RedisClient2x6([
    'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
    'timeout' => 2
]);

echo 'RedisClient: '. $Redis->getSupportedVersion() . PHP_EOL; // RedisClient: 2.6

Example

Please, see examples here: https://github.com/cheprasov/php-redis-client/tree/master/examples, (*4)

Installation

Composer

Download composer:, (*5)

wget -nc http://getcomposer.org/composer.phar

and add dependency to your project:, (*6)

php composer.phar require cheprasov/php-redis-client

Running tests

  1. Run Docker container with Redis for tests https://hub.docker.com/r/cheprasov/redis-for-tests/
  2. Run Docker container with Redis Cluster for tests https://hub.docker.com/r/cheprasov/redis-cluster-for-tests/
  3. To run tests type in console:, (*7)

    ./vendor/bin/phpunit, (*8)

Something doesn't work

Feel free to fork project, fix bugs and finally request for pull, (*9)

The Versions

03/07 2018

dev-master

9999999-dev http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

08/03 2018

1.8.0

1.8.0.0 http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

19/08 2017

1.7.2

1.7.2.0 http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

19/08 2017

1.7.1

1.7.1.0 http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

22/07 2017

1.7.0

1.7.0.0 http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

04/02 2017

1.6.1

1.6.1.0 http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

07/01 2017

1.6.0

1.6.0.0 http://github.com/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 4.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

17/08 2016

1.5.1

1.5.1.0 http://github.com/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 3.2

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

15/08 2016

1.5.0

1.5.0.0 http://github.com/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 3.2

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

18/07 2016

1.4.0

1.4.0.0 http://github.com/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 3.2.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

18/05 2016

1.3.1

1.3.1.0 http://github.com/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 3.2.0

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

07/05 2016

1.3.0

1.3.0.0 http://github.com/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 3.2.0-RC3

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

02/05 2016

1.2.3

1.2.3.0 http://github.com/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 3.2.0-RC3

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

30/03 2016

1.2.2

1.2.2.0 http://github.com/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 3.2.0-RC3

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

04/03 2016

1.2.1

1.2.1.0 http://github.com/cheprasov/php-redis-client

Php client for Redis

  Sources   Download

proprietary

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

30/01 2016

1.2.0

1.2.0.0 http://github.com/cheprasov/php-redis-client

Php client for Redis

  Sources   Download

proprietary

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

25/01 2016

1.1.0

1.1.0.0 http://github.com/cheprasov/php-redis-client

Php client for Redis

  Sources   Download

proprietary

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov

24/01 2016

1.0.0

1.0.0.0 http://github.com/cheprasov/php-redis-client

Php client for Redis

  Sources   Download

proprietary

The Requires

  • php >=5.5

 

The Development Requires

by Alexander Cheprasov