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
This commit is contained in:
michael-grunder
2024-03-21 14:34:33 -07:00
committed by Michael Grunder
parent c7a73abbd5
commit d9c48b788d
5 changed files with 38 additions and 18 deletions

View File

@@ -2310,9 +2310,9 @@ redis_read_xclaim_reply(RedisSock *redis_sock, int count, int is_xautoclaim, zva
zval z_msgs = {0};
char *id = NULL;
long id_len = 0;
int messages;
int messages = 0;
ZEND_ASSERT(!is_xautoclaim || count == 3);
ZEND_ASSERT(!is_xautoclaim || (count == 2 || count == 3));
ZVAL_UNDEF(rv);
@@ -2338,15 +2338,18 @@ redis_read_xclaim_reply(RedisSock *redis_sock, int count, int is_xautoclaim, zva
if (is_xautoclaim) {
zval z_deleted = {0};
if (redis_sock_read_multibulk_reply_zval(redis_sock, &z_deleted) == NULL)
if (count == 3 && redis_sock_read_multibulk_reply_zval(redis_sock, &z_deleted) == NULL)
goto failure;
array_init(rv);
// Package up ID, message, and deleted messages in our reply
// Package up ID and message
add_next_index_stringl(rv, id, id_len);
add_next_index_zval(rv, &z_msgs);
add_next_index_zval(rv, &z_deleted);
// Add deleted messages if they exist
if (count == 3)
add_next_index_zval(rv, &z_deleted);
efree(id);
} else {

View File

@@ -94,6 +94,7 @@ class Redis_Cluster_Test extends Redis_Test {
$this->redis = $this->newInstance();
$info = $this->redis->info(uniqid());
$this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0');
$this->is_keydb = $this->redis->info('keydb') !== false;
}
/* Override newInstance as we want a RedisCluster object */

View File

@@ -75,6 +75,8 @@ class Redis_Test extends TestSuite
$this->redis = $this->newInstance();
$info = $this->redis->info();
$this->version = (isset($info['redis_version'])?$info['redis_version']:'0.0.0');
$this->is_keydb = $this->redis->info('keydb') !== false;
}
protected function minVersionCheck($version) {
@@ -265,9 +267,11 @@ class Redis_Test extends TestSuite
$this->redis->set('bitcountkey', hex2bin('10eb8939e68bfdb640260f0629f3'));
$this->assertEquals(1, $this->redis->bitcount('bitcountkey', 8, 8, false));
/* key, start, end, BIT */
$this->redis->set('bitcountkey', hex2bin('cd0e4c80f9e4590d888a10'));
$this->assertEquals(5, $this->redis->bitcount('bitcountkey', 0, 9, true));
if ( ! $this->is_keydb) {
/* key, start, end, BIT */
$this->redis->set('bitcountkey', hex2bin('cd0e4c80f9e4590d888a10'));
$this->assertEquals(5, $this->redis->bitcount('bitcountkey', 0, 9, true));
}
}
public function testBitop() {
@@ -331,6 +335,8 @@ class Redis_Test extends TestSuite
}
public function testLcs() {
if ( ! $this->minVersionCheck('7.0.0') || $this->is_keydb)
$this->markTestSkipped();
$key1 = '{lcs}1'; $key2 = '{lcs}2';
$this->assertTrue($this->redis->set($key1, '12244447777777'));
@@ -7094,7 +7100,12 @@ return;
// Test an empty xautoclaim reply
$res = $this->redis->xAutoClaim('ships', 'combatants', 'Sisko', 0, '0-0');
$this->assertEquals(['0-0', [], []], $res);
$this->assertTrue(is_array($res) && (count($res) == 2 || count($res) == 3));
if (count($res) == 2) {
$this->assertEquals(['0-0', []], $res);
} else {
$this->assertEquals(['0-0', [], []], $res);
}
$this->redis->xAdd('ships', '1424-74205', ['name' => 'Defiant']);
@@ -7108,9 +7119,9 @@ return;
// Assume control of the pending message with a different consumer.
$res = $this->redis->xAutoClaim('ships', 'combatants', 'Sisko', 0, '0-0');
$this->assertTrue($res && count($res) == 3 && $res[0] == '0-0' &&
isset($res[1]['1424-74205']['name']) &&
$res[1]['1424-74205']['name'] == 'Defiant');
$this->assertTrue($res && (count($res) == 2 || count($res) == 3));
$this->assertTrue(isset($res[1]['1424-74205']['name']) &&
$res[1]['1424-74205']['name'] == 'Defiant');
// Now the 'Sisko' consumer should own the message
$pending = $this->redis->xPending('ships', 'combatants');
@@ -7640,9 +7651,12 @@ return;
$commands = $this->redis->command();
$this->assertTrue(is_array($commands));
$this->assertEquals(count($commands), $this->redis->command('count'));
$infos = $this->redis->command('info');
$this->assertTrue(is_array($infos));
$this->assertEquals(count($infos), count($commands));
if (!$this->is_keydb) {
$infos = $this->redis->command('info');
$this->assertTrue(is_array($infos));
$this->assertEquals(count($infos), count($commands));
}
if (version_compare($this->version, '7.0') >= 0) {
$docs = $this->redis->command('docs');

View File

@@ -15,6 +15,7 @@ class TestSuite
/* Redis server version */
protected $version;
protected $is_keydb;
private static $_boo_colorize = false;

View File

@@ -13,6 +13,8 @@ BASEDIR=`pwd`
NODEDIR=$BASEDIR/nodes
MAPFILE=$NODEDIR/nodemap
REDIS_BINARY=${REDIS_BINARY:-redis-server}
# Host, nodes, replicas, ports, etc. Change if you want different values
HOST="127.0.0.1"
NOASK=0
@@ -43,7 +45,7 @@ spawnNode() {
fi
# Attempt to spawn the node
verboseRun redis-server --cluster-enabled yes --dir $NODEDIR --port $PORT \
verboseRun "$REDIS_BINARY" --cluster-enabled yes --dir $NODEDIR --port $PORT \
--cluster-config-file node-$PORT.conf --daemonize yes --save \'\' \
--bind $HOST --dbfilename node-$PORT.rdb $ACLARG
@@ -167,8 +169,7 @@ printUsage() {
exit 0
}
# We need redis-server
checkExe redis-server
checkExe "$REDIS_BINARY"
while getopts "u:p:a:hy" OPT; do
case $OPT in