From b893a16eb4687a8afd8890844ca82f5167bd812b Mon Sep 17 00:00:00 2001 From: Alexander Cheprasov Date: Sun, 24 Jan 2016 13:51:40 +0000 Subject: [PATCH] Updated Readme.md --- README.md | 68 +++++++++++++++++-- examples/create_new_instance.php | 5 +- examples/monitor.php | 1 + examples/pipeline.php | 1 + examples/pubsub.php | 1 + examples/transactions.php | 1 + .../Version3x2/KeysCommandsTest.php | 42 +++++++++++- 7 files changed, 111 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4c342b9..7ea279c 100644 --- a/README.md +++ b/README.md @@ -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 + '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 diff --git a/examples/create_new_instance.php b/examples/create_new_instance.php index 71f60ac..ae4a061 100644 --- a/examples/create_new_instance.php +++ b/examples/create_new_instance.php @@ -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; @@ -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 ]); @@ -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 ]); diff --git a/examples/monitor.php b/examples/monitor.php index 74f650d..b12bcf0 100644 --- a/examples/monitor.php +++ b/examples/monitor.php @@ -16,6 +16,7 @@ namespace Examples; require (dirname(__DIR__).'/src/autoloader.php'); +// or require ('vendor/autoload.php'); use RedisClient\RedisClient; diff --git a/examples/pipeline.php b/examples/pipeline.php index 98284e4..3449b4a 100644 --- a/examples/pipeline.php +++ b/examples/pipeline.php @@ -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; diff --git a/examples/pubsub.php b/examples/pubsub.php index 56a63ab..5f5aeca 100644 --- a/examples/pubsub.php +++ b/examples/pubsub.php @@ -16,6 +16,7 @@ namespace Examples; require (dirname(__DIR__).'/src/autoloader.php'); +// or require ('vendor/autoload.php'); use RedisClient\RedisClient; diff --git a/examples/transactions.php b/examples/transactions.php index e114143..b539756 100644 --- a/examples/transactions.php +++ b/examples/transactions.php @@ -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; diff --git a/tests/Integration/Version3x2/KeysCommandsTest.php b/tests/Integration/Version3x2/KeysCommandsTest.php index 03816c9..a727671 100644 --- a/tests/Integration/Version3x2/KeysCommandsTest.php +++ b/tests/Integration/Version3x2/KeysCommandsTest.php @@ -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() {