Skip to content

Commit 388225b

Browse files
committed
Merge pull request #32 from cheprasov/v1-2-0
v1.2.0
2 parents c5e95fd + 6c4bd5c commit 388225b

File tree

8 files changed

+106
-6
lines changed

8 files changed

+106
-6
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## CHANGELOG
2+
3+
### v1.2.0 (2016-07-30)
4+
- Updated command __MIGRATE__ (Redis >= 3.2): many fixes to the variable number of arguments (new) mode using the KEYS option.
5+
6+
### v1.1.0 (2016-01-26)
7+
Sorry, no any history before.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
22

3-
# RedisClient v1.1.0 for PHP >= 5.5
3+
# RedisClient v1.2.0 for PHP >= 5.5
44

55
## About
66
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
77

88
## Main features
9-
- Support Redis versions from __2.6__ to __3.2-RC1__.
9+
- Support Redis versions from __2.6__ to __3.2.0-RC3__.
1010
- Support TCP/IP and UNIX sockets.
1111
- Support __PubSub__ and __monitor__ functionallity.
1212
- Support __pipeline__.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheprasov/php-redis-client",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Php client for Redis",
55
"homepage": "http://github.com/cheprasov/php-redis-client",
66
"minimum-stability": "stable",

src/RedisClient/Client/AbstractRedisClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
abstract class AbstractRedisClient {
2222

23-
const VERSION = '1.1.0';
23+
const VERSION = '1.2.0';
2424

2525
const CONFIG_SERVER = 'server';
2626
const CONFIG_TIMEOUT = 'timeout';

src/RedisClient/Command/Traits/Version3x2/CommandsTrait.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use RedisClient\Command\Traits\Version3x0\ClusterCommandsTrait;
1717
use RedisClient\Command\Traits\Version2x6\ConnectionCommandsTrait;
1818
use RedisClient\Command\Traits\Version2x8\HyperLogLogCommandsTrait;
19-
use RedisClient\Command\Traits\Version3x0\KeysCommandsTrait;
2019
use RedisClient\Command\Traits\Version2x6\ListsCommandsTrait;
2120
use RedisClient\Command\Traits\Version3x0\SortedSetsCommandsTrait;
2221
use RedisClient\Command\Traits\Version2x8\StringsCommandsTrait;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* This file is part of RedisClient.
4+
* git: https://github.com/cheprasov/php-redis-client
5+
*
6+
* (C) Alexander Cheprasov <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace RedisClient\Command\Traits\Version3x2;
12+
13+
use RedisClient\Command\Traits\Version3x0\KeysCommandsTrait as KeysCommandsTraitVersion3x0;
14+
15+
/**
16+
* trait KeysCommandsTrait
17+
*/
18+
trait KeysCommandsTrait {
19+
20+
use KeysCommandsTraitVersion3x0;
21+
22+
/**
23+
* MIGRATE host port key|"" destination-db timeout [COPY] [REPLACE] [KEYS key [key ...]]
24+
* Available since 2.6.0.
25+
* @link http://redis.io/commands/migrate
26+
*
27+
* @param string $host
28+
* @param int $port
29+
* @param string|string[] $keys
30+
* @param int $destinationDb
31+
* @param int $timeout In milliseconds
32+
* @param bool $copy Available in 3.0 and are not available in 2.6 or 2.8
33+
* @param bool $replace Available in 3.0 and are not available in 2.6 or 2.8
34+
* @return bool The command returns True on success.
35+
*/
36+
public function migrate($host, $port, $keys, $destinationDb, $timeout, $copy = false, $replace = false) {
37+
$params = [$host, $port, is_string($keys) ? $keys : '', $destinationDb, $timeout];
38+
if ($copy) {
39+
$params[] = 'COPY';
40+
}
41+
if ($replace) {
42+
$params[] = 'REPLACE';
43+
}
44+
if (is_array($keys)) {
45+
$params[] = 'KEYS';
46+
$params[] = $keys;
47+
}
48+
return $this->returnCommand(['MIGRATE'], $params);
49+
}
50+
51+
}

src/RedisClient/Pipeline/Version/Pipeline3x2.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
*
262262
* Keys
263263
* @method Pipeline3x2 exists($keys)
264-
* @method Pipeline3x2 migrate($host, $port, $key, $destinationDb, $timeout, $copy = false, $replace = false)
264+
* -method Pipeline3x2 migrate($host, $port, $key, $destinationDb, $timeout, $copy = false, $replace = false)
265265
* @method Pipeline3x2 restore($key, $ttl, $serializedValue, $replace = false)
266266
* @method Pipeline3x2 wait($numslaves, $timeout)
267267
*
@@ -282,6 +282,9 @@
282282
* Hashes
283283
* @method Pipeline3x2 hstrlen($key, $field)
284284
*
285+
* Keys
286+
* @method Pipeline3x2 migrate($host, $port, $keys, $destinationDb, $timeout, $copy = false, $replace = false)
287+
*
285288
* Scripting
286289
* @method Pipeline3x2 scriptDebug($param)
287290
*

tests/Integration/Version3x2/KeysCommandsTest.php

+40
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,44 @@ public function test_object() {
153153
$this->assertSame('raw', $Redis->object('encoding', 'foo'));
154154
}
155155

156+
public function test_migrate() {
157+
$Redis = static::$Redis;
158+
$Redis2 = static::$Redis2;
159+
$this->assertSame(true, $Redis2->flushall());
160+
161+
list(, $host, $port) = explode(':', str_replace('/', '', static::TEST_REDIS_SERVER_2), 3);
162+
163+
$this->assertSame(true, $Redis->set('one', 1));
164+
165+
$this->assertSame(null, $Redis2->get('one'));
166+
$this->assertSame(true, $Redis->migrate($host, $port, 'one', 0, 100, true));
167+
$this->assertSame('1', $Redis2->get('one'));
168+
$this->assertSame('1', $Redis->get('one'));
169+
170+
$this->assertSame(true, $Redis->set('one', 11));
171+
172+
try {
173+
$this->assertSame(true, $Redis->migrate($host, $port, 'one', 0, 100, true));
174+
$this->assertFalse('Expect Exception');
175+
} catch (\Exception $Ex) {
176+
$this->assertInstanceOf(ErrorResponseException::class, $Ex);
177+
}
178+
179+
$this->assertSame(true, $Redis->migrate($host, $port, 'one', 0, 100, false, true));
180+
$this->assertSame('11', $Redis2->get('one'));
181+
$this->assertSame(null, $Redis->get('one'));
182+
183+
$this->assertSame(true, $Redis->set('one', 1));
184+
$this->assertSame(true, $Redis->set('two', 2));
185+
$this->assertSame(true, $Redis->set('three', 3));
186+
187+
$this->assertSame(true, $Redis->migrate($host, $port, ['one', 'two', 'three'], 0, 100, false, true));
188+
$this->assertSame('1', $Redis2->get('one'));
189+
$this->assertSame(null, $Redis->get('one'));
190+
$this->assertSame('2', $Redis2->get('two'));
191+
$this->assertSame(null, $Redis->get('two'));
192+
$this->assertSame('3', $Redis2->get('three'));
193+
$this->assertSame(null, $Redis->get('three'));
194+
}
195+
156196
}

0 commit comments

Comments
 (0)