add method to get client args as list

Former-commit-id: 576b8cd2153c48c0ca4dfc9ed7d12f77d6f76f7e
This commit is contained in:
malavan 2021-08-30 21:09:22 +00:00
parent 0baa543819
commit 7ee39396c0
3 changed files with 21 additions and 19 deletions

View File

@ -4952,6 +4952,20 @@ bool client::postFunction(std::function<void(client *)> fn, bool fLock) {
}, fLock) == AE_OK;
}
list *client::argsAsList() {
list *args = listCreate();
for (int j = 1; j < this->argc; j++) {
incrRefCount(this->argv[j]);
listAddNodeTail(args, this->argv[j]);
}
return args;
}
void client::freeArgList(list* args) {
listSetFreeMethod(args,decrRefCountVoid);
listRelease(args);
}
bool client::asyncCommand(std::function<void *(const redisDbPersistentDataSnapshot *)> &&preFn,
std::function<void(const redisDbPersistentDataSnapshot *, void *)> &&mainFn,
std::function<void(const redisDbPersistentDataSnapshot *, void *)> &&postFn)

View File

@ -1661,6 +1661,8 @@ struct client {
// post a function from a non-client thread to run on its client thread
bool postFunction(std::function<void(client *)> fn, bool fLock = true);
size_t argv_len_sum() const;
list *argsAsList();
void freeArgList(list* args);
bool asyncCommand(std::function<void *(const redisDbPersistentDataSnapshot *)> &&preFn,
std::function<void(const redisDbPersistentDataSnapshot *, void *)> &&mainFn,
std::function<void(const redisDbPersistentDataSnapshot *, void *)> &&postFn);

View File

@ -524,15 +524,6 @@ void getrangeCommand(client *c) {
}
}
list *mgetKeysFromClient(client *c) {
list *keys = listCreate();
for (int j = 1; j < c->argc; j++) {
incrRefCount(c->argv[j]);
listAddNodeTail(keys, c->argv[j]);
}
return keys;
}
void mgetCore(client *c, list *keys, const redisDbPersistentDataSnapshot *snapshot = nullptr) {
addReplyArrayLen(c,listLength(keys));
listNode *ln = listFirst(keys);
@ -551,32 +542,27 @@ void mgetCore(client *c, list *keys, const redisDbPersistentDataSnapshot *snapsh
}
}
void mgetClearKeys(list *keys) {
listSetFreeMethod(keys,decrRefCountVoid);
listRelease(keys);
}
void mgetCommand(client *c) {
// Do async version for large number of arguments
if (c->argc > 100) {
if (c->asyncCommand(
[c] (const redisDbPersistentDataSnapshot *snapshot) {
return mgetKeysFromClient(c);
return c->argsAsList();
},
[c] (const redisDbPersistentDataSnapshot *snapshot, void *keys) {
mgetCore(c, (list *)keys, snapshot);
},
[] (const redisDbPersistentDataSnapshot *snapshot, void *keys) {
mgetClearKeys((list *)keys);
[c] (const redisDbPersistentDataSnapshot *snapshot, void *keys) {
c->freeArgList((list *)keys);
}
)) {
return;
}
}
list *keys = mgetKeysFromClient(c);
list *keys = c->argsAsList();
mgetCore(c, keys);
mgetClearKeys(keys);
c->freeArgList(keys);
}
void msetGenericCommand(client *c, int nx) {