DATAKV-24
+ align pubsub with binary arguments in Jedis
This commit is contained in:
@@ -36,11 +36,11 @@ import org.springframework.data.keyvalue.redis.connection.Subscription;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
import redis.clients.jedis.BinaryTransaction;
|
||||
import redis.clients.jedis.Client;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisException;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.SortingParams;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.ZParams;
|
||||
@@ -1673,11 +1673,7 @@ public class JedisConnection implements RedisConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// FIXME: DATAKV-24 once Jedis adds support for binary messages
|
||||
String chn = new String(channel);
|
||||
String msg = new String(message);
|
||||
|
||||
return jedis.publish(chn, msg);
|
||||
return jedis.publish(channel, message);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -1705,11 +1701,10 @@ public class JedisConnection implements RedisConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
String[] pats = JedisUtils.convert(patterns);
|
||||
JedisPubSub jedisPubSub = JedisUtils.adaptPubSub(listener);
|
||||
BinaryJedisPubSub jedisPubSub = JedisUtils.adaptPubSub(listener);
|
||||
|
||||
subscription = new JedisSubscription(listener, jedisPubSub, null, patterns);
|
||||
jedis.psubscribe(jedisPubSub, pats);
|
||||
jedis.psubscribe(jedisPubSub, patterns);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -1727,11 +1722,10 @@ public class JedisConnection implements RedisConnection {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
String[] chs = JedisUtils.convert(channels);
|
||||
JedisPubSub jedisPubSub = JedisUtils.adaptPubSub(listener);
|
||||
BinaryJedisPubSub jedisPubSub = JedisUtils.adaptPubSub(listener);
|
||||
|
||||
subscription = new JedisSubscription(listener, jedisPubSub, channels, null);
|
||||
jedis.subscribe(jedisPubSub, chs);
|
||||
jedis.subscribe(jedisPubSub, channels);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ import org.springframework.data.keyvalue.redis.connection.DefaultMessage;
|
||||
import org.springframework.data.keyvalue.redis.connection.MessageListener;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
|
||||
/**
|
||||
* MessageListener adapter on top of Jedis.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class JedisMessageListener extends JedisPubSub {
|
||||
class JedisMessageListener extends BinaryJedisPubSub {
|
||||
|
||||
private final MessageListener listener;
|
||||
|
||||
@@ -36,32 +36,32 @@ class JedisMessageListener extends JedisPubSub {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
listener.onMessage(new DefaultMessage(channel.getBytes(), message.getBytes()), null);
|
||||
public void onMessage(byte[] channel, byte[] message) {
|
||||
listener.onMessage(new DefaultMessage(channel, message), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
listener.onMessage(new DefaultMessage(channel.getBytes(), message.getBytes()), pattern.getBytes());
|
||||
public void onPMessage(byte[] pattern, byte[] channel, byte[] message) {
|
||||
listener.onMessage(new DefaultMessage(channel, message), pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
// no-op
|
||||
public void onUnsubscribe(byte[] channel, int subscribedChannels) {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.keyvalue.redis.connection.Subscription;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
|
||||
/**
|
||||
* Jedis specific subscription.
|
||||
@@ -33,12 +33,12 @@ import redis.clients.jedis.JedisPubSub;
|
||||
class JedisSubscription implements Subscription {
|
||||
|
||||
private final MessageListener listener;
|
||||
private final JedisPubSub jedisPubSub;
|
||||
private final BinaryJedisPubSub jedisPubSub;
|
||||
|
||||
private final Collection<byte[]> channels = new ArrayList<byte[]>(2);
|
||||
private final Collection<byte[]> patterns = new ArrayList<byte[]>(2);
|
||||
|
||||
JedisSubscription(MessageListener listener, JedisPubSub jedisPubSub, byte[][] channels, byte[][] patterns) {
|
||||
JedisSubscription(MessageListener listener, BinaryJedisPubSub jedisPubSub, byte[][] channels, byte[][] patterns) {
|
||||
Assert.notNull(listener);
|
||||
this.listener = listener;
|
||||
this.jedisPubSub = jedisPubSub;
|
||||
@@ -89,7 +89,7 @@ class JedisSubscription implements Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
jedisPubSub.psubscribe(JedisUtils.convert(patterns));
|
||||
jedisPubSub.psubscribe(patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,7 +113,7 @@ class JedisSubscription implements Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
jedisPubSub.punsubscribe(JedisUtils.convert(patterns));
|
||||
jedisPubSub.punsubscribe(patterns);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class JedisSubscription implements Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
jedisPubSub.subscribe(JedisUtils.convert(channels));
|
||||
jedisPubSub.subscribe(channels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,7 +150,7 @@ class JedisSubscription implements Subscription {
|
||||
}
|
||||
}
|
||||
|
||||
jedisPubSub.unsubscribe(JedisUtils.convert(channels));
|
||||
jedisPubSub.unsubscribe(channels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ import org.springframework.data.keyvalue.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters.Range;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
import redis.clients.jedis.JedisException;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.SortingParams;
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
@@ -192,7 +192,7 @@ public abstract class JedisUtils {
|
||||
return info;
|
||||
}
|
||||
|
||||
static JedisPubSub adaptPubSub(MessageListener listener) {
|
||||
static BinaryJedisPubSub adaptPubSub(MessageListener listener) {
|
||||
return new JedisMessageListener(listener);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user