Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] support "move" cmd #295

Open
wants to merge 1 commit into
base: xredis_2_ror
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ctrip_swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ int getKeyRequestsBitField(int dbid, struct redisCommand *cmd, robj **argv, int

int getKeyRequestsMemory(int dbid, struct redisCommand *cmd, robj **argv, int argc, struct getKeyRequestsResult *result);

int getKeyRequestsMemory(int dbid, struct redisCommand *cmd, robj **argv, int argc, struct getKeyRequestsResult *result);
int getKeyRequestsMove(int dbid, struct redisCommand *cmd, robj **argv, int argc, struct getKeyRequestsResult *result);

#define GET_KEYREQUESTS_RESULT_INIT { {{0}}, NULL, NULL, 0, MAX_KEYREQUESTS_BUFFER}

Expand Down
7 changes: 7 additions & 0 deletions src/ctrip_swap_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,13 @@ int getKeyRequestsMemory(int dbid, struct redisCommand *cmd, robj **argv,
}
}

int getKeyRequestsMove(int dbid, struct redisCommand *cmd, robj **argv,
int argc, struct getKeyRequestsResult *result) {
UNUSED(argc);
getKeyRequestsSingleKey(result,argv[1],cmd->intention,cmd->intention_flags,cmd->flags | CMD_SWAP_DATATYPE_KEYSPACE,dbid);
return 0;
}

#ifdef REDIS_TEST

void rewriteResetClientCommandCString(client *c, int argc, ...) {
Expand Down
12 changes: 10 additions & 2 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,12 +1318,20 @@ void moveCommand(client *c) {
}
expire = getExpire(c->db,c->argv[1]);

/* Return zero if the key already exists in the target DB */
if (lookupKeyWrite(dst,c->argv[1]) != NULL) {
/* Return zero if the key or meta already exist in the target DB */
if (lookupKeyWrite(dst,c->argv[1]) != NULL || lookupMeta(dst, c->argv[1]) != NULL) {
addReply(c,shared.czero);
return;
}

dbAdd(dst,c->argv[1],o);

objectMeta *om = lookupMeta(src, c->argv[1]);
if (om != NULL) {
objectMeta *dst_om = dupObjectMeta(om);
dbAddMeta(dst,c->argv[1],dst_om);
}

if (expire != -1) setExpire(c,dst,c->argv[1],expire);
incrRefCount(o);

Expand Down
4 changes: 2 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ struct redisCommand redisCommandTable[] = {
0,NULL,getKeyRequestsGlobal,SWAP_NOP,0,0,0,0,0,0,0},

{"move",moveCommand,3,
"write fast @keyspace",
0,NULL,NULL,SWAP_NOP,0,1,1,1,0,0,0},
"write fast @keyspace @swap_keyspace",
0,NULL,getKeyRequestsMove,SWAP_IN,SWAP_IN_DEL,1,1,1,0,0,0},

{"copy",copyCommand,-3,
"write use-memory @keyspace @swap_keyspace",
Expand Down
20 changes: 20 additions & 0 deletions tests/swap/unit/bitmap.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,26 @@ start_server {
r flushdb
}

test {bitmap move} {
r flushdb
build_cold_data mybitmap1
build_pure_hot_data mybitmap2

r move mybitmap1 10
r move mybitmap2 10
assert_equal [r dbsize] 0

r select 10
assert_equal [r dbsize] 2
assert [bitmap_object_is_pure_hot r mybitmap1]
assert [bitmap_object_is_pure_hot r mybitmap2]

check_mybitmap_is_right mybitmap1 $notextend
check_mybitmap_is_right mybitmap2 $notextend

r flushdb
}

}


Expand Down
Loading