diff --git a/src/db.c b/src/db.c index 9a53e6b4d1..e84cc4526b 100644 --- a/src/db.c +++ b/src/db.c @@ -1860,7 +1860,8 @@ void deleteExpiredKeyFromOverwriteAndPropagate(client *c, robj *keyobj) { robj *aux = server.lazyfree_lazy_expire ? shared.unlink : shared.del; rewriteClientCommandVector(c, 2, aux, keyobj); signalModifiedKey(c, c->db, keyobj); - notifyKeyspaceEvent(NOTIFY_GENERIC, "del", keyobj, c->db->id); + notifyKeyspaceEvent(NOTIFY_EXPIRED, "expired", keyobj, c->db->id); + server.stat_expiredkeys++; } /* Propagate an implicit key deletion into replicas and the AOF file. diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl index e1dcc9203b..a34d403dc5 100644 --- a/tests/unit/expire.tcl +++ b/tests/unit/expire.tcl @@ -142,6 +142,31 @@ start_server {tags {"expire"}} { list $e $f } {somevalue {}} + test {EXPIRE / EXPIREAT / PEXPIRE / PEXPIREAT Expiration time is already expired} { + set prev_expired [s expired_keys] + r del x + + r set x somevalue + r expire x -1 + assert_equal {0} [r exists x] + assert_equal {1} [expr {[s expired_keys] - $prev_expired}] + + r set x somevalue + r expireat x [expr [clock seconds] - 1] + assert_equal {0} [r exists x] + assert_equal {2} [expr {[s expired_keys] - $prev_expired}] + + r set x somevalue + r pexpire x -1 + assert_equal {0} [r exists x] + assert_equal {3} [expr {[s expired_keys] - $prev_expired}] + + r set x somevalue + r pexpireat x [expr [clock milliseconds] - 1] + assert_equal {0} [r exists x] + assert_equal {4} [expr {[s expired_keys] - $prev_expired}] + } + test {TTL returns time to live in seconds} { r del x r setex x 10 somevalue diff --git a/tests/unit/pubsub.tcl b/tests/unit/pubsub.tcl index 24b78b6e5a..482052dc3d 100644 --- a/tests/unit/pubsub.tcl +++ b/tests/unit/pubsub.tcl @@ -425,6 +425,17 @@ start_server {tags {"pubsub network"}} { $rd1 close } + test "Keyspace notification: expired event (Expiration time is already expired)" { + r config set notify-keyspace-events Ex + r del foo + set rd1 [valkey_deferring_client] + assert_equal {1} [psubscribe $rd1 *] + r set foo 1 + r expire foo 0 + assert_equal "pmessage * __keyevent@${db}__:expired foo" [$rd1 read] + $rd1 close + } + test "Keyspace notifications: evicted events" { r config set notify-keyspace-events Ee r config set maxmemory-policy allkeys-lru