Skip to content

Commit 88530ee

Browse files
Add cluster specific testInfo() method
1 parent 501561b commit 88530ee

3 files changed

Lines changed: 59 additions & 36 deletions

File tree

redis_cluster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,10 +2338,10 @@ static void cluster_raw_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len)
23382338
}
23392339

23402340
/* Initialize our command */
2341-
redis_cmd_init_sstr(&cmd, argc, kw, kw_len);
2341+
redis_cmd_init_sstr(&cmd, argc-1, kw, kw_len);
23422342

23432343
/* Iterate, appending args */
2344-
for(i=0;i<argc;i++) {
2344+
for(i=1;i<argc;i++) {
23452345
convert_to_string(z_args[i]);
23462346
redis_cmd_append_sstr(&cmd, Z_STRVAL_P(z_args[i]),
23472347
Z_STRLEN_P(z_args[i]));

tests/RedisClusterTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
class Redis_Cluster_Test extends Redis_Test {
1010
private $_arr_node_map = Array();
1111

12+
/* Tests we'll skip all together in the context of RedisCluster. The
13+
* RedisCluster class doesn't implement specialized (non-redis) commands
14+
* such as sortAsc, or sortDesc and other commands such as SELECT are
15+
* simply invalid in Redis Cluster */
16+
public function testSortAsc() { return $this->markTestSkipped(); }
17+
public function testSortDesc() { return $this->markTestSkipped(); }
18+
public function testWait() { return $this->markTestSkipped(); }
19+
public function testSelect() { return $this->markTestSkipped(); }
20+
1221
/* Load our seeds on construction */
1322
public function __construct() {
1423
$str_nodemap_file = dirname($_SERVER['PHP_SELF']) . '/nodes/nodemap';
@@ -59,9 +68,6 @@ public function testEcho() {
5968
$this->assertEquals($this->redis->echo('k3', " 0123 "), " 0123 ");
6069
}
6170

62-
public function testSortAsc() { return $this->markTestSkipped(); }
63-
public function testSortDesc() { return $this->markTestSkipped(); }
64-
6571
public function testSortPrefix() {
6672
$this->redis->setOption(Redis::OPT_PREFIX, 'some-prefix:');
6773
$this->redis->del('some-item');
@@ -85,5 +91,21 @@ public function testDBSize() {
8591
}
8692
}
8793

94+
public function testInfo() {
95+
$arr_check_keys = Array(
96+
"redis_version", "arch_bits", "uptime_in_seconds", "uptime_in_days",
97+
"connected_clients", "connected_slaves", "used_memory",
98+
"total_connections_received", "total_commands_processed",
99+
"role"
100+
);
101+
102+
for ($i = 0; $i < 3; $i++) {
103+
$arr_info = $this->redis->info("k:$i");
104+
foreach ($arr_check_keys as $str_check_key) {
105+
$this->assertTrue(isset($arr_info[$str_check_key]));
106+
}
107+
}
108+
}
109+
88110
}
89111
?>

tests/RedisTest.php

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,36 +1810,37 @@ public function testWait() {
18101810
}
18111811

18121812
public function testinfo() {
1813-
$info = $this->redis->info();
1814-
1815-
$keys = array(
1816-
"redis_version",
1817-
"arch_bits",
1818-
"uptime_in_seconds",
1819-
"uptime_in_days",
1820-
"connected_clients",
1821-
"connected_slaves",
1822-
"used_memory",
1823-
"total_connections_received",
1824-
"total_commands_processed",
1825-
"role");
1826-
if (version_compare($this->version, "2.5.0", "lt")) {
1827-
array_push($keys,
1828-
"changes_since_last_save",
1829-
"bgsave_in_progress",
1830-
"last_save_time"
1831-
);
1832-
} else {
1833-
array_push($keys,
1834-
"rdb_changes_since_last_save",
1835-
"rdb_bgsave_in_progress",
1836-
"rdb_last_save_time"
1837-
);
1838-
}
1813+
$info = $this->redis->info();
18391814

1840-
foreach($keys as $k) {
1841-
$this->assertTrue(in_array($k, array_keys($info)));
1842-
}
1815+
$keys = array(
1816+
"redis_version",
1817+
"arch_bits",
1818+
"uptime_in_seconds",
1819+
"uptime_in_days",
1820+
"connected_clients",
1821+
"connected_slaves",
1822+
"used_memory",
1823+
"total_connections_received",
1824+
"total_commands_processed",
1825+
"role"
1826+
);
1827+
if (version_compare($this->version, "2.5.0", "lt")) {
1828+
array_push($keys,
1829+
"changes_since_last_save",
1830+
"bgsave_in_progress",
1831+
"last_save_time"
1832+
);
1833+
} else {
1834+
array_push($keys,
1835+
"rdb_changes_since_last_save",
1836+
"rdb_bgsave_in_progress",
1837+
"rdb_last_save_time"
1838+
);
1839+
}
1840+
1841+
foreach($keys as $k) {
1842+
$this->assertTrue(in_array($k, array_keys($info)));
1843+
}
18431844
}
18441845

18451846
public function testInfoCommandStats() {
@@ -1860,8 +1861,8 @@ public function testInfoCommandStats() {
18601861
}
18611862

18621863
public function testSelect() {
1863-
$this->assertFalse($this->redis->select(-1));
1864-
$this->assertTrue($this->redis->select(0));
1864+
$this->assertFalse($this->redis->select(-1));
1865+
$this->assertTrue($this->redis->select(0));
18651866
}
18661867

18671868
public function testMset() {

0 commit comments

Comments
 (0)