Skip to content

Commit

Permalink
Evicted + fix expired (#1417)
Browse files Browse the repository at this point in the history
* evicted + expired
  • Loading branch information
ashtul committed Aug 13, 2020
1 parent 7024856 commit 4c444fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/notifications.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ typedef enum {
rename_to_cmd,
trimmed_cmd,
restore_cmd,
expire_cmd,
expired_cmd,
evicted_cmd,
change_cmd,
} RedisCmd;

Expand Down Expand Up @@ -54,7 +55,8 @@ int HashNotificationCallback(RedisModuleCtx *ctx, int type, const char *event,
*hincrby_event = 0, *hincrbyfloat_event = 0, *hdel_event = 0,
*del_event = 0, *set_event = 0,
*rename_from_event = 0, *rename_to_event = 0,
*trimmed_event = 0, *restore_event = 0, *expire_event = 0, *change_event = 0;
*trimmed_event = 0, *restore_event = 0, *expired_event = 0,
*evicted_event = 0, *change_event = 0;

// clang-format off

Expand All @@ -70,7 +72,8 @@ int HashNotificationCallback(RedisModuleCtx *ctx, int type, const char *event,
else CHECK_CACHED_EVENT(rename_to)
else CHECK_CACHED_EVENT(trimmed)
else CHECK_CACHED_EVENT(restore)
else CHECK_CACHED_EVENT(expire)
else CHECK_CACHED_EVENT(expired)
else CHECK_CACHED_EVENT(evicted)
else CHECK_CACHED_EVENT(change)
else CHECK_CACHED_EVENT(del)
else CHECK_CACHED_EVENT(set)
Expand All @@ -89,7 +92,8 @@ int HashNotificationCallback(RedisModuleCtx *ctx, int type, const char *event,
else CHECK_AND_CACHE_EVENT(rename_to)
else CHECK_AND_CACHE_EVENT(trimmed)
else CHECK_AND_CACHE_EVENT(restore)
else CHECK_AND_CACHE_EVENT(expire)
else CHECK_AND_CACHE_EVENT(expired)
else CHECK_AND_CACHE_EVENT(evicted)
else CHECK_AND_CACHE_EVENT(change)
else CHECK_AND_CACHE_EVENT(del)
else CHECK_AND_CACHE_EVENT(set)
Expand All @@ -111,7 +115,8 @@ int HashNotificationCallback(RedisModuleCtx *ctx, int type, const char *event,
case del_cmd:
case set_cmd:
case trimmed_cmd:
case expire_cmd:
case expired_cmd:
case evicted_cmd:
Indexes_DeleteMatchingWithSchemaRules(ctx, key, hashFields);
break;

Expand Down Expand Up @@ -197,7 +202,8 @@ void CommandFilterCallback(RedisModuleCommandFilterCtx *filter) {
void Initialize_KeyspaceNotifications(RedisModuleCtx *ctx) {
RedisModule_SubscribeToKeyspaceEvents(ctx,
REDISMODULE_NOTIFY_GENERIC | REDISMODULE_NOTIFY_HASH |
REDISMODULE_NOTIFY_TRIMMED | REDISMODULE_NOTIFY_STRING,
REDISMODULE_NOTIFY_TRIMMED | REDISMODULE_NOTIFY_STRING |
REDISMODULE_NOTIFY_EXPIRED | REDISMODULE_NOTIFY_EVICTED,
HashNotificationCallback);
}

Expand Down
20 changes: 20 additions & 0 deletions src/pytest/test_followhashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,25 @@ def testExpire(env):
conn.execute_command('HSET', 'doc1', 'test', 'foo')
env.expect('FT.SEARCH idx foo').equal([1L, 'doc1', ['test', 'foo']])
conn.execute_command('EXPIRE', 'doc1', '1')
env.expect('FT.SEARCH idx foo').equal([1L, 'doc1', ['test', 'foo']])
sleep(1.1)
env.expect('FT.SEARCH idx foo').equal([0L])

def testEvicted(env):
env.skipOnCluster()
conn = getConnectionByEnv(env)
env.expect('FT.CREATE idx SCHEMA test TEXT').equal('OK')

memory = 0
info = conn.execute_command('INFO MEMORY')
for line in info.splitlines():
if 'used_memory:' in line:
sub = line.split(':')
memory = int(sub[1])

conn.execute_command('CONFIG', 'SET', 'MAXMEMORY-POLICY', 'ALLKEYS-RANDOM')
conn.execute_command('CONFIG', 'SET', 'MAXMEMORY', memory + 10000)
for i in range(100):
env.expect('HSET', 'doc{}'.format(i), 'test', 'foo').equal(1)
res = env.cmd('FT.SEARCH idx foo limit 0 0')
env.assertLess(res[0], 100)

0 comments on commit 4c444fc

Please sign in to comment.