From 1be0d1ac65cca2f322e6df9ad8e7bbdb4d203c7d Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 16 Aug 2023 09:08:24 +0200 Subject: [PATCH] Add missing LongCodec to RedisCommandBuilder #2481 --- .../io/lettuce/core/RedisCommandBuilder.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/io/lettuce/core/RedisCommandBuilder.java b/src/main/java/io/lettuce/core/RedisCommandBuilder.java index 2ffc42c88f..f4f6e03f1c 100644 --- a/src/main/java/io/lettuce/core/RedisCommandBuilder.java +++ b/src/main/java/io/lettuce/core/RedisCommandBuilder.java @@ -4201,4 +4201,33 @@ private static void notEmptyRanges(Range[] ranges) { LettuceAssert.notEmpty(ranges, "Ranges " + MUST_NOT_BE_NULL); } + enum LongCodec implements RedisCodec { + + INSTANCE; + + @Override + public Long decodeKey(ByteBuffer bytes) { + + String s = StringCodec.ASCII.decodeKey(bytes); + + return s == null ? null : Long.valueOf(s); + } + + @Override + public Long decodeValue(ByteBuffer bytes) { + return decodeKey(bytes); + } + + @Override + public ByteBuffer encodeKey(Long key) { + return StringCodec.ASCII.encodeKey(key == null ? null : key.toString()); + } + + @Override + public ByteBuffer encodeValue(Long value) { + return encodeKey(value); + } + + } + }