Skip to content

Commit f84f3de

Browse files
authored
Merge pull request #43 from plainbanana/use-redisClusterAsyncCommandArgvToNode
use redisClusterAsyncCommandArgvToNode for refactoring
2 parents 310923b + 1dcac82 commit f84f3de

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

Diff for: src/Fast.xs

+8-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
} /* extern "C" */
1818
#endif
1919

20+
#define NEED_newRV_noinc
2021
#define NEED_my_strlcpy
2122
#include "ppport.h"
2223

@@ -214,14 +215,11 @@ cluster_node *get_node_by_random(pTHX_ Redis__Cluster__Fast self) {
214215

215216
void Redis__Cluster__Fast_run_cmd(pTHX_ Redis__Cluster__Fast self, int argc, const char **argv, size_t *argvlen,
216217
cmd_reply_context_t *reply_t) {
217-
char *cmd;
218-
int len, status, event_loop_error;
218+
int status, event_loop_error;
219219
pid_t current_pid;
220220

221221
DEBUG_MSG("start: %s", *argv);
222222

223-
cmd = NULL;
224-
225223
reply_t->done = 0;
226224
reply_t->self = (void *) self;
227225
reply_t->result = NULL;
@@ -232,20 +230,13 @@ void Redis__Cluster__Fast_run_cmd(pTHX_ Redis__Cluster__Fast self, int argc, con
232230
DEBUG_MSG("%s", "pid changed");
233231
if (event_reinit(self->cluster_event_base) != 0) {
234232
reply_t->error = newSVpvf("%s", "event reinit failed");
235-
goto end;
233+
return;
236234
}
237235
redisClusterAsyncDisconnect(self->acc);
238236
self->pid = current_pid;
239237
}
240238

241-
len = (int) redisFormatCommandArgv(&cmd, argc, argv, argvlen);
242-
if (len == -1) {
243-
DEBUG_MSG("error: err=%s", "memory error");
244-
reply_t->error = newSVpvf("%s", "memory allocation error");
245-
goto end;
246-
}
247-
248-
status = redisClusterAsyncFormattedCommand(self->acc, replyCallback, reply_t, cmd, len);
239+
status = redisClusterAsyncCommandArgv(self->acc, replyCallback, reply_t, argc, argv, argvlen);
249240
if (status != REDIS_OK) {
250241
if (self->acc->err == REDIS_ERR_OTHER &&
251242
strcmp(self->acc->errstr, "No keys in command(must have keys for redis cluster mode)") == 0) {
@@ -258,19 +249,19 @@ void Redis__Cluster__Fast_run_cmd(pTHX_ Redis__Cluster__Fast self, int argc, con
258249
node = get_node_by_random(aTHX_ self);
259250
if (node == NULL) {
260251
reply_t->error = newSVpvf("%s", "No node found");
261-
goto end;
252+
return;
262253
}
263254

264-
status = redisClusterAsyncFormattedCommandToNode(self->acc, node, replyCallback, reply_t, cmd, len);
255+
status = redisClusterAsyncCommandArgvToNode(self->acc, node, replyCallback, reply_t, argc, argv, argvlen);
265256
if (status != REDIS_OK) {
266257
DEBUG_MSG("error: err=%d errstr=%s", self->acc->err, self->acc->errstr);
267258
reply_t->error = newSVpvf("%s", self->acc->errstr);
268-
goto end;
259+
return;
269260
}
270261
} else {
271262
DEBUG_MSG("error: err=%d errstr=%s", self->acc->err, self->acc->errstr);
272263
reply_t->error = newSVpvf("%s", self->acc->errstr);
273-
goto end;
264+
return;
274265
}
275266
}
276267

@@ -282,10 +273,6 @@ void Redis__Cluster__Fast_run_cmd(pTHX_ Redis__Cluster__Fast self, int argc, con
282273
break;
283274
}
284275
}
285-
286-
end:
287-
if (cmd != NULL)
288-
hi_free(cmd);
289276
}
290277

291278
MODULE = Redis::Cluster::Fast PACKAGE = Redis::Cluster::Fast

0 commit comments

Comments
 (0)