Skip to content

Commit c7f5eeb

Browse files
author
Emmanuel Merali
committed
Added key expiry on rehash
Added a call to expire when migrating a key that has an TTL other than -1
1 parent 31663d4 commit c7f5eeb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

redis_array_impl.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,41 @@ ra_move_list(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC) {
976976
return ra_move_collection(key, key_len, z_from, z_to, 3, cmd_list, 1, cmd_add TSRMLS_CC);
977977
}
978978

979+
static zend_bool
980+
ra_expire_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC) {
981+
982+
zval z_fun_ttl, z_fun_expire, z_ret, *z_args[2];
983+
long ttl;
984+
985+
/* run TTL on source */
986+
MAKE_STD_ZVAL(z_args[0]);
987+
ZVAL_STRINGL(&z_fun_ttl, "TTL", 3, 0);
988+
ZVAL_STRINGL(z_args[0], key, key_len, 0);
989+
call_user_function(&redis_ce->function_table, &z_from, &z_fun_ttl, &z_ret, 1, z_args TSRMLS_CC);
990+
991+
if(Z_TYPE(z_ret) != IS_LONG) {
992+
efree(z_args[0]);
993+
return 0;
994+
}
995+
996+
ttl = Z_LVAL(z_ret);
997+
zval_dtor(&z_ret);
998+
if (ttl > 0)
999+
{
1000+
/* run EXPIRE on target */
1001+
MAKE_STD_ZVAL(z_args[1]);
1002+
ZVAL_STRINGL(&z_fun_expire, "EXPIRE", 6, 0);
1003+
ZVAL_STRINGL(z_args[0], key, key_len, 0);
1004+
ZVAL_LONG(z_args[1], ttl);
1005+
call_user_function(&redis_ce->function_table, &z_to, &z_fun_expire, &z_ret, 2, z_args TSRMLS_CC);
1006+
efree(z_args[1]);
1007+
}
1008+
/* cleanup */
1009+
efree(z_args[0]);
1010+
1011+
return 1;
1012+
}
1013+
9791014
void
9801015
ra_move_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC) {
9811016

@@ -1012,6 +1047,7 @@ ra_move_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC) {
10121047
}
10131048

10141049
if(success) {
1050+
ra_expire_key(key, key_len, z_from, z_to TSRMLS_CC);
10151051
ra_del_key(key, key_len, z_from TSRMLS_CC);
10161052
ra_index_key(key, key_len, z_to TSRMLS_CC);
10171053
}

0 commit comments

Comments
 (0)