integrate the latest srp updates

add pub/sub listening support now that it's supported by srp
This commit is contained in:
Costin Leau
2012-04-02 10:38:21 +03:00
parent 5ca5632899
commit 3cf59c2241
3 changed files with 62 additions and 5 deletions

View File

@@ -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);
}

View File

@@ -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) {
}
}

View File

@@ -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);