diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index bd07a475d..46fa598da 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -1465,10 +1465,11 @@ public class SrpConnection implements RedisConnection { public Long zRank(byte[] key, byte[] value) { try { if (isPipelined()) { - pipeline.zrank(key, value); - return null; + // (Long) pipeline .zrank(key, value).data; + // return null; + throw new UnsupportedOperationException(); } - return client.zrank(key, value).data(); + return (Long) client.zrank(key, value).data(); } catch (Exception ex) { throw convertSRAccessException(ex); } diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java new file mode 100644 index 000000000..619438adc --- /dev/null +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011-2012 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.data.redis.connection.srp; + +import org.springframework.data.redis.connection.DefaultMessage; +import org.springframework.data.redis.connection.MessageListener; +import org.springframework.util.Assert; + +import redis.client.ReplyListener; + +/** + * MessageListener wrapper around SRP {@link ReplyListener}. + * + * @author Costin Leau + */ +class SrpMessageListener implements ReplyListener { + + private final MessageListener listener; + + SrpMessageListener(MessageListener listener) { + Assert.notNull(listener, "message listener is required"); + this.listener = listener; + } + + public void message(byte[] channel, byte[] message) { + listener.onMessage(new DefaultMessage(channel, message), null); + } + + public void psubscribed(byte[] arg0, int arg1) { + } + + public void punsubscribed(byte[] arg0, int arg1) { + } + + public void subscribed(byte[] arg0, int arg1) { + } + + public void unsubscribed(byte[] arg0, int arg1) { + } +} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java index 2ac193382..16b44803a 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java @@ -20,6 +20,7 @@ import org.springframework.data.redis.connection.MessageListener; import org.springframework.data.redis.connection.util.AbstractSubscription; import redis.client.RedisClient; +import redis.client.ReplyListener; /** * Message subscription on top of SRP. @@ -29,10 +30,13 @@ import redis.client.RedisClient; class SrpSubscription extends AbstractSubscription { private final RedisClient client; + private final ReplyListener listener; SrpSubscription(MessageListener listener, RedisClient client) { super(listener); this.client = client; + this.listener = new SrpMessageListener(listener); + client.addListener(this.listener); } protected void doClose() { @@ -45,7 +49,6 @@ class SrpSubscription extends AbstractSubscription { client.psubscribe((Object[]) patterns); } - protected void doPUnsubscribe(boolean all, byte[]... patterns) { if (all) { client.punsubscribe((Object[]) null); @@ -59,7 +62,6 @@ class SrpSubscription extends AbstractSubscription { client.subscribe((Object[]) channels); } - protected void doUnsubscribe(boolean all, byte[]... channels) { if (all) { client.unsubscribe((Object[]) null);