mirror of
https://github.com/fluencelabs/redis
synced 2025-06-13 09:11:20 +00:00
expires: refactoring judgment about whether a key is expired
Calling lookupKey*() many times to search a key in one command may get different result. That's because lookupKey*() calls expireIfNeeded(), and delete the key when reach the expire time. So we can get an robj before the expire time, but a NULL after the expire time. The worst is that may lead to Redis crash, for example `RPOPLPUSH foo foo` the first time we get a list form `foo` and hold the pointer, but when we get `foo` again it's expired and deleted. Now we hold a freed memory, when execute rpoplpushHandlePush() redis crash. To fix it, we can refactor the judgment about whether a key is expired, using the same basetime `server.cmd_start_mstime` instead of calling mstime() everytime.
This commit is contained in:
2
src/db.c
2
src/db.c
@ -1199,7 +1199,7 @@ int keyIsExpired(redisDb *db, robj *key) {
|
||||
* only the first time it is accessed and not in the middle of the
|
||||
* script execution, making propagation to slaves / AOF consistent.
|
||||
* See issue #1525 on Github for more information. */
|
||||
mstime_t now = server.lua_caller ? server.lua_time_start : mstime();
|
||||
mstime_t now = server.lua_caller ? server.lua_time_start : server.cmd_start_mstime;
|
||||
|
||||
return now > when;
|
||||
}
|
||||
|
Reference in New Issue
Block a user