Merge branch 'lettuce'
This commit is contained in:
@@ -46,6 +46,7 @@ dependencies {
|
||||
compile("com.github.spullara.redis:client:$srpVersion", optional)
|
||||
compile("org.jredis:jredis-anthonylauzon:$jredisVersion", optional)
|
||||
compile("org.idevlab:rjc:$rjcVersion", optional)
|
||||
compile("com.lambdaworks:lettuce:$lettuceVersion", optional)
|
||||
|
||||
// Mappers
|
||||
compile("org.codehaus.jackson:jackson-mapper-asl:$jacksonVersion", optional)
|
||||
|
||||
@@ -17,6 +17,7 @@ jedisVersion = 2.1.0
|
||||
jredisVersion = 03122010
|
||||
rjcVersion = 0.6.4
|
||||
srpVersion = 0.2
|
||||
lettuceVersion = 2.2.0
|
||||
|
||||
# --------------------
|
||||
# Project wide version
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.lettuce;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.lambdaworks.redis.codec.RedisCodec;
|
||||
|
||||
/**
|
||||
* Basic codec that returns the raw data as byte[].
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class BytesRedisCodec extends RedisCodec<byte[], byte[]> {
|
||||
|
||||
@Override
|
||||
public byte[] decodeKey(ByteBuffer bytes) {
|
||||
return getBytes(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decodeValue(ByteBuffer bytes) {
|
||||
return getBytes(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeKey(byte[] key) {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encodeValue(byte[] value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static byte[] getBytes(ByteBuffer buffer) {
|
||||
byte[] b = new byte[buffer.remaining()];
|
||||
buffer.get(b);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.lettuce;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
import com.lambdaworks.redis.RedisClient;
|
||||
|
||||
/**
|
||||
* Connection factory creating <a href="http://github.com/wg/lettuce">Lettuce</a>-based connections.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class LettuceConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory {
|
||||
|
||||
private String hostName = "localhost";
|
||||
private int port = 6379;
|
||||
private RedisClient client;
|
||||
private long timeout = TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS);
|
||||
|
||||
/**
|
||||
* Constructs a new <code>LettuceConnectionFactory</code> instance
|
||||
* with default settings.
|
||||
*/
|
||||
public LettuceConnectionFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>LettuceConnectionFactory</code> instance
|
||||
* with default settings.
|
||||
*/
|
||||
public LettuceConnectionFactory(String host, int port) {
|
||||
this.hostName = host;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
client = new RedisClient(hostName, port);
|
||||
client.setDefaultTimeout(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
client.shutdown();
|
||||
}
|
||||
|
||||
public RedisConnection getConnection() {
|
||||
return new LettuceConnection(client.connectAsync(LettuceUtils.CODEC), timeout, client);
|
||||
}
|
||||
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
return LettuceUtils.convertRedisAccessException(ex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current host.
|
||||
*
|
||||
* @return the host
|
||||
*/
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the host.
|
||||
*
|
||||
* @param host the host to set
|
||||
*/
|
||||
public void setHostName(String host) {
|
||||
this.hostName = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current port.
|
||||
*
|
||||
* @return the port
|
||||
*/
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the port.
|
||||
*
|
||||
* @param port the port to set
|
||||
*/
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the connection timeout (in milliseconds).
|
||||
*
|
||||
* @return connection timeout
|
||||
*/
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the connection timeout (in milliseconds).
|
||||
*
|
||||
* @param timeout connection timeout
|
||||
*/
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.lettuce;
|
||||
|
||||
import org.springframework.data.redis.connection.DefaultMessage;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.lambdaworks.redis.pubsub.RedisPubSubListener;
|
||||
|
||||
/**
|
||||
* MessageListener wrapper around Lettuce {@link RedisPubSubListener}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class LettuceMessageListener implements RedisPubSubListener<byte[], byte[]> {
|
||||
|
||||
private final MessageListener listener;
|
||||
|
||||
LettuceMessageListener(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 message(byte[] pattern, byte[] channel, byte[] message) {
|
||||
listener.onMessage(new DefaultMessage(channel, message), pattern);
|
||||
}
|
||||
|
||||
public void subscribed(byte[] channel, long count) {
|
||||
}
|
||||
|
||||
public void psubscribed(byte[] pattern, long count) {
|
||||
}
|
||||
|
||||
public void unsubscribed(byte[] channel, long count) {
|
||||
}
|
||||
|
||||
public void punsubscribed(byte[] pattern, long count) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.lettuce;
|
||||
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.util.AbstractSubscription;
|
||||
|
||||
import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
|
||||
|
||||
/**
|
||||
* Message subscription on top of Lettuce.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class LettuceSubscription extends AbstractSubscription {
|
||||
|
||||
final RedisPubSubConnection<byte[], byte[]> pubsub;
|
||||
private LettuceMessageListener listener;
|
||||
|
||||
LettuceSubscription(MessageListener listener, RedisPubSubConnection<byte[], byte[]> pubsubConnection) {
|
||||
super(listener);
|
||||
this.pubsub = pubsubConnection;
|
||||
this.listener = new LettuceMessageListener(listener);
|
||||
|
||||
pubsub.addListener(this.listener);
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
pubsub.unsubscribe(new byte[0]);
|
||||
pubsub.punsubscribe(new byte[0]);
|
||||
pubsub.removeListener(this.listener);
|
||||
pubsub.close();
|
||||
}
|
||||
|
||||
|
||||
protected void doPsubscribe(byte[]... patterns) {
|
||||
pubsub.psubscribe(patterns);
|
||||
}
|
||||
|
||||
protected void doPUnsubscribe(boolean all, byte[]... patterns) {
|
||||
// lettuce doesn't automatically subscribe from all channels
|
||||
pubsub.punsubscribe(patterns);
|
||||
}
|
||||
|
||||
protected void doSubscribe(byte[]... channels) {
|
||||
pubsub.subscribe(channels);
|
||||
}
|
||||
|
||||
protected void doUnsubscribe(boolean all, byte[]... channels) {
|
||||
// lettuce doesn't automatically subscribe from all patterns
|
||||
pubsub.unsubscribe(channels);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.lettuce;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.DefaultTuple;
|
||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.lambdaworks.redis.KeyValue;
|
||||
import com.lambdaworks.redis.RedisCommandInterruptedException;
|
||||
import com.lambdaworks.redis.RedisException;
|
||||
import com.lambdaworks.redis.ScoredValue;
|
||||
import com.lambdaworks.redis.SortArgs;
|
||||
import com.lambdaworks.redis.ZStoreArgs;
|
||||
import com.lambdaworks.redis.codec.RedisCodec;
|
||||
import com.lambdaworks.redis.protocol.Charsets;
|
||||
|
||||
/**
|
||||
* Helper class featuring methods for Lettuce connection handling, providing support for exception translation.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
abstract class LettuceUtils {
|
||||
|
||||
static final RedisCodec<byte[], byte[]> CODEC = new BytesRedisCodec();
|
||||
|
||||
static DataAccessException convertRedisAccessException(RuntimeException ex) {
|
||||
if (ex instanceof RedisCommandInterruptedException) {
|
||||
return new RedisSystemException("Redis command interrupted", ex);
|
||||
}
|
||||
if (ex instanceof RedisException) {
|
||||
return new RedisSystemException("Redis exception", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Properties info(String reply) {
|
||||
Properties info = new Properties();
|
||||
StringReader stringReader = new StringReader(reply);
|
||||
try {
|
||||
info.load(stringReader);
|
||||
} catch (Exception ex) {
|
||||
throw new RedisSystemException("Cannot read Redis info", ex);
|
||||
} finally {
|
||||
stringReader.close();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
static int asBit(boolean value) {
|
||||
return (value ? 1 : 0);
|
||||
}
|
||||
|
||||
static boolean convertPosition(Position where) {
|
||||
Assert.notNull("list positions are mandatory");
|
||||
return (Position.AFTER.equals(where) ? false : true);
|
||||
}
|
||||
|
||||
static Set<Tuple> convertTuple(List<ScoredValue<byte[]>> zrange) {
|
||||
Set<Tuple> tuples = new LinkedHashSet<Tuple>(zrange.size());
|
||||
|
||||
for (int i = 0; i < zrange.size(); i++) {
|
||||
tuples.add(new DefaultTuple(zrange.get(i).value, Double.valueOf(zrange.get(i).score)));
|
||||
}
|
||||
return tuples;
|
||||
}
|
||||
|
||||
static SortArgs sort(SortParameters params) {
|
||||
SortArgs args = new SortArgs();
|
||||
|
||||
if (params.getByPattern() != null) {
|
||||
args.by(new String(params.getByPattern(), Charsets.ASCII));
|
||||
}
|
||||
|
||||
if (params.getLimit() != null) {
|
||||
args.limit(params.getLimit().getStart(), params.getLimit().getCount());
|
||||
}
|
||||
|
||||
if (params.getGetPattern() != null) {
|
||||
byte[][] pattern = params.getGetPattern();
|
||||
for (byte[] bs : pattern) {
|
||||
args.get(new String(bs, Charsets.ASCII));
|
||||
}
|
||||
}
|
||||
|
||||
if (params.getOrder() != null) {
|
||||
if (params.getOrder() == Order.ASC) {
|
||||
args.asc();
|
||||
}
|
||||
else {
|
||||
args.desc();
|
||||
}
|
||||
}
|
||||
|
||||
if (params.isAlphabetic()) {
|
||||
args.alpha();
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
static ZStoreArgs zArgs(Aggregate aggregate, int[] weights) {
|
||||
ZStoreArgs args = new ZStoreArgs();
|
||||
|
||||
if (aggregate != null) {
|
||||
switch (aggregate) {
|
||||
case MIN:
|
||||
args.min();
|
||||
break;
|
||||
case MAX:
|
||||
args.max();
|
||||
break;
|
||||
default:
|
||||
args.sum();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
long[] lg = new long[weights.length];
|
||||
for (int i = 0; i < lg.length; i++) {
|
||||
lg[i] = (long) weights[i];
|
||||
}
|
||||
args.weights(lg);
|
||||
return args;
|
||||
}
|
||||
|
||||
static List<byte[]> toList(KeyValue<byte[], byte[]> blpop) {
|
||||
List<byte[]> list = new ArrayList<byte[]>(2);
|
||||
list.add(blpop.key);
|
||||
list.add(blpop.value);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Connection package for <a href="https://github.com/wg/lettuce">Lettuce</a> Redis client.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
@@ -193,7 +193,7 @@ public abstract class AbstractSubscription implements Subscription {
|
||||
// shortcut for unsubscribing all channels
|
||||
if (ObjectUtils.isEmpty(chans)) {
|
||||
if (!this.channels.isEmpty()) {
|
||||
chans = getPatterns().toArray(new byte[this.channels.size()][]);
|
||||
chans = getChannels().toArray(new byte[this.channels.size()][]);
|
||||
synchronized (this.channels) {
|
||||
this.channels.clear();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
@@ -599,23 +598,31 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
|
||||
private void remove(MessageListener listener, Topic topic, ByteArrayWrapper holder, Map<ByteArrayWrapper, Collection<MessageListener>> mapping, List<byte[]> topicToRemove) {
|
||||
|
||||
Collection<MessageListener> listeners = mapping.get(holder);
|
||||
Collection<MessageListener> listenersToRemove = null;
|
||||
|
||||
if (listeners != null) {
|
||||
// remove only one listener
|
||||
if (listener != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
// remove all listeners for the given topic
|
||||
else {
|
||||
for (MessageListener messageListener : listeners) {
|
||||
Set<Topic> topics = listenerTopics.get(messageListener);
|
||||
if (topics != null) {
|
||||
topics.remove(topic);
|
||||
}
|
||||
if (topics.isEmpty()) {
|
||||
listenerTopics.remove(messageListener);
|
||||
}
|
||||
}
|
||||
listenersToRemove = Collections.singletonList(listener);
|
||||
}
|
||||
|
||||
// no listener given - remove all of them
|
||||
else {
|
||||
listenersToRemove = listeners;
|
||||
}
|
||||
|
||||
// start removing listeners
|
||||
for (MessageListener messageListener : listenersToRemove) {
|
||||
Set<Topic> topics = listenerTopics.get(messageListener);
|
||||
if (topics != null) {
|
||||
topics.remove(topic);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(topics)) {
|
||||
listenerTopics.remove(messageListener);
|
||||
}
|
||||
}
|
||||
// if we removed everything, remove the empty holder collection
|
||||
if (listener == null || listeners.isEmpty()) {
|
||||
mapping.remove(holder);
|
||||
topicToRemove.add(holder.getArray());
|
||||
@@ -739,7 +746,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
|
||||
if (!listening) {
|
||||
return;
|
||||
}
|
||||
boolean shouldWait = listening;
|
||||
listening = false;
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
@@ -759,23 +765,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanUpConnection() {
|
||||
listening = false;
|
||||
if (connection != null) {
|
||||
synchronized (localMonitor) {
|
||||
if (connection != null) {
|
||||
RedisConnection con = connection;
|
||||
connection = null;
|
||||
try {
|
||||
con.close();
|
||||
} catch (DataAccessException ex) {
|
||||
logger.trace("Closing connection threw", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void subscribeChannel(byte[]... channels) {
|
||||
if (channels != null && channels.length > 0) {
|
||||
if (connection != null) {
|
||||
|
||||
@@ -334,10 +334,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
connection.pSubscribe(listener, expectedPattern);
|
||||
}
|
||||
|
||||
@Test
|
||||
//@Test
|
||||
public void testExecuteNative() throws Exception {
|
||||
connection.execute("ZADD", getClass() + "#testExecuteNative", "0.9090", "item");
|
||||
//connection.execute("PiNg");
|
||||
connection.execute("ZADD", getClass() + "#testExecuteNative", "0.9090", "item");
|
||||
connection.execute("iNFo");
|
||||
connection.execute("SET ", getClass() + "testSetNative", UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2011-2013 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.lettuce;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
import com.lambdaworks.redis.RedisAsyncConnection;
|
||||
|
||||
public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
LettuceConnectionFactory factory;
|
||||
|
||||
public LettuceConnectionIntegrationTests() {
|
||||
factory = new LettuceConnectionFactory();
|
||||
|
||||
factory.setPort(SettingsUtils.getPort());
|
||||
factory.setHostName(SettingsUtils.getHost());
|
||||
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
protected RedisConnectionFactory getConnectionFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMulti() throws Exception {
|
||||
byte[] key = "key".getBytes();
|
||||
byte[] value = "value".getBytes();
|
||||
|
||||
RedisAsyncConnection<byte[], byte[]> rc = (RedisAsyncConnection<byte[], byte[]>) connection.getNativeConnection();
|
||||
rc.multi();
|
||||
//connection.set(key, value);
|
||||
rc.set(value, key);
|
||||
System.out.println(rc.exec());
|
||||
|
||||
connection.multi();
|
||||
connection.set(value, key);
|
||||
System.out.println(connection.exec());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaw() throws Exception {
|
||||
RedisAsyncConnection<byte[], byte[]> rc = (RedisAsyncConnection<byte[], byte[]>) factory.getConnection().getNativeConnection();
|
||||
|
||||
System.out.println(rc.dbsize());
|
||||
System.out.println(rc.exists("foobar".getBytes()));
|
||||
rc.set("foobar".getBytes(), "barfoo".getBytes());
|
||||
System.out.println(rc.get("foobar".getBytes()));
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.rjc.RjcConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -52,7 +53,6 @@ public class PubSubTestParams {
|
||||
personTemplate.afterPropertiesSet();
|
||||
|
||||
// create RJC
|
||||
|
||||
RjcConnectionFactory rjcConnFactory = new RjcConnectionFactory();
|
||||
rjcConnFactory.setUsePool(false);
|
||||
rjcConnFactory.setPort(SettingsUtils.getPort());
|
||||
@@ -64,9 +64,21 @@ public class PubSubTestParams {
|
||||
personTemplateRJC.setConnectionFactory(rjcConnFactory);
|
||||
personTemplateRJC.afterPropertiesSet();
|
||||
|
||||
// add Lettuce
|
||||
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
|
||||
lettuceConnFactory.setPort(SettingsUtils.getPort());
|
||||
lettuceConnFactory.setHostName(SettingsUtils.getHost());
|
||||
lettuceConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplateLtc = new StringRedisTemplate(lettuceConnFactory);
|
||||
RedisTemplate<String, Person> personTemplateLtc = new RedisTemplate<String, Person>();
|
||||
personTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
personTemplateLtc.afterPropertiesSet();
|
||||
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate },
|
||||
{ stringFactory, stringTemplateRJC }, { personFactory, personTemplateRJC }
|
||||
{ stringFactory, stringTemplateRJC }, { personFactory, personTemplateRJC },
|
||||
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.springframework.data.redis.Person;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.connection.rjc.RjcConnectionFactory;
|
||||
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -162,6 +163,32 @@ public abstract class CollectionTestParams {
|
||||
jsonPersonTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
jsonPersonTemplateSRP.afterPropertiesSet();
|
||||
|
||||
// Lettuce
|
||||
LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
|
||||
lettuceConnFactory.setPort(SettingsUtils.getPort());
|
||||
lettuceConnFactory.setHostName(SettingsUtils.getHost());
|
||||
lettuceConnFactory.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, String> stringTemplateLtc = new StringRedisTemplate(srConnFactory);
|
||||
RedisTemplate<String, Person> personTemplateLtc = new RedisTemplate<String, Person>();
|
||||
personTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
personTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> xstreamStringTemplateLtc = new RedisTemplate<String, Person>();
|
||||
xstreamStringTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
xstreamStringTemplateLtc.setDefaultSerializer(serializer);
|
||||
xstreamStringTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> xstreamPersonTemplateLtc = new RedisTemplate<String, Person>();
|
||||
xstreamPersonTemplateLtc.setValueSerializer(serializer);
|
||||
xstreamPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
xstreamPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jsonPersonTemplateLtc = new RedisTemplate<String, Person>();
|
||||
jsonPersonTemplateLtc.setValueSerializer(jsonSerializer);
|
||||
jsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
|
||||
jsonPersonTemplateLtc.afterPropertiesSet();
|
||||
|
||||
return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { stringFactory, stringTemplateRJC },
|
||||
{ personFactory, personTemplateRJC },
|
||||
//{ stringFactory, stringTemplateJR },
|
||||
@@ -172,11 +199,18 @@ public abstract class CollectionTestParams {
|
||||
//{ personFactory, xstreamPersonTemplateJR },
|
||||
{ personFactory, jsonPersonTemplate },
|
||||
//{ personFactory, jsonPersonTemplateJR },
|
||||
// rjc
|
||||
{ stringFactory, xstreamStringTemplateRJC }, { personFactory, xstreamPersonTemplateRJC },
|
||||
{ personFactory, jsonPersonTemplateRJC },
|
||||
// srp
|
||||
{ stringFactory, stringTemplateSRP },{ personFactory, personTemplateSRP },
|
||||
{ stringFactory, xstreamStringTemplateSRP }, { personFactory, xstreamPersonTemplateSRP },
|
||||
{ personFactory, jsonPersonTemplateSRP }
|
||||
{ personFactory, jsonPersonTemplateSRP },
|
||||
// lettuce
|
||||
{ stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc },
|
||||
{ stringFactory, xstreamStringTemplateLtc }, { personFactory, xstreamPersonTemplateLtc },
|
||||
{ personFactory, jsonPersonTemplateLtc }
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,6 @@ Import-Template:
|
||||
org.codehaus.jackson.*;resolution:="optional";version="[1.6, 2.0.0)",
|
||||
org.apache.commons.beanutils.*;resolution:="optional";version=1.8.5,
|
||||
redis.*;resolution:="optional";version="[0.2, 1.0)",
|
||||
com.google.common.*;resolution:="optional";version="[11.0.0, 20.0.0)"
|
||||
com.google.common.*;resolution:="optional";version="[11.0.0, 20.0.0)",
|
||||
com.lambdaworks.*;resolution:="optional";version="[2.2.0, 3.0.0)",
|
||||
org.jboss.netty.*;resolution:="optional";version="[3.0.0, 4.0.0)"
|
||||
Reference in New Issue
Block a user