use INVALID_EXPIRE instead of -1
Former-commit-id: 9e45984a97a293d87474f87612204a24c831a343
This commit is contained in:
parent
9b201b31c3
commit
3a379f0934
@ -5425,11 +5425,11 @@ try_again:
|
||||
for (j = 0; j < num_keys; j++) {
|
||||
long long ttl = 0;
|
||||
expireEntry *pexpire = getExpire(c->db,kv[j]);
|
||||
long long expireat = -1;
|
||||
long long expireat = INVALID_EXPIRE;
|
||||
if (pexpire != nullptr)
|
||||
pexpire->FGetPrimaryExpire(&expireat);
|
||||
|
||||
if (expireat != -1) {
|
||||
if (expireat != INVALID_EXPIRE) {
|
||||
ttl = expireat-mstime();
|
||||
if (ttl < 0) {
|
||||
continue;
|
||||
|
@ -1626,7 +1626,7 @@ int keyIsExpired(redisDb *db, robj *key) {
|
||||
/* Don't expire anything while loading. It will be done later. */
|
||||
if (g_pserver->loading) return 0;
|
||||
|
||||
long long when = pexpire->whenFull();
|
||||
long long when = pexpire->FGetPrimaryExpire();
|
||||
|
||||
if (when == INVALID_EXPIRE)
|
||||
return 0;
|
||||
|
@ -128,7 +128,7 @@ void xorObjectDigest(redisDb *db, robj_roptr keyobj, unsigned char *digest, robj
|
||||
uint32_t aux = htonl(o->type);
|
||||
mixDigest(digest,&aux,sizeof(aux));
|
||||
expireEntry *pexpire = getExpire(db,keyobj);
|
||||
long long expiretime = -1;
|
||||
long long expiretime = INVALID_EXPIRE;
|
||||
char buf[128];
|
||||
|
||||
if (pexpire != nullptr)
|
||||
@ -260,7 +260,7 @@ void xorObjectDigest(redisDb *db, robj_roptr keyobj, unsigned char *digest, robj
|
||||
serverPanic("Unknown object type");
|
||||
}
|
||||
/* If the key has an expire, add it to the mix */
|
||||
if (expiretime != -1) xorDigest(digest,"!!expire!!",10);
|
||||
if (expiretime != INVALID_EXPIRE) xorDigest(digest,"!!expire!!",10);
|
||||
}
|
||||
|
||||
/* Compute the dataset digest. Since keys, sets elements, hashes elements
|
||||
|
@ -668,7 +668,7 @@ void pexpireatCommand(client *c) {
|
||||
|
||||
/* Implements TTL and PTTL */
|
||||
void ttlGenericCommand(client *c, int output_ms) {
|
||||
long long expire = -1, ttl = -1;
|
||||
long long expire = INVALID_EXPIRE, ttl = -1;
|
||||
|
||||
/* If the key does not exist at all, return -2 */
|
||||
if (lookupKeyReadWithFlags(c->db,c->argv[1],LOOKUP_NOTOUCH) == nullptr) {
|
||||
@ -702,7 +702,7 @@ void ttlGenericCommand(client *c, int output_ms) {
|
||||
}
|
||||
|
||||
|
||||
if (expire != -1) {
|
||||
if (expire != INVALID_EXPIRE) {
|
||||
ttl = expire-mstime();
|
||||
if (ttl < 0) ttl = 0;
|
||||
}
|
||||
|
45
src/expire.h
45
src/expire.h
@ -34,14 +34,7 @@ public:
|
||||
~expireEntryFat();
|
||||
|
||||
long long when() const noexcept { return m_vecexpireEntries.front().when; }
|
||||
long long whenFull() const noexcept {
|
||||
for (size_t i = 0; i < size(); ++i) {
|
||||
if (m_vecexpireEntries[i].spsubkey == nullptr) {
|
||||
return m_vecexpireEntries[i].when;
|
||||
}
|
||||
}
|
||||
return INVALID_EXPIRE;
|
||||
}
|
||||
|
||||
const char *key() const noexcept { return m_keyPrimary; }
|
||||
|
||||
bool operator<(long long when) const noexcept { return this->when() < when; }
|
||||
@ -120,7 +113,10 @@ public:
|
||||
expireEntry(expireEntryFat *pfatentry)
|
||||
{
|
||||
u.m_pfatentry = pfatentry;
|
||||
m_when = FFatMask() | pfatentry->whenFull();
|
||||
if (FGetPrimaryExpireSlow(&m_when))
|
||||
m_when = FFatMask() | m_when;
|
||||
else
|
||||
m_when = INVALID_EXPIRE;
|
||||
}
|
||||
|
||||
expireEntry(expireEntry &&e)
|
||||
@ -173,11 +169,7 @@ public:
|
||||
{
|
||||
if (FFat())
|
||||
return u.m_pfatentry->when();
|
||||
return whenFull();
|
||||
}
|
||||
long long whenFull() const noexcept
|
||||
{
|
||||
return m_when & (~FFatMask());
|
||||
return FGetPrimaryExpire();
|
||||
}
|
||||
|
||||
void update(const char *subkey, long long when)
|
||||
@ -221,12 +213,27 @@ public:
|
||||
pfatentry()->m_vecexpireEntries.begin() + itr.m_idx);
|
||||
}
|
||||
|
||||
bool FGetPrimaryExpire(long long *pwhen)
|
||||
long long FGetPrimaryExpire() const noexcept
|
||||
{
|
||||
return m_when & (~FFatMask());
|
||||
}
|
||||
|
||||
bool FGetPrimaryExpire(long long *pwhen) const noexcept
|
||||
{
|
||||
*pwhen = FGetPrimaryExpire();
|
||||
return *pwhen != INVALID_EXPIRE;
|
||||
}
|
||||
|
||||
bool FGetPrimaryExpireSlow(long long *pwhen)
|
||||
{
|
||||
*pwhen = -1;
|
||||
if (this->whenFull() != INVALID_EXPIRE) {
|
||||
*pwhen = this->whenFull();
|
||||
return true;
|
||||
*pwhen = INVALID_EXPIRE;
|
||||
for (auto itr : *this)
|
||||
{
|
||||
if (itr.subkey() == nullptr)
|
||||
{
|
||||
*pwhen = itr.when();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -2264,11 +2264,11 @@ int RM_UnlinkKey(RedisModuleKey *key) {
|
||||
* REDISMODULE_NO_EXPIRE is returned. */
|
||||
mstime_t RM_GetExpire(RedisModuleKey *key) {
|
||||
expireEntry *pexpire = getExpire(key->db,key->key);
|
||||
mstime_t expire = -1;
|
||||
mstime_t expire = INVALID_EXPIRE;
|
||||
if (pexpire != nullptr)
|
||||
pexpire->FGetPrimaryExpire(&expire);
|
||||
|
||||
if (expire == -1 || key->value == NULL)
|
||||
if (expire == INVALID_EXPIRE || key->value == NULL)
|
||||
return REDISMODULE_NO_EXPIRE;
|
||||
expire -= mstime();
|
||||
return expire >= 0 ? expire : 0;
|
||||
|
@ -1101,7 +1101,7 @@ int rdbSaveKeyValuePair(rio *rdb, robj *key, robj *val, expireEntry *pexpire) {
|
||||
int savelfu = g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU;
|
||||
|
||||
/* Save the expire time */
|
||||
long long expiretime = -1;
|
||||
long long expiretime = INVALID_EXPIRE;
|
||||
if (pexpire != nullptr && pexpire->FGetPrimaryExpire(&expiretime)) {
|
||||
if (rdbSaveType(rdb,RDB_OPCODE_EXPIRETIME_MS) == -1) return -1;
|
||||
if (rdbSaveMillisecondTime(rdb,expiretime) == -1) return -1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user