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,30 @@
|
||||
# Jackson 3 serializers: JacksonJsonRedisSerializer and GenericJacksonJsonRedisSerializer
|
||||
|
||||
|
||||
--- JacksonJsonRedisSerializer<User>: one type, plain JSON ---
|
||||
value serializer: org.springframework.data.redis.serializer.JacksonJsonRedisSerializer
|
||||
userTemplate.opsForValue().set("user:1", new User(1, "Ankur"))
|
||||
$ redis-cli -p 6390 KEYS '*'
|
||||
user:1
|
||||
$ redis-cli -p 6390 GET user:1
|
||||
{"id":1,"name":"Ankur"}
|
||||
read back: User[id=1, name=Ankur] (User)
|
||||
|
||||
--- GenericJacksonJsonRedisSerializer with an allow-list: any type, plus @class ---
|
||||
value serializer: org.springframework.data.redis.serializer.GenericJacksonJsonRedisSerializer
|
||||
jsonTemplate.opsForValue().set("user:2", new User(2, "Ankur"))
|
||||
$ redis-cli -p 6390 GET user:2
|
||||
{"@class":"com.ankurm.redis.model.User","id":2,"name":"Ankur"}
|
||||
read back: User[id=2, name=Ankur] (User)
|
||||
|
||||
--- GenericJacksonJsonRedisSerializer with no typing configured ---
|
||||
plain.opsForValue().set("user:3", new User(3, "Ankur"))
|
||||
$ redis-cli -p 6390 GET user:3
|
||||
{"id":3,"name":"Ankur"}
|
||||
read back: {id=3, name=Ankur} (LinkedHashMap)
|
||||
|
||||
--- Two different shapes of the same JSON ---
|
||||
$ redis-cli -p 6390 GET user:1
|
||||
{"id":1,"name":"Ankur"}
|
||||
$ redis-cli -p 6390 GET user:2
|
||||
{"@class":"com.ankurm.redis.model.User","id":2,"name":"Ankur"}
|
||||
Reference in New Issue
Block a user