Add redis: Boot 4.1 + Spring Data Redis 4.1, the JDK-serialisation default vs Jackson 3 serializers, @RedisHash TTL and keyspace events, @RedisListener, and Redis as the Spring cache
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B38FGKKam5SCGgwgduVAh3
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# TTL: set, read, lose, keep and clear it
|
||||
|
||||
|
||||
--- No TTL, and a key that does not exist ---
|
||||
set("plain", "v")
|
||||
getExpire("plain") = -1
|
||||
getExpire("missing") = -2
|
||||
|
||||
--- Set a value with a Duration ---
|
||||
set("session", "v1", Duration.ofMinutes(10))
|
||||
getExpire("session") = 600
|
||||
getExpire("session", TimeUnit.MINUTES) = 9
|
||||
$ redis-cli -p 6390 --no-raw TTL session
|
||||
(integer) 600
|
||||
|
||||
--- A plain set() afterwards throws the TTL away ---
|
||||
set("session", "v2")
|
||||
getExpire("session") = -1
|
||||
$ redis-cli -p 6390 --no-raw TTL session
|
||||
(integer) -1
|
||||
|
||||
--- Put a TTL back, then overwrite while keeping it ---
|
||||
expire("session", Duration.ofMinutes(10))
|
||||
set("session", "v3", Expiration.keepTtl())
|
||||
getExpire("session") = 600, value = v3
|
||||
$ redis-cli -p 6390 --no-raw TTL session
|
||||
(integer) 600
|
||||
|
||||
--- Sub-second precision ---
|
||||
set("short", "v", Duration.ofMillis(1500))
|
||||
getExpire("short", TimeUnit.MILLISECONDS) <= 1500: true
|
||||
getExpire("short") in seconds = 1
|
||||
|
||||
--- persist() removes a TTL ---
|
||||
persist("session")
|
||||
getExpire("session") = -1
|
||||
|
||||
--- Expiry actually happens ---
|
||||
set("blink", "v", Duration.ofMillis(300))
|
||||
get("blink") straight away = v
|
||||
get("blink") later = null
|
||||
$ redis-cli -p 6390 --no-raw EXISTS blink
|
||||
(integer) 0
|
||||
|
||||
--- setIfAbsent with a TTL is the smallest lock ---
|
||||
setIfAbsent("lock:job", "worker-1", 30s) = true
|
||||
setIfAbsent("lock:job", "worker-2", 30s) = false
|
||||
$ redis-cli -p 6390 --no-raw GET lock:job
|
||||
"worker-1"
|
||||
$ redis-cli -p 6390 --no-raw TTL lock:job
|
||||
(integer) 30
|
||||
Reference in New Issue
Block a user