From c9c118aa86a1ff473b94dddd7fb28d640837e194 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque Date: Wed, 17 Jul 2019 10:13:22 +0600 Subject: [PATCH] byte[] conversion for numbers in Params classes (#2019) This would also be required when upgrading to JDK 1.8. --- .../java/redis/clients/jedis/params/GeoRadiusParam.java | 2 +- src/main/java/redis/clients/jedis/params/Params.java | 9 +++++++++ src/main/java/redis/clients/jedis/params/SetParams.java | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/params/GeoRadiusParam.java b/src/main/java/redis/clients/jedis/params/GeoRadiusParam.java index 6ac27a7554..b7e4c0221a 100644 --- a/src/main/java/redis/clients/jedis/params/GeoRadiusParam.java +++ b/src/main/java/redis/clients/jedis/params/GeoRadiusParam.java @@ -65,7 +65,7 @@ public byte[][] getByteParams(byte[]... args) { if (contains(COUNT)) { byteParams.add(SafeEncoder.encode(COUNT)); - byteParams.add(Protocol.toByteArray((Integer) getParam(COUNT))); + byteParams.add(Protocol.toByteArray((int) getParam(COUNT))); } if (contains(ASC)) { diff --git a/src/main/java/redis/clients/jedis/params/Params.java b/src/main/java/redis/clients/jedis/params/Params.java index a51735534a..67c7214280 100644 --- a/src/main/java/redis/clients/jedis/params/Params.java +++ b/src/main/java/redis/clients/jedis/params/Params.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Map.Entry; +import redis.clients.jedis.Protocol; import redis.clients.jedis.util.SafeEncoder; public abstract class Params { @@ -29,6 +30,14 @@ public byte[][] getByteParams() { if (value != null) { if (value instanceof byte[]) { byteParams.add((byte[]) value); + } else if (value instanceof Boolean) { + byteParams.add(Protocol.toByteArray((boolean) value)); + } else if (value instanceof Integer) { + byteParams.add(Protocol.toByteArray((int) value)); + } else if (value instanceof Long) { + byteParams.add(Protocol.toByteArray((long) value)); + } else if (value instanceof Double) { + byteParams.add(Protocol.toByteArray((double) value)); } else { byteParams.add(SafeEncoder.encode(String.valueOf(value))); } diff --git a/src/main/java/redis/clients/jedis/params/SetParams.java b/src/main/java/redis/clients/jedis/params/SetParams.java index 6e14e9b04b..b213ebf0bf 100644 --- a/src/main/java/redis/clients/jedis/params/SetParams.java +++ b/src/main/java/redis/clients/jedis/params/SetParams.java @@ -2,6 +2,7 @@ import java.util.ArrayList; +import redis.clients.jedis.Protocol; import redis.clients.jedis.util.SafeEncoder; public class SetParams extends Params { @@ -71,11 +72,11 @@ public byte[][] getByteParams(byte[]... args) { if (contains(EX)) { byteParams.add(SafeEncoder.encode(EX)); - byteParams.add(SafeEncoder.encode(String.valueOf(getParam(EX)))); + byteParams.add(Protocol.toByteArray((int) getParam(EX))); } if (contains(PX)) { byteParams.add(SafeEncoder.encode(PX)); - byteParams.add(SafeEncoder.encode(String.valueOf(getParam(PX)))); + byteParams.add(Protocol.toByteArray((long) getParam(PX))); } return byteParams.toArray(new byte[byteParams.size()][]);