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:
Claude
2026-09-21 15:46:55 +00:00
parent 8cdfcd4d8d
commit b0c39a8d4c
60 changed files with 2900 additions and 1 deletions
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Writes docs/output/17-dependencies.txt: which client and which JSON library actually arrive.
set -euo pipefail
cd "$(dirname "$0")/.."
OUT=docs/output/17-dependencies.txt
TREE=$(mktemp)
trap 'rm -f "$TREE"' EXIT
STARTER_POM=$(ls "$HOME"/.m2/repository/org/springframework/boot/spring-boot-starter-data-redis/*/spring-boot-starter-data-redis-*.pom | head -1)
mvn -B -q dependency:tree -DoutputFile="$TREE" \
-Dincludes='io.lettuce,redis.clients,tools.jackson.core,com.fasterxml.jackson.core,org.springframework.data,org.springframework:spring-messaging' >/dev/null
{
echo "# What the Redis starter brings, and what it does not"
echo
echo "--- The starter's own dependencies (from its pom) ---"
echo "\$ grep -E 'artifactId|scope' spring-boot-starter-data-redis-*.pom"
grep -E 'artifactId|scope' "$STARTER_POM" | sed 's/^[ \t]*//'
echo
echo "--- The client and JSON libraries in this module (mvn dependency:tree, filtered) ---"
echo "\$ mvn dependency:tree -Dincludes=io.lettuce,redis.clients,tools.jackson.core,com.fasterxml.jackson.core,org.springframework.data,org.springframework:spring-messaging"
cat "$TREE"
echo
echo "--- The server the tests start ---"
echo "\$ redis-server --version"
redis-server --version
} > "$OUT"
cat "$OUT"
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Writes docs/output/16-serializers-javap.txt: which serializer classes ship in Spring Data Redis,
# which are deprecated, what the Jackson 3 ones accept, and which beans Boot 4.1 registers.
#
# Reading bytecode is how the article's claims about class names were checked. The reference
# documentation still shows Jackson 2 class names in places.
set -euo pipefail
cd "$(dirname "$0")/.."
OUT=docs/output/16-serializers-javap.txt
CP_FILE=$(mktemp)
trap 'rm -f "$CP_FILE"' EXIT
mvn -B -q dependency:build-classpath -Dmdep.outputFile="$CP_FILE" >/dev/null
CP=$(cat "$CP_FILE")
jar_of() { tr ':' '\n' < "$CP_FILE" | grep "/$1-[0-9]" | head -1; }
SDR=$(jar_of spring-data-redis)
BOOT=$(jar_of spring-boot-data-redis)
S=org.springframework.data.redis.serializer
run() { # run <display-command> <shell-command>
echo "\$ $1"
bash -c "$2" || true
}
{
echo "# Serializer classes in $(basename "$SDR"), read from the jar"
echo
echo "--- What ships in org/springframework/data/redis/serializer ---"
run "unzip -l spring-data-redis-*.jar | grep serializer/ (top-level classes, names only)" \
"unzip -l '$SDR' | awk '{print \$4}' | grep 'redis/serializer/[A-Za-z0-9]*\.class' | sed 's|.*/||; s|\.class||' | grep -E 'Serializer\$' | sort"
echo
echo "--- Which of them are deprecated ---"
for c in GenericJackson2JsonRedisSerializer Jackson2JsonRedisSerializer GenericJacksonJsonRedisSerializer JacksonJsonRedisSerializer; do
run "javap -v -cp spring-data-redis-*.jar $S.$c | grep -E 'Deprecated|since'" \
"javap -v -cp '$SDR' $S.$c | grep -E 'Deprecated|since'"
echo "(end of output for $c)"
done
echo
echo "--- Jackson 3: what the constructors and factories accept ---"
run "javap -public -cp <classpath> $S.JacksonJsonRedisSerializer | grep 'JacksonJsonRedisSerializer('" \
"javap -public -cp '$CP' $S.JacksonJsonRedisSerializer | grep 'JacksonJsonRedisSerializer('"
run "javap -public -cp <classpath> $S.GenericJacksonJsonRedisSerializer | grep -E 'GenericJacksonJsonRedisSerializer\(|create|builder'" \
"javap -public -cp '$CP' $S.GenericJacksonJsonRedisSerializer | grep -E 'GenericJacksonJsonRedisSerializer\(|create|builder'"
echo
echo "--- Jackson 3: how the generic serializer's builder turns typing on ---"
run "javap -public -cp <classpath> '$S.GenericJacksonJsonRedisSerializer\$GenericJacksonJsonRedisSerializerBuilder' | grep -E 'Typing|typeValidator|typePropertyName'" \
"javap -public -cp '$CP' '$S.GenericJacksonJsonRedisSerializer\$GenericJacksonJsonRedisSerializerBuilder' | grep -E 'Typing|typeValidator|typePropertyName'"
echo
echo "--- What Boot 4.1 registers ---"
run "javap -p -cp spring-boot-data-redis-*.jar org.springframework.boot.data.redis.autoconfigure.DataRedisAutoConfiguration | grep -E 'redisTemplate|stringRedisTemplate'" \
"javap -p -cp '$BOOT' org.springframework.boot.data.redis.autoconfigure.DataRedisAutoConfiguration | grep -E 'redisTemplate|stringRedisTemplate'"
run "javap -p -cp spring-boot-data-redis-*.jar org.springframework.boot.data.redis.autoconfigure.DataRedisAnnotationDrivenConfiguration | grep 'redisMessageListenerContainer'" \
"javap -p -cp '$BOOT' org.springframework.boot.data.redis.autoconfigure.DataRedisAnnotationDrivenConfiguration | grep 'redisMessageListenerContainer'"
echo
echo "--- Defaults of @EnableRedisRepositories that matter for expiry ---"
run "javap -v -cp spring-data-redis-*.jar org.springframework.data.redis.repository.configuration.EnableRedisRepositories | grep -A6 -E '(enableKeyspaceEvents|keyspaceNotificationsConfigParameter)\\(\\);' | grep -E '\\(\\);|\"Ex\"|\\.OFF'" \
"javap -v -cp '$SDR' org.springframework.data.redis.repository.configuration.EnableRedisRepositories | grep -A6 -E '(enableKeyspaceEvents|keyspaceNotificationsConfigParameter)\\(\\);' | grep -E '\\(\\);|\"Ex\"|\\.OFF'"
echo
echo "--- The @RedisListener annotation ---"
run "javap -public -cp spring-data-redis-*.jar org.springframework.data.redis.annotation.RedisListener" \
"javap -public -cp '$SDR' org.springframework.data.redis.annotation.RedisListener"
} > "$OUT"
cat "$OUT"
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Regenerates every file under docs/output/.
#
# ./scripts/run-all.sh
#
# Needs a JDK 25, Maven 3.9, and redis-server and redis-cli (7.x) on the PATH. The tests start a
# throwaway redis-server on port 6390 and stop it when the JVM exits; they refuse to run if
# something already listens there, because they call FLUSHALL.
#
# Everything except transcripts 16 and 17 comes out of the test suite, so the numbers in the
# article are assertions that fail the build if they stop being true.
set -euo pipefail
cd "$(dirname "$0")/.."
echo "== test suite (transcripts 01-15)"
mvn -B test
echo "== javap transcript (16)"
./scripts/capture-javap.sh >/dev/null
echo "== dependency transcript (17)"
./scripts/capture-dependencies.sh >/dev/null
echo
echo "docs/output:"
ls -1 docs/output