summaryrefslogtreecommitdiff
path: root/src/db.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2011-03-23 18:09:17 +0100
committerantirez <antirez@gmail.com>2011-03-23 18:09:17 +0100
commit9791f0f8ceb18e2e3c297a8c479307b7af0f9830 (patch)
treea9efb22e822b995c7a65ab88c43ca1e5ddf8eee9 /src/db.c
parent03af999cb0befed9d2556c2df1eb0511de2d96d2 (diff)
downloadredis-9791f0f8ceb18e2e3c297a8c479307b7af0f9830.tar.gz
new preloading implemented, still EXEC not handled correctly, everything to test
Diffstat (limited to 'src/db.c')
-rw-r--r--src/db.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/db.c b/src/db.c
index 9daa5ddbd..9bc299ca1 100644
--- a/src/db.c
+++ b/src/db.c
@@ -616,3 +616,75 @@ void persistCommand(redisClient *c) {
}
}
}
+
+/* -----------------------------------------------------------------------------
+ * API to get key arguments from commands
+ * ---------------------------------------------------------------------------*/
+
+int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, int *numkeys) {
+ int j, i = 0, last, *keys;
+ REDIS_NOTUSED(argv);
+
+ if (cmd->firstkey == 0) {
+ *numkeys = 0;
+ return NULL;
+ }
+ last = cmd->lastkey;
+ if (last < 0) last = argc+last;
+ keys = zmalloc(sizeof(int)*((last - cmd->firstkey)+1));
+ for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
+ redisAssert(j < argc);
+ keys[i] = j;
+ }
+ return keys;
+}
+
+int *getKeysFromCommand(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) {
+ if (cmd->getkeys_proc) {
+ return cmd->getkeys_proc(cmd,argv,argc,numkeys,flags);
+ } else {
+ return getKeysUsingCommandTable(cmd,argv,argc,numkeys);
+ }
+}
+
+void getKeysFreeResult(int *result) {
+ zfree(result);
+}
+
+int *noPreloadGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) {
+ if (flags & REDIS_GETKEYS_PRELOAD) {
+ *numkeys = 0;
+ return NULL;
+ } else {
+ return getKeysUsingCommandTable(cmd,argv,argc,numkeys);
+ }
+}
+
+int *renameGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) {
+ if (flags & REDIS_GETKEYS_PRELOAD) {
+ int *keys = zmalloc(sizeof(int));
+ *numkeys = 1;
+ keys[0] = 1;
+ return NULL;
+ } else {
+ return getKeysUsingCommandTable(cmd,argv,argc,numkeys);
+ }
+}
+
+int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) {
+ int i, num, *keys;
+ REDIS_NOTUSED(cmd);
+ REDIS_NOTUSED(flags);
+
+ num = atoi(argv[2]->ptr);
+ /* Sanity check. Don't return any key if the command is going to
+ * reply with syntax error. */
+ if (num > (argc-3)) {
+ *numkeys = 0;
+ return NULL;
+ }
+ keys = zmalloc(num);
+ for (i = 0; i < num; i++) keys[i] = 3+i;
+ *numkeys = num;
+ return keys;
+}