Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2018-01-17 20:36:38 +0300
committermichael-grunder <michael.grunder@gmail.com>2018-01-17 20:36:38 +0300
commit9e65c429318d93bd37c9d42abf79709395e6e805 (patch)
tree379dc0f44cb4b7219eab0c4c31184f734f1d881d /tests
parent837dee471ccac86581d306594ee945e82027572f (diff)
Implement UNLINK command
This commit implements UNLINK for Redis, RedisCluster, and RedisArray. To a client library UNLINK behaves identically to DEL so we can use the same handlers for both.
Diffstat (limited to 'tests')
-rw-r--r--tests/RedisArrayTest.php55
-rw-r--r--tests/RedisTest.php65
2 files changed, 90 insertions, 30 deletions
diff --git a/tests/RedisArrayTest.php b/tests/RedisArrayTest.php
index 0233b6d2..01e1c2f2 100644
--- a/tests/RedisArrayTest.php
+++ b/tests/RedisArrayTest.php
@@ -18,8 +18,30 @@ function parseHostPort($str, &$host, &$port) {
$port = substr($str, $pos+1);
}
+function getRedisVersion($obj_r) {
+ $arr_info = $obj_r->info();
+ if (!$arr_info || !isset($arr_info['redis_version'])) {
+ return "0.0.0";
+ }
+ return $arr_info['redis_version'];
+}
+
+/* Determine the lowest redis version attached to this RedisArray object */
+function getMinVersion($obj_ra) {
+ $min_version = "0.0.0";
+ foreach ($obj_ra->_hosts() as $host) {
+ $version = getRedisVersion($obj_ra->_instance($host));
+ if (version_compare($version, $min_version) > 0) {
+ $min_version = $version;
+ }
+ }
+
+ return $min_version;
+}
+
class Redis_Array_Test extends TestSuite
{
+ private $min_version;
private $strings;
public $ra = NULL;
private $data = NULL;
@@ -34,6 +56,7 @@ class Redis_Array_Test extends TestSuite
global $newRing, $oldRing, $useIndex;
$this->ra = new RedisArray($newRing, array('previous' => $oldRing, 'index' => $useIndex));
+ $this->min_version = getMinVersion($this->ra);
}
public function testMSet() {
@@ -141,6 +164,8 @@ class Redis_Rehashing_Test extends TestSuite
public $ra = NULL;
private $useIndex;
+ private $min_version;
+
// data
private $strings;
private $sets;
@@ -185,6 +210,7 @@ class Redis_Rehashing_Test extends TestSuite
// create array
$this->ra = new RedisArray($newRing, array('previous' => $oldRing, 'index' => $useIndex));
+ $this->min_version = getMinVersion($this->ra);
}
public function testFlush() {
@@ -206,12 +232,12 @@ class Redis_Rehashing_Test extends TestSuite
foreach($this->strings as $k => $v) {
$this->ra->set($k, $v);
}
-
+
// sets
foreach($this->sets as $k => $v) {
call_user_func_array(array($this->ra, 'sadd'), array_merge(array($k), $v));
}
-
+
// lists
foreach($this->lists as $k => $v) {
call_user_func_array(array($this->ra, 'rpush'), array_merge(array($k), $v));
@@ -221,7 +247,7 @@ class Redis_Rehashing_Test extends TestSuite
foreach($this->hashes as $k => $v) {
$this->ra->hmset($k, $v);
}
-
+
// sorted sets
foreach($this->zsets as $k => $v) {
call_user_func_array(array($this->ra, 'zadd'), array_merge(array($k), $v));
@@ -314,6 +340,7 @@ class Redis_Rehashing_Test extends TestSuite
class Redis_Auto_Rehashing_Test extends TestSuite {
public $ra = NULL;
+ private $min_version;
// data
private $strings;
@@ -330,6 +357,7 @@ class Redis_Auto_Rehashing_Test extends TestSuite {
// create array
$this->ra = new RedisArray($newRing, array('previous' => $oldRing, 'index' => $useIndex, 'autorehash' => TRUE));
+ $this->min_version = getMinVersion($this->ra);
}
public function testDistribute() {
@@ -378,11 +406,14 @@ class Redis_Auto_Rehashing_Test extends TestSuite {
// Test node-specific multi/exec
class Redis_Multi_Exec_Test extends TestSuite {
public $ra = NULL;
+ private $min_version;
public function setUp() {
global $newRing, $oldRing, $useIndex;
+
// create array
$this->ra = new RedisArray($newRing, array('previous' => $oldRing, 'index' => $useIndex));
+ $this->min_version = getMinVersion($this->ra);
}
public function testInit() {
@@ -464,6 +495,22 @@ class Redis_Multi_Exec_Test extends TestSuite {
$this->assertEquals(0, $this->ra->exists('1_{employee:joe}_salary'));
}
+ public function testMutliExecUnlink() {
+ if (version_compare($this->min_version, "4.0.0", "lt")) {
+ var_dump($this->min_version);
+ $this->markTestSkipped();
+ }
+
+ $this->ra->set('{unlink}:key1', 'bar');
+ $this->ra->set('{unlink}:key2', 'bar');
+
+ $out = $this->ra->multi($this->ra->_target('{unlink}'))
+ ->del('{unlink}:key1', '{unlink}:key2')
+ ->exec();
+
+ $this->assertTrue($out[0] === 2);
+ }
+
public function testDiscard() {
/* phpredis issue #87 */
$key = 'test_err';
@@ -502,11 +549,13 @@ class Redis_Multi_Exec_Test extends TestSuite {
class Redis_Distributor_Test extends TestSuite {
public $ra = NULL;
+ private $min_version;
public function setUp() {
global $newRing, $oldRing, $useIndex;
// create array
$this->ra = new RedisArray($newRing, array('previous' => $oldRing, 'index' => $useIndex, 'distributor' => array($this, 'distribute')));
+ $this->min_version = getMinVersion($this->ra);
}
public function testInit() {
diff --git a/tests/RedisTest.php b/tests/RedisTest.php
index f2ec3015..b7a0ba2b 100644
--- a/tests/RedisTest.php
+++ b/tests/RedisTest.php
@@ -456,7 +456,7 @@ class Redis_Test extends TestSuite
$this->assertTrue($this->redis->ttl('key') ===7);
$this->assertTrue($this->redis->get('key') === 'val');
}
-
+
public function testPSetEx() {
$this->redis->del('key');
$this->assertTrue($this->redis->psetex('key', 7 * 1000, 'val') === TRUE);
@@ -626,38 +626,49 @@ class Redis_Test extends TestSuite
$this->assertEquals(array(), $this->redis->keys(rand().rand().rand().'*'));
}
- public function testDelete()
- {
+ protected function genericDelUnlink($cmd) {
$key = 'key' . rand();
$this->redis->set($key, 'val');
$this->assertEquals('val', $this->redis->get($key));
- $this->assertEquals(1, $this->redis->del($key));
+ $this->assertEquals(1, $this->redis->$cmd($key));
$this->assertEquals(false, $this->redis->get($key));
- // multiple, all existing
- $this->redis->set('x', 0);
- $this->redis->set('y', 1);
- $this->redis->set('z', 2);
- $this->assertEquals(3, $this->redis->del('x', 'y', 'z'));
- $this->assertEquals(false, $this->redis->get('x'));
- $this->assertEquals(false, $this->redis->get('y'));
- $this->assertEquals(false, $this->redis->get('z'));
-
- // multiple, none existing
- $this->assertEquals(0, $this->redis->del('x', 'y', 'z'));
- $this->assertEquals(false, $this->redis->get('x'));
- $this->assertEquals(false, $this->redis->get('y'));
- $this->assertEquals(false, $this->redis->get('z'));
-
- // multiple, some existing
- $this->redis->set('y', 1);
- $this->assertEquals(1, $this->redis->del('x', 'y', 'z'));
- $this->assertEquals(false, $this->redis->get('y'));
-
- $this->redis->set('x', 0);
- $this->redis->set('y', 1);
- $this->assertEquals(2, $this->redis->del(array('x', 'y')));
+ // multiple, all existing
+ $this->redis->set('x', 0);
+ $this->redis->set('y', 1);
+ $this->redis->set('z', 2);
+ $this->assertEquals(3, $this->redis->$cmd('x', 'y', 'z'));
+ $this->assertEquals(false, $this->redis->get('x'));
+ $this->assertEquals(false, $this->redis->get('y'));
+ $this->assertEquals(false, $this->redis->get('z'));
+
+ // multiple, none existing
+ $this->assertEquals(0, $this->redis->$cmd('x', 'y', 'z'));
+ $this->assertEquals(false, $this->redis->get('x'));
+ $this->assertEquals(false, $this->redis->get('y'));
+ $this->assertEquals(false, $this->redis->get('z'));
+
+ // multiple, some existing
+ $this->redis->set('y', 1);
+ $this->assertEquals(1, $this->redis->$cmd('x', 'y', 'z'));
+ $this->assertEquals(false, $this->redis->get('y'));
+
+ $this->redis->set('x', 0);
+ $this->redis->set('y', 1);
+ $this->assertEquals(2, $this->redis->$cmd(array('x', 'y')));
+ }
+
+ public function testDelete() {
+ $this->genericDelUnlink("DEL");
+ }
+
+ public function testUnlink() {
+ if (version_compare($this->version, "4.0.0", "lt")) {
+ $this->markTestSkipped();
+ return;
+ }
+ $this->genericDelUnlink("UNLINK");
}
public function testType()