Skip to content

Commit ee7a698

Browse files
committed
Merge pull request #28 from cheprasov/dev-with-versions
Updated Readme.md
2 parents d331ea1 + b893a16 commit ee7a698

File tree

7 files changed

+111
-8
lines changed

7 files changed

+111
-8
lines changed

README.md

+64-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
1-
# php-redis-client
2-
Project in development
1+
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
32

4-
Docker with Redis for tests
5-
https://hub.docker.com/r/cheprasov/redis-for-tests/
3+
# RedisClient v1.0.0 for PHP >= 5.5
4+
5+
## About
6+
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
7+
8+
## Main features
9+
- Support Redis versions from __2.6__ to __3.2-RC1__.
10+
- Support TCP/IP and UNIX sockets.
11+
- Support __PubSub__ and __monitor__ functionallity.
12+
- Support __pipeline__.
13+
- Connections to Redis are established lazily by the client upon the first command.
14+
- Easy to use with IDE, client has PHPDocs for all supported versions.
15+
16+
## Usage
17+
18+
### Create a new instance of RedisClient
19+
```php
20+
<?php
21+
require (dirname(__DIR__).'/src/autoloader.php');
22+
// or require ('vendor/autoload.php');
23+
24+
use RedisClient\RedisClient;
25+
use RedisClient\Client\Version\RedisClient2x6;
26+
27+
$Redis = new RedisClient([
28+
'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
29+
'timeout' => 2
30+
]);
31+
32+
echo 'RedisClient: '. $Redis->getVersion() . PHP_EOL;
33+
echo 'Redis: '. $Redis->info('Server')['redis_version'] . PHP_EOL;
34+
35+
// RedisClient: 3.0
36+
// Redis: 3.0.3
37+
```
38+
### Example
39+
Please, see examples here: https://github.com/cheprasov/php-redis-client/tree/master/examples
40+
41+
42+
## Installation
43+
44+
### Composer
45+
46+
Download composer:
47+
48+
wget -nc http://getcomposer.org/composer.phar
49+
50+
and add dependency to your project:
51+
52+
php composer.phar require cheprasov/php-redis-client
53+
54+
## Running tests
55+
56+
1. Use Docker container with Redis for tests https://hub.docker.com/r/cheprasov/redis-for-tests/
57+
2. To run tests type in console (do not forget run Docker):
58+
59+
60+
./vendor/bin/phpunit
61+
62+
63+
## Something doesn't work
64+
65+
Feel free to fork project, fix bugs and finally request for pull

examples/create_new_instance.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Examples;
1717

1818
require (dirname(__DIR__).'/src/autoloader.php');
19+
// or require ('vendor/autoload.php');
1920

2021
use RedisClient\RedisClient;
2122
use RedisClient\Client\Version\RedisClient2x6;
@@ -35,7 +36,7 @@
3536
// Example 2. Create new Instance with config
3637

3738
$Redis = new RedisClient([
38-
'server' => 'tcp://127.0.0.1:6379',
39+
'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
3940
'timeout' => 2
4041
]);
4142

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

5253
$Redis = new RedisClient2x6([
53-
'server' => 'tcp://127.0.0.1:6379',
54+
'server' => 'tcp://127.0.0.1:6379', // or 'unix:///tmp/redis.sock'
5455
'timeout' => 2
5556
]);
5657

examples/monitor.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Examples;
1717

1818
require (dirname(__DIR__).'/src/autoloader.php');
19+
// or require ('vendor/autoload.php');
1920

2021
use RedisClient\RedisClient;
2122

examples/pipeline.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Examples;
1717

1818
require (dirname(__DIR__).'/src/autoloader.php');
19+
// or require ('vendor/autoload.php');
1920

2021
use RedisClient\Pipeline\Pipeline;
2122
use RedisClient\Pipeline\PipelineInterface;

examples/pubsub.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Examples;
1717

1818
require (dirname(__DIR__).'/src/autoloader.php');
19+
// or require ('vendor/autoload.php');
1920

2021
use RedisClient\RedisClient;
2122

examples/transactions.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Examples;
1717

1818
require (dirname(__DIR__).'/src/autoloader.php');
19+
// or require ('vendor/autoload.php');
1920

2021
use RedisClient\Pipeline\Pipeline;
2122
use RedisClient\Pipeline\PipelineInterface;

tests/Integration/Version3x2/KeysCommandsTest.php

+40-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,49 @@ public static function setUpBeforeClass() {
3939
}
4040

4141
public function test_dump() {
42-
//todo
42+
$Redis = static::$Redis;
43+
44+
$this->assertSame(null, $Redis->dump('key'));
45+
46+
$Redis->set('key', "\x00");
47+
$this->assertSame("\x00\x01\x00\x07\x00\xa4\xca\xf0\x3f\x64\xdd\x96\x4c", $Redis->dump('key'));
48+
49+
$Redis->set('key', "1");
50+
$this->assertSame("\x00\xc0\x01\x07\x00\xd9\x4a\x32\x45\xd9\xcb\xc4\xe6", $Redis->dump('key'));
51+
52+
$Redis->set('key', "10");
53+
$this->assertSame("\x00\xc0\x0a\x07\x00\x91\xad\x82\xb6\x06\x64\xb6\xa1", $Redis->dump('key'));
54+
55+
$Redis->hset('hash', 'field', 'value');
56+
$this->assertSame("\x0d\x19\x19\x00\x00\x00\x11\x00\x00\x00\x02\x00\x00\x05\x66\x69\x65\x6c\x64".
57+
"\x07\x05\x76\x61\x6c\x75\x65\xff\x07\x00\x93\xd1\xce\x4d\xd7\x96\x00\xd0", $Redis->dump('hash'));
58+
4359
}
4460

4561
public function test_restore() {
46-
//todo
62+
$Redis = static::$Redis;
63+
64+
$this->assertSame(true, $Redis->restore('key', 0, "\x00\x01\x00\x07\x00\xa4\xca\xf0\x3f\x64\xdd\x96\x4c"));
65+
$this->assertSame("\x00", $Redis->get('key'));
66+
67+
$this->assertSame(true, $Redis->restore('key', 0, "\x00\xc0\x01\x07\x00\xd9\x4a\x32\x45\xd9\xcb\xc4\xe6", true));
68+
$this->assertSame('1', $Redis->get('key'));
69+
70+
$this->assertSame(true, $Redis->restore('key', 0, "\x00\xc0\x0a\x07\x00\x91\xad\x82\xb6\x06\x64\xb6\xa1", true));
71+
$this->assertSame('10', $Redis->get('key'));
72+
73+
$this->assertSame(true, $Redis->restore('hash', 0,
74+
"\x0d\x19\x19\x00\x00\x00\x11\x00\x00\x00\x02\x00\x00\x05\x66\x69\x65\x6c\x64".
75+
"\x07\x05\x76\x61\x6c\x75\x65\xff\x07\x00\x93\xd1\xce\x4d\xd7\x96\x00\xd0"
76+
));
77+
$this->assertSame('value', $Redis->hget('hash', 'field'));
78+
79+
try {
80+
$this->assertSame(true, $Redis->restore('key', 0, "\x00\x01\x00\x07\x00\xa4\xca\xf0\x3f\x64\xdd\x96\x4c"));
81+
$this->assertFalse('Expect Exception');
82+
} catch (\Exception $Ex) {
83+
$this->assertInstanceOf(ErrorResponseException::class, $Ex);
84+
}
4785
}
4886

4987
public function test_rename() {

0 commit comments

Comments
 (0)