Skip to content

Commit

Permalink
Fix KEEPTTL option in EXSET can't be propagated to replica (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
VonAlex authored Nov 13, 2024
1 parent f91b62a commit 2ffe26c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tairstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int TairStringTypeSet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
}

/* Rewrite relative value to absolute value. */
size_t vlen = 4, VSIZE_MAX = 8;
size_t vlen = 4, VSIZE_MAX = 9;
RedisModuleString **v = NULL;
v = RedisModule_Calloc(sizeof(RedisModuleString *), VSIZE_MAX);
v[0] = RedisModule_CreateStringFromString(ctx, argv[1]);
Expand All @@ -340,6 +340,9 @@ int TairStringTypeSet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
v[vlen + 1] = RedisModule_CreateStringFromLongLong(ctx, (long long)tair_string_obj->flags);
vlen += 2;
}
if (ex_flags&TAIR_STRING_SET_KEEPTTL) {
v[vlen++] = RedisModule_CreateString(ctx, "KEEPTTL", 7);
}
RedisModule_Replicate(ctx, "EXSET", "v", v, vlen);
RedisModule_Free(v);

Expand Down
45 changes: 45 additions & 0 deletions tests/tairstring.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,51 @@ start_server {tags {"ex_string"} overrides {bind 0.0.0.0}} {
}
}

start_server {tags {"ex_string_repl"}} {
r module load $testmodule
r set myexkey foo

start_server {} {
r module load $testmodule

test {Second server should have role master at first} {
s role
} {master}

test {SLAVEOF should start with link status "down"} {
r slaveof [srv -1 host] [srv -1 port]
s master_link_status
} {down}

wait_for_sync r
test {The link status should be up} {
s master_link_status
} {up}

test {Sync should have transferred keys from master} {
r get myexkey
} {foo}

test {KEEPTTL option should retain in replcia} {
r -1 del myexkey
assert {[r -1 exset myexkey foo ex 100] eq {OK}}
set mttl [r -1 ttl myexkey]
assert {$mttl != -1 && $mttl != -2}
# Wait propagation
after 1000
set sttl [r ttl myexkey]
assert {$sttl != -1 && $sttl != -2}

assert {[r -1 exset myexkey foo2 keepttl] eq {OK}}
set mttl [r -1 ttl myexkey]
assert {$mttl != -1 && $mttl != -2}
after 2000
set sttl [r ttl myexkey]
assert {$sttl != -1 && $sttl != -2}
}
}
}

start_server {tags {"exhash repl"} overrides {bind 0.0.0.0}} {
r module load $testmodule
set slave [srv 0 client]
Expand Down

0 comments on commit 2ffe26c

Please sign in to comment.