Skip to content
Bluetape4k docs1.11

Codecs and serialization

Latest stable Based on Bluetape4k release 1.11.0

LettuceBinaryCodec<V> combines String keys with values produced by a BinarySerializer. LettuceJsonCodec<V> restores JSON to an explicit valueType. The integer and long codecs use fixed-width big-endian values compatible with Redisson primitive codecs.

val codec = LettuceBinaryCodecs.lz4Fory<User>()
val connection = LettuceClients.connect(client, codec)
connection.sync().set("user:1", User(1, "Alice"))

The default binary codec is LZ4+Fory. FastFory is not wire-compatible with Fory, has no fallback, and does not support cyclic object graphs. A codec switch therefore needs a new prefix, dual writes, or a deliberate cache reset.

Use object deserializers only for trusted values written by the application. If external actors can modify Redis bytes, narrow Redis permissions and prefer primitives or JSON with an explicit type contract. Compression may cost more than it saves for small values, so benchmark representative payloads.

Continue with Maps and cache loading.