Skip to content

Commit

Permalink
byte[] conversion for numbers in Params classes (#2019)
Browse files Browse the repository at this point in the history
This would also be required when upgrading to JDK 1.8.
  • Loading branch information
sazzad16 authored Jul 17, 2019
1 parent 1bebbcd commit c9c118a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/redis/clients/jedis/params/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)));
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/redis/clients/jedis/params/SetParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;

import redis.clients.jedis.Protocol;
import redis.clients.jedis.util.SafeEncoder;

public class SetParams extends Params {
Expand Down Expand Up @@ -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()][]);
Expand Down

0 comments on commit c9c118a

Please sign in to comment.