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

Skip to content

Commit 15995c0

Browse files
Xgroup updates (#1499)
Adds support for XGROUP CREATE ... MKSTREAM, and support at all for XGROUP DESTROY.
1 parent 3aad9e6 commit 15995c0

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

redis_commands.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3722,35 +3722,45 @@ int redis_xclaim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
37223722
}
37233723

37243724
/* XGROUP HELP
3725+
* XGROUP CREATE key groupname id [MKSTREAM]
37253726
* XGROUP SETID key group id
3726-
* XGROUP DELGROUP key groupname
3727-
* XGROUP CREATE key groupname id
3727+
* XGROUP DESTROY key groupname
37283728
* XGROUP DELCONSUMER key groupname consumername */
37293729
int redis_xgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
37303730
char **cmd, int *cmd_len, short *slot, void **ctx)
37313731
{
37323732
char *op, *key = NULL, *arg1 = NULL, *arg2 = NULL;
37333733
strlen_t oplen, keylen, arg1len, arg2len;
3734+
zend_bool mkstream = 0;
37343735
int argc = ZEND_NUM_ARGS();
37353736

3736-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssss", &op, &oplen,
3737-
&key, &keylen, &arg1, &arg1len, &arg2, &arg2len)
3738-
== FAILURE)
3737+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sssb", &op, &oplen,
3738+
&key, &keylen, &arg1, &arg1len, &arg2, &arg2len,
3739+
&mkstream) == FAILURE)
37393740
{
37403741
return FAILURE;
37413742
}
37423743

37433744
if (argc == 1 && oplen == 4 && !strncasecmp(op, "HELP", 4)) {
37443745
*cmd_len = REDIS_CMD_SPPRINTF(cmd, "XGROUP", "s", "HELP", 4);
37453746
return SUCCESS;
3747+
} else if (argc >= 4 && (oplen == 6 && !strncasecmp(op, "CREATE", 6))) {
3748+
if (mkstream) {
3749+
*cmd_len = REDIS_CMD_SPPRINTF(cmd, "XGROUP", "sksss", op, oplen, key, keylen,
3750+
arg1, arg1len, arg2, arg2len, "MKSTREAM",
3751+
sizeof("MKSTREAM") - 1);
3752+
} else {
3753+
*cmd_len = REDIS_CMD_SPPRINTF(cmd, "XGROUP", "skss", op, oplen, key, keylen,
3754+
arg1, arg1len, arg2, arg2len);
3755+
}
3756+
return SUCCESS;
37463757
} else if (argc == 4 && ((oplen == 5 && !strncasecmp(op, "SETID", 5)) ||
3747-
(oplen == 6 && !strncasecmp(op, "CREATE", 6)) ||
37483758
(oplen == 11 && !strncasecmp(op, "DELCONSUMER", 11))))
37493759
{
37503760
*cmd_len = REDIS_CMD_SPPRINTF(cmd, "XGROUP", "skss", op, oplen, key, keylen,
37513761
arg1, arg1len, arg2, arg2len);
37523762
return SUCCESS;
3753-
} else if (argc == 3 && ((oplen == 7 && !strncasecmp(op, "DELGROUP", 7)))) {
3763+
} else if (argc == 3 && ((oplen == 7 && !strncasecmp(op, "DESTROY", 7)))) {
37543764
*cmd_len = REDIS_CMD_SPPRINTF(cmd, "XGROUP", "sks", op, oplen, key,
37553765
keylen, arg1, arg1len);
37563766
return SUCCESS;

tests/RedisTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5384,6 +5384,15 @@ public function testXGroup() {
53845384
if (!$this->minVersionCheck("5.0"))
53855385
return $this->markTestSkipped();
53865386

5387+
/* CREATE MKSTREAM */
5388+
$str_key = 's:' . uniqid();
5389+
$this->assertFalse($this->redis->xGroup('CREATE', $str_key, 'g0', 0));
5390+
$this->assertTrue($this->redis->xGroup('CREATE', $str_key, 'g1', 0, true));
5391+
5392+
/* XGROUP DESTROY */
5393+
$this->assertEquals($this->redis->xGroup('DESTROY', $str_key, 'g1'), 1);
5394+
5395+
/* Populate some entries in stream 's' */
53875396
$this->addStreamEntries('s', 2);
53885397

53895398
/* CREATE */
@@ -5399,8 +5408,6 @@ public function testXGroup() {
53995408
$this->assertFalse($this->redis->xGroup('SETID', 's', 'mygroup', 'BAD_ID'));
54005409

54015410
$this->assertEquals($this->redis->xGroup('DELCONSUMER', 's', 'mygroup', 'myconsumer'),0);
5402-
5403-
/* DELGROUP not yet implemented in Redis */
54045411
}
54055412

54065413
public function testXAck() {

0 commit comments

Comments
 (0)