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

Skip to content

Commit 0b97ec3

Browse files
Update STREAM API to handle STATUS -> BULK reply change
Right before Redis 5.0 was released, the api was changed to send message ids as BULK instead of STATUS replies.
1 parent 7e3362c commit 0b97ec3

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

library.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,17 +1269,18 @@ redis_read_stream_messages(RedisSock *redis_sock, int count, zval *z_ret
12691269
{
12701270
zval zv, *z_message = &zv;
12711271
int i, mhdr, fields;
1272-
char id[1024];
1273-
size_t idlen;
1272+
char *id = NULL;
1273+
int idlen;
12741274

12751275
/* Iterate over each message */
12761276
for (i = 0; i < count; i++) {
12771277
/* Consume inner multi-bulk header, message ID itself and finaly
12781278
* the multi-bulk header for field and values */
12791279
if ((read_mbulk_header(redis_sock, &mhdr TSRMLS_CC) < 0 || mhdr != 2) ||
1280-
redis_sock_read_single_line(redis_sock, id, sizeof(id), &idlen, 0 TSRMLS_CC) < 0 ||
1280+
((id = redis_sock_read(redis_sock, &idlen TSRMLS_CC)) == NULL) ||
12811281
(read_mbulk_header(redis_sock, &fields TSRMLS_CC) < 0 || fields % 2 != 0))
12821282
{
1283+
if (id) efree(id);
12831284
return -1;
12841285
}
12851286

@@ -1289,6 +1290,7 @@ redis_read_stream_messages(RedisSock *redis_sock, int count, zval *z_ret
12891290
redis_mbulk_reply_loop(redis_sock, z_message, fields, UNSERIALIZE_VALS TSRMLS_CC);
12901291
array_zip_values_and_scores(redis_sock, z_message, SCORE_DECODE_NONE TSRMLS_CC);
12911292
add_assoc_zval_ex(z_ret, id, idlen, z_message);
1293+
efree(id);
12921294
}
12931295

12941296
return 0;
@@ -1404,31 +1406,38 @@ PHP_REDIS_API int
14041406
redis_read_xclaim_response(RedisSock *redis_sock, int count, zval *rv TSRMLS_DC) {
14051407
zval zv, *z_msg = &zv;
14061408
REDIS_REPLY_TYPE type;
1407-
char id[1024];
1408-
int i, fields;
1409+
char *id;
1410+
int i, fields, idlen;
14091411
long li;
1410-
size_t idlen;
14111412

14121413
for (i = 0; i < count; i++) {
14131414
/* Consume inner reply type */
14141415
if (redis_read_reply_type(redis_sock, &type, &li TSRMLS_CC) < 0 ||
1415-
(type != TYPE_LINE && type != TYPE_MULTIBULK)) return -1;
1416+
(type != TYPE_BULK && type != TYPE_MULTIBULK) ||
1417+
(type == TYPE_BULK && li <= 0)) return -1;
14161418

1417-
if (type == TYPE_LINE) {
1418-
/* JUSTID variant */
1419-
if (redis_sock_gets(redis_sock, id, sizeof(id), &idlen TSRMLS_CC) < 0)
1419+
/* TYPE_BULK is the JUSTID variant, otherwise it's standard xclaim response */
1420+
if (type == TYPE_BULK) {
1421+
if ((id = redis_sock_read_bulk_reply(redis_sock, (size_t)li TSRMLS_CC)) == NULL)
14201422
return -1;
1421-
add_next_index_stringl(rv, id, idlen);
1423+
1424+
add_next_index_stringl(rv, id, li);
1425+
efree(id);
14221426
} else {
1423-
if (li != 2 || redis_sock_read_single_line(redis_sock, id, sizeof(id), &idlen, 0 TSRMLS_CC) < 0 ||
1424-
(read_mbulk_header(redis_sock, &fields TSRMLS_CC) < 0 || fields % 2 != 0)) return -1;
1427+
if ((li != 2 || (id = redis_sock_read(redis_sock, &idlen TSRMLS_CC)) == NULL) ||
1428+
(read_mbulk_header(redis_sock, &fields TSRMLS_CC) < 0 || fields % 2 != 0))
1429+
{
1430+
if (id) efree(id);
1431+
return -1;
1432+
}
14251433

14261434
REDIS_MAKE_STD_ZVAL(z_msg);
14271435
array_init(z_msg);
14281436

14291437
redis_mbulk_reply_loop(redis_sock, z_msg, fields, UNSERIALIZE_VALS TSRMLS_CC);
14301438
array_zip_values_and_scores(redis_sock, z_msg, SCORE_DECODE_NONE TSRMLS_CC);
14311439
add_assoc_zval_ex(rv, id, idlen, z_msg);
1440+
efree(id);
14321441
}
14331442
}
14341443

redis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,7 @@ PHP_METHOD(Redis, xack) {
35923592
}
35933593

35943594
PHP_METHOD(Redis, xadd) {
3595-
REDIS_PROCESS_CMD(xadd, redis_single_line_reply);
3595+
REDIS_PROCESS_CMD(xadd, redis_read_variant_reply);
35963596
}
35973597

35983598
PHP_METHOD(Redis, xclaim) {

redis_cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2983,7 +2983,7 @@ PHP_METHOD(RedisCluster, xack) {
29832983

29842984
/* {{{ proto string RedisCluster::xadd(string key, string id, array field_values) }}} */
29852985
PHP_METHOD(RedisCluster, xadd) {
2986-
CLUSTER_PROCESS_CMD(xadd, cluster_single_line_resp, 0);
2986+
CLUSTER_PROCESS_CMD(xadd, cluster_bulk_raw_resp, 0);
29872987
}
29882988

29892989
/* {{{ proto array RedisCluster::xclaim(string key, string group, string consumer,

0 commit comments

Comments
 (0)