mirror of https://mirror.osredm.com/root/redis.git
![]() ## Background This PR introduces support for field-level expiration in Redis hashes. Previously, Redis supported expiration only at the key level, but this enhancement allows setting expiration times for individual fields within a hash. ## New commands * HEXPIRE * HEXPIREAT * HEXPIRETIME * HPERSIST * HPEXPIRE * HPEXPIREAT * HPEXPIRETIME * HPTTL * HTTL ## Short example from @moticless ```sh 127.0.0.1:6379> hset myhash f1 v1 f2 v2 f3 v3 (integer) 3 127.0.0.1:6379> hpexpire myhash 10000 NX fields 2 f2 f3 1) (integer) 1 2) (integer) 1 127.0.0.1:6379> hpttl myhash fields 3 f1 f2 f3 1) (integer) -1 2) (integer) 9997 3) (integer) 9997 127.0.0.1:6379> hgetall myhash 1) "f3" 2) "v3" 3) "f2" 4) "v2" 5) "f1" 6) "v1" ... after 10 seconds ... 127.0.0.1:6379> hgetall myhash 1) "f1" 2) "v1" 127.0.0.1:6379> ``` ## Expiration strategy 1. Integrate active Redis periodically performs active expiration and deletion of hash keys that contain expired fields, with a maximum attempt limit. 3. Lazy expiration When a client touches fields within a hash, Redis checks if the fields are expired. If a field is expired, it will be deleted. However, we do not delete expired fields during a traversal, we implicitly skip over them. ## RDB changes Add two new rdb type s`RDB_TYPE_HASH_METADATA` and `RDB_TYPE_HASH_LISTPACK_EX`. ## Notification 1. Add `hpersist` notification for `HPERSIST` command. 5. Add `hexpire` notification for `HEXPIRE`, `HEXPIREAT`, `HPEXPIRE` and `HPEXPIREAT` commands. ## Internal 1. Add new data structure `ebuckets`, which is used to store TTL and keys, enabling quick retrieval of keys based on TTL. 2. Add new data structure `mstr` like sds, which is used to store a string with TTL. This work was done by @moticless, @tezc, @ronen-kalish, @sundb, I just release it. |
||
---|---|---|
.. | ||
aof-multi-part.tcl | ||
aof-race.tcl | ||
aof.tcl | ||
block-repl.tcl | ||
convert-ziplist-hash-on-load.tcl | ||
convert-ziplist-zset-on-load.tcl | ||
convert-zipmap-hash-on-load.tcl | ||
corrupt-dump-fuzzer.tcl | ||
corrupt-dump.tcl | ||
dismiss-mem.tcl | ||
failover.tcl | ||
logging.tcl | ||
psync2-master-restart.tcl | ||
psync2-pingoff.tcl | ||
psync2-reg.tcl | ||
psync2.tcl | ||
rdb.tcl | ||
redis-benchmark.tcl | ||
redis-cli.tcl | ||
replication-2.tcl | ||
replication-3.tcl | ||
replication-4.tcl | ||
replication-buffer.tcl | ||
replication-psync.tcl | ||
replication.tcl | ||
shutdown.tcl |