throw JedisDataException when sending NULL values to redis as it is not a valid value in the protocol

This commit is contained in:
Jonathan Leibiusky
2011-05-11 19:22:31 -03:00
parent cfc906167c
commit 0d6d37b95f
2 changed files with 11 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package redis.clients.util;
import java.io.UnsupportedEncodingException;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException;
/**
@@ -12,6 +13,10 @@ import redis.clients.jedis.exceptions.JedisException;
public class SafeEncoder {
public static byte[] encode(final String str) {
try {
if (str == null) {
throw new JedisDataException(
"value sent to redis cannot be null");
}
return str.getBytes(Protocol.CHARSET);
} catch (UnsupportedEncodingException e) {
throw new JedisException(e);