Check if the key is expired. */
| 1483 | |
| 1484 | /* Check if the key is expired. */ |
| 1485 | int keyIsExpired(redisDb *db, robj *key) { |
| 1486 | mstime_t when = getExpire(db,key); |
| 1487 | mstime_t now; |
| 1488 | |
| 1489 | if (when < 0) return 0; /* No expire for this key */ |
| 1490 | |
| 1491 | /* Don't expire anything while loading. It will be done later. */ |
| 1492 | if (server.loading) return 0; |
| 1493 | |
| 1494 | /* If we are in the context of a Lua script, we pretend that time is |
| 1495 | * blocked to when the Lua script started. This way a key can expire |
| 1496 | * only the first time it is accessed and not in the middle of the |
| 1497 | * script execution, making propagation to slaves / AOF consistent. |
| 1498 | * See issue #1525 on Github for more information. */ |
| 1499 | if (server.lua_caller) { |
| 1500 | now = server.lua_time_snapshot; |
| 1501 | } |
| 1502 | /* If we are in the middle of a command execution, we still want to use |
| 1503 | * a reference time that does not change: in that case we just use the |
| 1504 | * cached time, that we update before each call in the call() function. |
| 1505 | * This way we avoid that commands such as RPOPLPUSH or similar, that |
| 1506 | * may re-open the same key multiple times, can invalidate an already |
| 1507 | * open object in a next call, if the next call will see the key expired, |
| 1508 | * while the first did not. */ |
| 1509 | else if (server.fixed_time_expire > 0) { |
| 1510 | now = server.mstime; |
| 1511 | } |
| 1512 | /* For the other cases, we want to use the most fresh time we have. */ |
| 1513 | else { |
| 1514 | now = mstime(); |
| 1515 | } |
| 1516 | |
| 1517 | /* The key expired if the current (virtual or real) time is greater |
| 1518 | * than the expire time of the key. */ |
| 1519 | return now > when; |
| 1520 | } |
| 1521 | |
| 1522 | /* This function is called when we are going to perform some operation |
| 1523 | * in a given key, but such key may be already logically expired even if |
no test coverage detected