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

Skip to content

Commit b665925

Browse files
JakubOnderkamichael-grunder
authored andcommitted
Use smart str for constructing pipeline cmd
1 parent 6097e7b commit b665925

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

common.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,7 @@ typedef enum {
177177
#define IS_PIPELINE(redis_sock) (redis_sock->mode & PIPELINE)
178178

179179
#define PIPELINE_ENQUEUE_COMMAND(cmd, cmd_len) do { \
180-
if (redis_sock->pipeline_cmd == NULL) { \
181-
redis_sock->pipeline_cmd = zend_string_init(cmd, cmd_len, 0); \
182-
} else { \
183-
size_t pipeline_len = ZSTR_LEN(redis_sock->pipeline_cmd); \
184-
redis_sock->pipeline_cmd = zend_string_realloc(redis_sock->pipeline_cmd, pipeline_len + cmd_len, 0); \
185-
memcpy(&ZSTR_VAL(redis_sock->pipeline_cmd)[pipeline_len], cmd, cmd_len); \
186-
} \
180+
smart_str_appendl(&redis_sock->pipeline_cmd, cmd, cmd_len); \
187181
} while (0)
188182

189183
#define REDIS_SAVE_CALLBACK(callback, closure_context) do { \
@@ -324,7 +318,7 @@ typedef struct {
324318
struct fold_item *head;
325319
struct fold_item *current;
326320

327-
zend_string *pipeline_cmd;
321+
smart_str pipeline_cmd;
328322

329323
zend_string *err;
330324

library.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3605,9 +3605,7 @@ PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock)
36053605
if (redis_sock->prefix) {
36063606
zend_string_release(redis_sock->prefix);
36073607
}
3608-
if (redis_sock->pipeline_cmd) {
3609-
zend_string_release(redis_sock->pipeline_cmd);
3610-
}
3608+
smart_str_free(&redis_sock->pipeline_cmd);
36113609
if (redis_sock->err) {
36123610
zend_string_release(redis_sock->err);
36133611
}

redis.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,10 +1948,7 @@ PHP_METHOD(Redis, discard)
19481948

19491949
if (IS_PIPELINE(redis_sock)) {
19501950
ret = SUCCESS;
1951-
if (redis_sock->pipeline_cmd) {
1952-
zend_string_release(redis_sock->pipeline_cmd);
1953-
redis_sock->pipeline_cmd = NULL;
1954-
}
1951+
smart_str_free(&redis_sock->pipeline_cmd);
19551952
} else if (IS_MULTI(redis_sock)) {
19561953
ret = redis_send_discard(redis_sock);
19571954
}
@@ -2022,12 +2019,12 @@ PHP_METHOD(Redis, exec)
20222019
}
20232020

20242021
if (IS_PIPELINE(redis_sock)) {
2025-
if (redis_sock->pipeline_cmd == NULL) {
2022+
if (smart_str_get_len(&redis_sock->pipeline_cmd) == 0) {
20262023
/* Empty array when no command was run. */
20272024
array_init(&z_ret);
20282025
} else {
2029-
if (redis_sock_write(redis_sock, ZSTR_VAL(redis_sock->pipeline_cmd),
2030-
ZSTR_LEN(redis_sock->pipeline_cmd)) < 0) {
2026+
if (redis_sock_write(redis_sock, ZSTR_VAL(redis_sock->pipeline_cmd.s),
2027+
ZSTR_LEN(redis_sock->pipeline_cmd.s)) < 0) {
20312028
ZVAL_FALSE(&z_ret);
20322029
} else {
20332030
array_init(&z_ret);
@@ -2037,8 +2034,7 @@ PHP_METHOD(Redis, exec)
20372034
ZVAL_FALSE(&z_ret);
20382035
}
20392036
}
2040-
zend_string_release(redis_sock->pipeline_cmd);
2041-
redis_sock->pipeline_cmd = NULL;
2037+
smart_str_free(&redis_sock->pipeline_cmd);
20422038
}
20432039
free_reply_callbacks(redis_sock);
20442040
REDIS_DISABLE_MODE(redis_sock, PIPELINE);

0 commit comments

Comments
 (0)