Implement the lastmodified query for the OBJECT command

Former-commit-id: 3a3b59a0543148956797ce4ad9d08095051517b9
This commit is contained in:
John Sully 2019-10-13 14:12:09 -04:00
parent 6310847d61
commit 6b2c838e8b
3 changed files with 8 additions and 2 deletions

View File

@ -1302,6 +1302,10 @@ NULL
* because we update the access time only * because we update the access time only
* when the key is read or overwritten. */ * when the key is read or overwritten. */
addReplyLongLong(c,LFUDecrAndReturn(o)); addReplyLongLong(c,LFUDecrAndReturn(o));
} else if (!strcasecmp(szFromObj(c->argv[1]), "lastmodified") && c->argc == 3) {
if ((o = objectCommandLookupOrReply(c,c->argv[2],shared.null[c->resp]))
== NULL) return;
addReplyLongLong(c, (g_pserver->mstime - (o->mvcc_tstamp >> MVCC_MS_SHIFT)) / 1000);
} else { } else {
addReplySubcommandSyntaxError(c); addReplySubcommandSyntaxError(c);
} }

View File

@ -4988,7 +4988,7 @@ void incrementMvccTstamp()
{ {
uint64_t msPrev; uint64_t msPrev;
__atomic_load(&g_pserver->mvcc_tstamp, &msPrev, __ATOMIC_ACQUIRE); __atomic_load(&g_pserver->mvcc_tstamp, &msPrev, __ATOMIC_ACQUIRE);
msPrev >>= 20; // convert to milliseconds msPrev >>= MVCC_MS_SHIFT; // convert to milliseconds
long long mst; long long mst;
__atomic_load(&g_pserver->mstime, &mst, __ATOMIC_RELAXED); __atomic_load(&g_pserver->mstime, &mst, __ATOMIC_RELAXED);
@ -4998,7 +4998,7 @@ void incrementMvccTstamp()
} }
else else
{ {
atomicSet(g_pserver->mvcc_tstamp, ((uint64_t)g_pserver->mstime) << 20); atomicSet(g_pserver->mvcc_tstamp, ((uint64_t)g_pserver->mstime) << MVCC_MS_SHIFT);
} }
} }

View File

@ -722,6 +722,8 @@ typedef struct RedisModuleDigest {
#define OBJ_SHARED_REFCOUNT (0x7FFFFFFF) #define OBJ_SHARED_REFCOUNT (0x7FFFFFFF)
#define OBJ_MVCC_INVALID (0xFFFFFFFFFFFFFFFFULL) #define OBJ_MVCC_INVALID (0xFFFFFFFFFFFFFFFFULL)
#define MVCC_MS_SHIFT 20
typedef struct redisObject { typedef struct redisObject {
unsigned type:4; unsigned type:4;
unsigned encoding:4; unsigned encoding:4;