Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
# php-redis-client
Project in development
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)

Docker with Redis for tests
https://hub.docker.com/r/cheprasov/redis-for-tests/
# RedisClient v1.0.0 for PHP >= 5.5

## About
RedisClient is a fast, fully-functional and user-friendly client for Redis, optimized for performance. RedisClient supports latests versions of Redis starting from 2.6

## Main features
- Support Redis versions from __2.6__ to __3.2-RC1__.
- Support TCP/IP and UNIX sockets.
- Support __PubSub__ and __monitor__ functionallity.
- Support __pipeline__.
- 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.

## Usage

### Create a new instance of RedisClient
```php
<?php
require (dirname(__DIR__).'/src/autoloader.php');
// or require ('vendor/autoload.php');

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

$Redis = new RedisClient([
'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
'timeout' => 2
]);

echo 'RedisClient: '. $Redis->getVersion() . PHP_EOL;
echo 'Redis: '. $Redis->info('Server')['redis_version'] . PHP_EOL;

// RedisClient: 3.0
// Redis: 3.0.3
```
### Example
Please, see examples here: https://github.com/cheprasov/php-redis-client/tree/master/examples


## Installation

### Composer

Download composer:

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

and add dependency to your project:

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

## Running tests

1. Use Docker container with Redis for tests https://hub.docker.com/r/cheprasov/redis-for-tests/
2. To run tests type in console (do not forget run Docker):


./vendor/bin/phpunit


## Something doesn't work

Feel free to fork project, fix bugs and finally request for pull
5 changes: 3 additions & 2 deletions examples/create_new_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Examples;

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

use RedisClient\RedisClient;
use RedisClient\Client\Version\RedisClient2x6;
Expand All @@ -35,7 +36,7 @@
// Example 2. Create new Instance with config

$Redis = new RedisClient([
'server' => 'tcp://127.0.0.1:6379',
'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
'timeout' => 2
]);

Expand All @@ -50,7 +51,7 @@
// Example 3. Create new Instance for Redis version 2.6.x with config

$Redis = new RedisClient2x6([
'server' => 'tcp://127.0.0.1:6379',
'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
'timeout' => 2
]);

Expand Down
1 change: 1 addition & 0 deletions examples/monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Examples;

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

use RedisClient\RedisClient;

Expand Down
1 change: 1 addition & 0 deletions examples/pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Examples;

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

use RedisClient\Pipeline\Pipeline;
use RedisClient\Pipeline\PipelineInterface;
Expand Down
1 change: 1 addition & 0 deletions examples/pubsub.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Examples;

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

use RedisClient\RedisClient;

Expand Down
1 change: 1 addition & 0 deletions examples/transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Examples;

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

use RedisClient\Pipeline\Pipeline;
use RedisClient\Pipeline\PipelineInterface;
Expand Down
42 changes: 40 additions & 2 deletions tests/Integration/Version3x2/KeysCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,49 @@ public static function setUpBeforeClass() {
}

public function test_dump() {
//todo
$Redis = static::$Redis;

$this->assertSame(null, $Redis->dump('key'));

$Redis->set('key', "\x00");
$this->assertSame("\x00\x01\x00\x07\x00\xa4\xca\xf0\x3f\x64\xdd\x96\x4c", $Redis->dump('key'));

$Redis->set('key', "1");
$this->assertSame("\x00\xc0\x01\x07\x00\xd9\x4a\x32\x45\xd9\xcb\xc4\xe6", $Redis->dump('key'));

$Redis->set('key', "10");
$this->assertSame("\x00\xc0\x0a\x07\x00\x91\xad\x82\xb6\x06\x64\xb6\xa1", $Redis->dump('key'));

$Redis->hset('hash', 'field', 'value');
$this->assertSame("\x0d\x19\x19\x00\x00\x00\x11\x00\x00\x00\x02\x00\x00\x05\x66\x69\x65\x6c\x64".
"\x07\x05\x76\x61\x6c\x75\x65\xff\x07\x00\x93\xd1\xce\x4d\xd7\x96\x00\xd0", $Redis->dump('hash'));

}

public function test_restore() {
//todo
$Redis = static::$Redis;

$this->assertSame(true, $Redis->restore('key', 0, "\x00\x01\x00\x07\x00\xa4\xca\xf0\x3f\x64\xdd\x96\x4c"));
$this->assertSame("\x00", $Redis->get('key'));

$this->assertSame(true, $Redis->restore('key', 0, "\x00\xc0\x01\x07\x00\xd9\x4a\x32\x45\xd9\xcb\xc4\xe6", true));
$this->assertSame('1', $Redis->get('key'));

$this->assertSame(true, $Redis->restore('key', 0, "\x00\xc0\x0a\x07\x00\x91\xad\x82\xb6\x06\x64\xb6\xa1", true));
$this->assertSame('10', $Redis->get('key'));

$this->assertSame(true, $Redis->restore('hash', 0,
"\x0d\x19\x19\x00\x00\x00\x11\x00\x00\x00\x02\x00\x00\x05\x66\x69\x65\x6c\x64".
"\x07\x05\x76\x61\x6c\x75\x65\xff\x07\x00\x93\xd1\xce\x4d\xd7\x96\x00\xd0"
));
$this->assertSame('value', $Redis->hget('hash', 'field'));

try {
$this->assertSame(true, $Redis->restore('key', 0, "\x00\x01\x00\x07\x00\xa4\xca\xf0\x3f\x64\xdd\x96\x4c"));
$this->assertFalse('Expect Exception');
} catch (\Exception $Ex) {
$this->assertInstanceOf(ErrorResponseException::class, $Ex);
}
}

public function test_rename() {
Expand Down