Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9c48b7

Browse files
KeyDB: Get our tests passing against KeyDB.
This commit fixes our unit tests so they also pass against the KeyDB server. We didn't ned to change all that much. Most of it was just adding a version/keydb check. The only change to PhpRedis itself was to relax the reply requirements for XAUTOCLAIM. Redis 7.0.0 added a third "these elements were recently removed" reply which KeyDB does not have. Fixes #2466
1 parent c7a73ab commit d9c48b7

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

library.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,9 +2310,9 @@ redis_read_xclaim_reply(RedisSock *redis_sock, int count, int is_xautoclaim, zva
23102310
zval z_msgs = {0};
23112311
char *id = NULL;
23122312
long id_len = 0;
2313-
int messages;
2313+
int messages = 0;
23142314

2315-
ZEND_ASSERT(!is_xautoclaim || count == 3);
2315+
ZEND_ASSERT(!is_xautoclaim || (count == 2 || count == 3));
23162316

23172317
ZVAL_UNDEF(rv);
23182318

@@ -2338,15 +2338,18 @@ redis_read_xclaim_reply(RedisSock *redis_sock, int count, int is_xautoclaim, zva
23382338
if (is_xautoclaim) {
23392339
zval z_deleted = {0};
23402340

2341-
if (redis_sock_read_multibulk_reply_zval(redis_sock, &z_deleted) == NULL)
2341+
if (count == 3 && redis_sock_read_multibulk_reply_zval(redis_sock, &z_deleted) == NULL)
23422342
goto failure;
23432343

23442344
array_init(rv);
23452345

2346-
// Package up ID, message, and deleted messages in our reply
2346+
// Package up ID and message
23472347
add_next_index_stringl(rv, id, id_len);
23482348
add_next_index_zval(rv, &z_msgs);
2349-
add_next_index_zval(rv, &z_deleted);
2349+
2350+
// Add deleted messages if they exist
2351+
if (count == 3)
2352+
add_next_index_zval(rv, &z_deleted);
23502353

23512354
efree(id);
23522355
} else {

tests/RedisClusterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function setUp() {
9494
$this->redis = $this->newInstance();
9595
$info = $this->redis->info(uniqid());
9696
$this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0');
97+
$this->is_keydb = $this->redis->info('keydb') !== false;
9798
}
9899

99100
/* Override newInstance as we want a RedisCluster object */

tests/RedisTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function setUp() {
7575
$this->redis = $this->newInstance();
7676
$info = $this->redis->info();
7777
$this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0');
78+
79+
$this->is_keydb = $this->redis->info('keydb') !== false;
7880
}
7981

8082
protected function minVersionCheck($version) {
@@ -265,9 +267,11 @@ public function testBitcount() {
265267
$this->redis->set('bitcountkey', hex2bin('10eb8939e68bfdb640260f0629f3'));
266268
$this->assertEquals(1, $this->redis->bitcount('bitcountkey', 8, 8, false));
267269

268-
/* key, start, end, BIT */
269-
$this->redis->set('bitcountkey', hex2bin('cd0e4c80f9e4590d888a10'));
270-
$this->assertEquals(5, $this->redis->bitcount('bitcountkey', 0, 9, true));
270+
if ( ! $this->is_keydb) {
271+
/* key, start, end, BIT */
272+
$this->redis->set('bitcountkey', hex2bin('cd0e4c80f9e4590d888a10'));
273+
$this->assertEquals(5, $this->redis->bitcount('bitcountkey', 0, 9, true));
274+
}
271275
}
272276

273277
public function testBitop() {
@@ -331,6 +335,8 @@ public function testBitsets() {
331335
}
332336

333337
public function testLcs() {
338+
if ( ! $this->minVersionCheck('7.0.0') || $this->is_keydb)
339+
$this->markTestSkipped();
334340

335341
$key1 = '{lcs}1'; $key2 = '{lcs}2';
336342
$this->assertTrue($this->redis->set($key1, '12244447777777'));
@@ -7094,7 +7100,12 @@ public function testXAutoClaim() {
70947100

70957101
// Test an empty xautoclaim reply
70967102
$res = $this->redis->xAutoClaim('ships', 'combatants', 'Sisko', 0, '0-0');
7097-
$this->assertEquals(['0-0', [], []], $res);
7103+
$this->assertTrue(is_array($res) && (count($res) == 2 || count($res) == 3));
7104+
if (count($res) == 2) {
7105+
$this->assertEquals(['0-0', []], $res);
7106+
} else {
7107+
$this->assertEquals(['0-0', [], []], $res);
7108+
}
70987109

70997110
$this->redis->xAdd('ships', '1424-74205', ['name' => 'Defiant']);
71007111

@@ -7108,9 +7119,9 @@ public function testXAutoClaim() {
71087119
// Assume control of the pending message with a different consumer.
71097120
$res = $this->redis->xAutoClaim('ships', 'combatants', 'Sisko', 0, '0-0');
71107121

7111-
$this->assertTrue($res && count($res) == 3 && $res[0] == '0-0' &&
7112-
isset($res[1]['1424-74205']['name']) &&
7113-
$res[1]['1424-74205']['name'] == 'Defiant');
7122+
$this->assertTrue($res && (count($res) == 2 || count($res) == 3));
7123+
$this->assertTrue(isset($res[1]['1424-74205']['name']) &&
7124+
$res[1]['1424-74205']['name'] == 'Defiant');
71147125

71157126
// Now the 'Sisko' consumer should own the message
71167127
$pending = $this->redis->xPending('ships', 'combatants');
@@ -7640,9 +7651,12 @@ public function testCommand()
76407651
$commands = $this->redis->command();
76417652
$this->assertTrue(is_array($commands));
76427653
$this->assertEquals(count($commands), $this->redis->command('count'));
7643-
$infos = $this->redis->command('info');
7644-
$this->assertTrue(is_array($infos));
7645-
$this->assertEquals(count($infos), count($commands));
7654+
7655+
if (!$this->is_keydb) {
7656+
$infos = $this->redis->command('info');
7657+
$this->assertTrue(is_array($infos));
7658+
$this->assertEquals(count($infos), count($commands));
7659+
}
76467660

76477661
if (version_compare($this->version, '7.0') >= 0) {
76487662
$docs = $this->redis->command('docs');

tests/TestSuite.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class TestSuite
1515

1616
/* Redis server version */
1717
protected $version;
18+
protected $is_keydb;
1819

1920
private static $_boo_colorize = false;
2021

tests/make-cluster.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ BASEDIR=`pwd`
1313
NODEDIR=$BASEDIR/nodes
1414
MAPFILE=$NODEDIR/nodemap
1515

16+
REDIS_BINARY=${REDIS_BINARY:-redis-server}
17+
1618
# Host, nodes, replicas, ports, etc. Change if you want different values
1719
HOST="127.0.0.1"
1820
NOASK=0
@@ -43,7 +45,7 @@ spawnNode() {
4345
fi
4446

4547
# Attempt to spawn the node
46-
verboseRun redis-server --cluster-enabled yes --dir $NODEDIR --port $PORT \
48+
verboseRun "$REDIS_BINARY" --cluster-enabled yes --dir $NODEDIR --port $PORT \
4749
--cluster-config-file node-$PORT.conf --daemonize yes --save \'\' \
4850
--bind $HOST --dbfilename node-$PORT.rdb $ACLARG
4951

@@ -167,8 +169,7 @@ printUsage() {
167169
exit 0
168170
}
169171

170-
# We need redis-server
171-
checkExe redis-server
172+
checkExe "$REDIS_BINARY"
172173

173174
while getopts "u:p:a:hy" OPT; do
174175
case $OPT in

0 commit comments

Comments
 (0)