Merge remote-tracking branch 'origin/feature/travis-ci' into feature/travis-ci

# Conflicts:
#	.travis.yml
pull/509/head
jackygurui 9 years ago
commit 06361b775d

@ -38,4 +38,4 @@ before_script:
- export REDIS_VERSION="$(redis-cli INFO SERVER | sed -n 2p)"
- echo $REDIS_VERSION
- redis-cli SHUTDOWN NOSAVE
script: mvn -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true -server -Dorg.slf4j.simpleLogger.defaultLogLevel=trace -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.sss" -Punit-test clean verify
script: mvn -Dsurefire.rerunFailingTestsCount=5 -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true -server -Dorg.slf4j.simpleLogger.defaultLogLevel=trace -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.sss" -Punit-test clean verify

@ -1,107 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>test</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>test</goal>
</goals>
<properties>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>test.single</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>test-compile</goal>
<goal>surefire:test</goal>
</goals>
<properties>
<test>${packageClassName}</test>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>run.single.main</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath ${packageClassName}</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>${classPathScope}</exec.classpathScope>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>debug</actionName>
<properties>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>debug.single.main</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName}</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>${classPathScope}</exec.classpathScope>
<jpda.listen>true</jpda.listen>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>debug.test.single</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>test-compile</goal>
<goal>surefire:test</goal>
</goals>
<properties>
<test>${packageClassName}</test>
<forkMode>once</forkMode>
<maven.surefire.debug>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</maven.surefire.debug>
<jpda.listen>true</jpda.listen>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>profile</actionName>
<properties>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
<action>
<actionName>profile.single.main</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath ${packageClassName}</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>${classPathScope}</exec.classpathScope>
<argLine>"-DredisBinary=/Applications/EAPManager.app/Contents/Resources/redis/redis-server"</argLine>
</properties>
</action>
</actions>

@ -47,6 +47,7 @@ import org.redisson.core.RBlockingDeque;
import org.redisson.core.RBlockingQueue;
import org.redisson.core.RBloomFilter;
import org.redisson.core.RBucket;
import org.redisson.core.RBuckets;
import org.redisson.core.RCountDownLatch;
import org.redisson.core.RDeque;
import org.redisson.core.RGeo;
@ -202,6 +203,16 @@ public class Redisson implements RedissonClient {
return new RedissonBucket<V>(codec, commandExecutor, name);
}
@Override
public RBuckets getBuckets() {
return new RedissonBuckets(this, commandExecutor);
}
@Override
public RBuckets getBuckets(Codec codec) {
return new RedissonBuckets(this, codec, commandExecutor);
}
@Override
public <V> List<RBucket<V>> findBuckets(String pattern) {
Collection<String> keys = commandExecutor.get(commandExecutor.<List<String>, String>readAllAsync(RedisCommands.KEYS, pattern));
@ -260,11 +271,6 @@ public class Redisson implements RedissonClient {
commandExecutor.write(params.get(0).toString(), RedisCommands.MSET, params.toArray());
}
@Override
public <V> List<RBucket<V>> getBuckets(String pattern) {
return findBuckets(pattern);
}
@Override
public <V> RHyperLogLog<V> getHyperLogLog(String name) {
return new RedissonHyperLogLog<V>(commandExecutor, name);
@ -537,16 +543,6 @@ public class Redisson implements RedissonClient {
return new RedisNodes<ClusterNode>(connectionManager);
}
@Override
public void flushdb() {
commandExecutor.get(commandExecutor.writeAllAsync(RedisCommands.FLUSHDB));
}
@Override
public void flushall() {
commandExecutor.get(commandExecutor.writeAllAsync(RedisCommands.FLUSHALL));
}
@Override
public boolean isShutdown() {
return connectionManager.isShutdown();

@ -0,0 +1,118 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* 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.redisson;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DelegateDecoderCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommand.ValueType;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.connection.decoder.MapGetAllDecoder;
import org.redisson.core.RBucket;
import org.redisson.core.RBuckets;
import io.netty.util.concurrent.Future;
public class RedissonBuckets implements RBuckets {
private final Codec codec;
private final CommandExecutor commandExecutor;
private final Redisson redisson;
public RedissonBuckets(Redisson redisson, CommandExecutor commandExecutor) {
this(redisson, commandExecutor.getConnectionManager().getCodec(), commandExecutor);
}
public RedissonBuckets(Redisson redisson, Codec codec, CommandExecutor commandExecutor) {
super();
this.codec = codec;
this.commandExecutor = commandExecutor;
this.redisson = redisson;
}
@Override
public <V> List<RBucket<V>> find(String pattern) {
Collection<String> keys = commandExecutor.get(commandExecutor.<List<String>, String>readAllAsync(RedisCommands.KEYS, pattern));
List<RBucket<V>> buckets = new ArrayList<RBucket<V>>(keys.size());
for (String key : keys) {
if(key == null) {
continue;
}
buckets.add(redisson.<V>getBucket(key, codec));
}
return buckets;
}
@Override
public <V> Map<String, V> get(String... keys) {
if (keys.length == 0) {
return Collections.emptyMap();
}
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("MGET", new MapGetAllDecoder(Arrays.<Object>asList(keys), 0), ValueType.OBJECTS);
Future<Map<String, V>> future = commandExecutor.readAsync(keys[0], new DelegateDecoderCodec(codec), command, keys);
return commandExecutor.get(future);
}
@Override
public boolean trySet(Map<String, ?> buckets) {
if (buckets.isEmpty()) {
return false;
}
List<Object> params = new ArrayList<Object>(buckets.size());
for (Entry<String, ?> entry : buckets.entrySet()) {
params.add(entry.getKey());
try {
params.add(codec.getValueEncoder().encode(entry.getValue()));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
return commandExecutor.write(params.get(0).toString(), RedisCommands.MSETNX, params.toArray());
}
@Override
public void set(Map<String, ?> buckets) {
if (buckets.isEmpty()) {
return;
}
List<Object> params = new ArrayList<Object>(buckets.size());
for (Entry<String, ?> entry : buckets.entrySet()) {
params.add(entry.getKey());
try {
params.add(codec.getValueEncoder().encode(entry.getValue()));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
commandExecutor.write(params.get(0).toString(), RedisCommands.MSET, params.toArray());
}
}

@ -31,6 +31,7 @@ import org.redisson.core.RBlockingDeque;
import org.redisson.core.RBlockingQueue;
import org.redisson.core.RBloomFilter;
import org.redisson.core.RBucket;
import org.redisson.core.RBuckets;
import org.redisson.core.RCountDownLatch;
import org.redisson.core.RDeque;
import org.redisson.core.RGeo;
@ -151,57 +152,43 @@ public interface RedissonClient {
<V> RBucket<V> getBucket(String name, Codec codec);
/**
* <p>Returns a list of object holder instances by a key pattern.
* Returns interface for mass operations with Bucket objects.
*
* <pre>Supported glob-style patterns:
* h?llo subscribes to hello, hallo and hxllo
* h*llo subscribes to hllo and heeeello
* h[ae]llo subscribes to hello and hallo, but not hillo
* h[^e]llo matches hallo, hbllo, ... but not hello
* h[a-b]llo matches hallo and hbllo</pre>
* <p>Use \ to escape special characters if you want to match them verbatim.
*
* <p>Uses <code>KEYS</code> Redis command.
*
* @param pattern
* @return
*/
<V> List<RBucket<V>> findBuckets(String pattern);
RBuckets getBuckets();
/**
* <p>Returns Redis object mapped by key. Result Map is not contains
* key-value entry for null values.
*
* <p>Uses <code>MGET</code> Redis command.
* Returns interface for mass operations with Bucket objects
* using provided codec for object.
*
* @param keys
* @return
*/
<V> Map<String, V> loadBucketValues(Collection<String> keys);
RBuckets getBuckets(Codec codec);
/**
* <p>Returns Redis object mapped by key. Result Map is not contains
* key-value entry for null values.
*
* <p>Uses <code>MGET</code> Redis command.
*
* @param keys
* @return
* Use {@link RBuckets#find(String)}
*/
<V> Map<String, V> loadBucketValues(String ... keys);
@Deprecated
<V> List<RBucket<V>> findBuckets(String pattern);
/**
* Saves Redis object mapped by key.
*
* @param buckets
* Use {@link RBuckets#get(String...)}
*/
void saveBuckets(Map<String, ?> buckets);
@Deprecated
<V> Map<String, V> loadBucketValues(Collection<String> keys);
/**
* Use {@link RBuckets#get(String...)}
*/
@Deprecated
<V> Map<String, V> loadBucketValues(String ... keys);
/**
* Use {@link #findBuckets(String)}
* Use {@link RBuckets#set(Map)}
*/
@Deprecated
<V> List<RBucket<V>> getBuckets(String pattern);
void saveBuckets(Map<String, ?> buckets);
/**
* Returns HyperLogLog instance by name.
@ -658,18 +645,6 @@ public interface RedissonClient {
*/
NodesGroup<ClusterNode> getClusterNodesGroup();
/**
* Use {@link RKeys#flushdb()}
*/
@Deprecated
void flushdb();
/**
* Use {@link RKeys#flushall()}
*/
@Deprecated
void flushall();
/**
* Returns {@code true} if this Redisson instance has been shut down.
*

@ -104,7 +104,7 @@ public class RedissonGeo<V> extends RedissonExpirable implements RGeo<V> {
List<Object> params = new ArrayList<Object>(members.length + 1);
params.add(getName());
params.addAll(Arrays.asList(members));
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder(params), 2, ValueType.OBJECTS);
RedisCommand<Map<Object, Object>> command = new RedisCommand<Map<Object, Object>>("GEOHASH", new MapGetAllDecoder(params, 1), 2, ValueType.OBJECTS);
return commandExecutor.readAsync(getName(), new ScoredCodec(codec), command, params.toArray());
}

@ -32,14 +32,29 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
super(StringCodec.INSTANCE, commandExecutor, name);
}
@Override
public int removeRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
return removeRangeByLex(fromElement, fromInclusive, toElement, toInclusive);
}
@Override
public int removeRangeByLex(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
return get(removeRangeByLexAsync(fromElement, fromInclusive, toElement, toInclusive));
return get(removeRangeAsync(fromElement, fromInclusive, toElement, toInclusive));
}
@Override
public int removeRangeHead(String toElement, boolean toInclusive) {
return removeRangeHeadByLex(toElement, toInclusive);
}
@Override
public int removeRangeHeadByLex(String toElement, boolean toInclusive) {
return get(removeRangeHeadByLexAsync(toElement, toInclusive));
return get(removeRangeHeadAsync(toElement, toInclusive));
}
@Override
public Future<Integer> removeRangeHeadAsync(String toElement, boolean toInclusive) {
return removeRangeHeadByLexAsync(toElement, toInclusive);
}
@Override
@ -48,9 +63,19 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), "-", toValue);
}
@Override
public int removeRangeTail(String fromElement, boolean fromInclusive) {
return removeRangeTailByLex(fromElement, fromInclusive);
}
@Override
public int removeRangeTailByLex(String fromElement, boolean fromInclusive) {
return get(removeRangeTailByLexAsync(fromElement, fromInclusive));
return get(removeRangeTailAsync(fromElement, fromInclusive));
}
@Override
public Future<Integer> removeRangeTailAsync(String fromElement, boolean fromInclusive) {
return removeRangeTailByLexAsync(fromElement, fromInclusive);
}
@Override
@ -59,6 +84,12 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, "+");
}
@Override
public Future<Integer> removeRangeAsync(String fromElement, boolean fromInclusive, String toElement,
boolean toInclusive) {
return removeRangeByLexAsync(fromElement, fromInclusive, toElement, toInclusive);
}
@Override
public Future<Integer> removeRangeByLexAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
String fromValue = value(fromElement, fromInclusive);
@ -67,14 +98,29 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, toValue);
}
@Override
public Collection<String> range(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
return lexRange(fromElement, fromInclusive, toElement, toInclusive);
}
@Override
public Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive));
return get(rangeAsync(fromElement, fromInclusive, toElement, toInclusive));
}
@Override
public Collection<String> rangeHead(String toElement, boolean toInclusive) {
return lexRangeHead(toElement, toInclusive);
}
@Override
public Collection<String> lexRangeHead(String toElement, boolean toInclusive) {
return get(lexRangeHeadAsync(toElement, toInclusive));
return get(rangeHeadAsync(toElement, toInclusive));
}
@Override
public Future<Collection<String>> rangeHeadAsync(String toElement, boolean toInclusive) {
return lexRangeHeadAsync(toElement, toInclusive);
}
@Override
@ -83,9 +129,19 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue);
}
@Override
public Collection<String> rangeTail(String fromElement, boolean fromInclusive) {
return lexRangeTail(fromElement, fromInclusive);
}
@Override
public Collection<String> lexRangeTail(String fromElement, boolean fromInclusive) {
return get(lexRangeTailAsync(fromElement, fromInclusive));
return get(rangeTailAsync(fromElement, fromInclusive));
}
@Override
public Future<Collection<String>> rangeTailAsync(String fromElement, boolean fromInclusive) {
return lexRangeTailAsync(fromElement, fromInclusive);
}
@Override
@ -94,6 +150,11 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+");
}
@Override
public Future<Collection<String>> rangeAsync(String fromElement, boolean fromInclusive, String toElement,
boolean toInclusive) {
return lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive);
}
@Override
public Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
@ -103,14 +164,30 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue);
}
@Override
public Collection<String> range(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive,
int offset, int count) {
return lexRange(fromElement, fromInclusive, toElement, toInclusive, offset, count);
}
@Override
public Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count) {
return get(lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive, offset, count));
return get(rangeAsync(fromElement, fromInclusive, toElement, toInclusive, offset, count));
}
@Override
public Collection<String> rangeHead(String toElement, boolean toInclusive, int offset, int count) {
return lexRangeHead(toElement, toInclusive, offset, count);
}
@Override
public Collection<String> lexRangeHead(String toElement, boolean toInclusive, int offset, int count) {
return get(lexRangeHeadAsync(toElement, toInclusive, offset, count));
return get(rangeHeadAsync(toElement, toInclusive, offset, count));
}
@Override
public Future<Collection<String>> rangeHeadAsync(String toElement, boolean toInclusive, int offset, int count) {
return lexRangeHeadAsync(toElement, toInclusive, offset, count);
}
@Override
@ -119,9 +196,19 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), "-", toValue, "LIMIT", offset, count);
}
@Override
public Collection<String> rangeTail(String fromElement, boolean fromInclusive, int offset, int count) {
return lexRangeTail(fromElement, fromInclusive, offset, count);
}
@Override
public Collection<String> lexRangeTail(String fromElement, boolean fromInclusive, int offset, int count) {
return get(lexRangeTailAsync(fromElement, fromInclusive, offset, count));
return get(rangeTailAsync(fromElement, fromInclusive, offset, count));
}
@Override
public Future<Collection<String>> rangeTailAsync(String fromElement, boolean fromInclusive, int offset, int count) {
return lexRangeTailAsync(fromElement, fromInclusive, offset, count);
}
@Override
@ -130,6 +217,12 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, "+", "LIMIT", offset, count);
}
@Override
public Future<Collection<String>> rangeAsync(String fromElement, boolean fromInclusive, String toElement,
boolean toInclusive, int offset, int count) {
return lexRangeAsync(fromElement, fromInclusive, toElement, toInclusive, offset, count);
}
@Override
public Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count) {
String fromValue = value(fromElement, fromInclusive);
@ -138,9 +231,19 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZRANGEBYLEX, getName(), fromValue, toValue, "LIMIT", offset, count);
}
@Override
public int countTail(String fromElement, boolean fromInclusive) {
return lexCountTail(fromElement, fromInclusive);
}
@Override
public int lexCountTail(String fromElement, boolean fromInclusive) {
return get(lexCountTailAsync(fromElement, fromInclusive));
return get(countTailAsync(fromElement, fromInclusive));
}
@Override
public Future<Integer> countTailAsync(String fromElement, boolean fromInclusive) {
return lexCountTailAsync(fromElement, fromInclusive);
}
@Override
@ -150,9 +253,19 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZLEXCOUNT, getName(), fromValue, "+");
}
@Override
public int countHead(String toElement, boolean toInclusive) {
return lexCountHead(toElement, toInclusive);
}
@Override
public int lexCountHead(String toElement, boolean toInclusive) {
return get(lexCountHeadAsync(toElement, toInclusive));
return get(countHeadAsync(toElement, toInclusive));
}
@Override
public Future<Integer> countHeadAsync(String toElement, boolean toInclusive) {
return lexCountHeadAsync(toElement, toInclusive);
}
@Override
@ -162,9 +275,20 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZLEXCOUNT, getName(), "-", toValue);
}
@Override
public int count(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
return lexCount(fromElement, fromInclusive, toElement, toInclusive);
}
@Override
public int lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive) {
return get(lexCountAsync(fromElement, fromInclusive, toElement, toInclusive));
return get(countAsync(fromElement, fromInclusive, toElement, toInclusive));
}
@Override
public Future<Integer> countAsync(String fromElement, boolean fromInclusive, String toElement,
boolean toInclusive) {
return lexCountAsync(fromElement, fromInclusive, toElement, toInclusive);
}
@Override
@ -192,6 +316,9 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
@Override
public Future<Boolean> addAllAsync(Collection<? extends String> c) {
if (c.isEmpty()) {
return newSucceededFuture(false);
}
List<Object> params = new ArrayList<Object>(2*c.size());
for (Object param : c) {
params.add(0);
@ -210,4 +337,14 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
return get(addAllAsync(c));
}
@Override
public Collection<String> range(int startIndex, int endIndex) {
return valueRange(startIndex, endIndex);
}
@Override
public Future<Collection<String>> rangeAsync(int startIndex, int endIndex) {
return valueRangeAsync(startIndex, endIndex);
}
}

@ -130,7 +130,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
List<Object> args = new ArrayList<Object>(keys.size() + 1);
args.add(getName());
args.addAll(keys);
return commandExecutor.readAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("HMGET", new MapGetAllDecoder(args), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE), args.toArray());
return commandExecutor.readAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("HMGET", new MapGetAllDecoder(args, 1), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE), args.toArray());
}
@Override

@ -162,11 +162,11 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
return newSucceededFuture(Collections.<K, V>emptyMap());
}
List<Object> args = new ArrayList<Object>(keys.size() + 2);
List<Object> args = new ArrayList<Object>(keys.size() + 1);
args.add(System.currentTimeMillis());
args.addAll(keys);
return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("EVAL", new MapGetAllDecoder(args), 7, ValueType.MAP_KEY, ValueType.MAP_VALUE),
return commandExecutor.evalWriteAsync(getName(), codec, new RedisCommand<Map<Object, Object>>("EVAL", new MapGetAllDecoder(args, 1), 7, ValueType.MAP_KEY, ValueType.MAP_VALUE),
"local expireHead = redis.call('zrange', KEYS[2], 0, 0, 'withscores');" +
"local expireIdleHead = redis.call('zrange', KEYS[3], 0, 0, 'withscores');" +
"local maxDate = table.remove(ARGV, 1); " // index is the first parameter

@ -121,6 +121,9 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
@Override
public Future<Long> addAllAsync(Map<V, Double> objects) {
if (objects.isEmpty()) {
return newSucceededFuture(0L);
}
List<Object> params = new ArrayList<Object>(objects.size()*2+1);
params.add(getName());
try {

@ -0,0 +1,34 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* 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.redisson.client.codec;
import org.redisson.client.protocol.Decoder;
public class DelegateDecoderCodec extends StringCodec {
private final Codec delegate;
public DelegateDecoderCodec(Codec delegate) {
super();
this.delegate = delegate;
}
@Override
public Decoder<Object> getValueDecoder() {
return delegate.getValueDecoder();
}
}

@ -196,6 +196,7 @@ public interface RedisCommands {
RedisStrictCommand<List<String>> KEYS = new RedisStrictCommand<List<String>>("KEYS", new StringListReplayDecoder());
RedisCommand<List<Object>> MGET = new RedisCommand<List<Object>>("MGET", new ObjectListReplayDecoder<Object>());
RedisStrictCommand<Void> MSET = new RedisStrictCommand<Void>("MSET", new VoidReplayConvertor());
RedisStrictCommand<Boolean> MSETNX = new RedisStrictCommand<Boolean>("MSETNX", new BooleanReplayConvertor());
RedisCommand<Boolean> HSETNX = new RedisCommand<Boolean>("HSETNX", new BooleanReplayConvertor(), 2, ValueType.MAP);
RedisCommand<Boolean> HSET = new RedisCommand<Boolean>("HSET", new BooleanReplayConvertor(), 2, ValueType.MAP);

@ -25,7 +25,6 @@ import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>> {
@ -40,7 +39,6 @@ public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>>
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
System.out.println("1 " + buf.toString(CharsetUtil.UTF_8));
if (pos.get() % 2 == 0) {
return codec.getValueDecoder().decode(buf, state);
}
@ -55,7 +53,6 @@ public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>>
@Override
public Map<Object, Object> decode(List<Object> parts, State state) {
System.out.println(parts);
Map<Object, Object> result = new HashMap<Object, Object>(parts.size()/2);
for (int i = 0; i < parts.size(); i++) {
if (i % 2 != 0) {

@ -28,10 +28,12 @@ import io.netty.buffer.ByteBuf;
public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
private final int shiftIndex;
private final List<Object> args;
public MapGetAllDecoder(List<Object> args) {
public MapGetAllDecoder(List<Object> args, int shiftIndex) {
this.args = args;
this.shiftIndex = shiftIndex;
}
@Override
@ -50,12 +52,12 @@ public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
return Collections.emptyMap();
}
Map<Object, Object> result = new HashMap<Object, Object>(parts.size());
for (int index = 0; index < args.size()-1; index++) {
for (int index = 0; index < args.size()-shiftIndex; index++) {
Object value = parts.get(index);
if (value == null) {
continue;
}
result.put(args.get(index+1), value);
result.put(args.get(index+shiftIndex), value);
}
return result;
}

@ -0,0 +1,64 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* 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.redisson.core;
import java.util.List;
import java.util.Map;
public interface RBuckets {
/**
* <p>Returns a list of object holder instances by a key pattern.
*
* <pre>Supported glob-style patterns:
* h?llo subscribes to hello, hallo and hxllo
* h*llo subscribes to hllo and heeeello
* h[ae]llo subscribes to hello and hallo, but not hillo
* h[^e]llo matches hallo, hbllo, ... but not hello
* h[a-b]llo matches hallo and hbllo</pre>
* <p>Use \ to escape special characters if you want to match them verbatim.
*
* @param pattern
* @return
*/
<V> List<RBucket<V>> find(String pattern);
/**
* Returns Redis object mapped by key. Result Map is not contains
* key-value entry for null values.
*
* @param keys
* @return
*/
<V> Map<String, V> get(String ... keys);
/**
* Try to save objects mapped by Redis key.
* If at least one of them is already exist then
* don't set none of them.
*
* @param buckets
*/
boolean trySet(Map<String, ?> buckets);
/**
* Saves objects mapped by Redis key.
*
* @param buckets
*/
void set(Map<String, ?> buckets);
}

@ -20,32 +20,110 @@ import java.util.Set;
public interface RLexSortedSet extends RLexSortedSetAsync, Set<String>, RExpirable {
int removeRangeTail(String fromElement, boolean fromInclusive);
/**
* Use {@link RLexSortedSet#removeRangeTail(String, boolean)}
*/
@Deprecated
int removeRangeTailByLex(String fromElement, boolean fromInclusive);
int removeRangeHead(String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSet#removeRangeHead(String, boolean)}
*/
@Deprecated
int removeRangeHeadByLex(String toElement, boolean toInclusive);
int removeRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSet#removeRange(String, boolean)}
*/
@Deprecated
int removeRangeByLex(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
int countTail(String fromElement, boolean fromInclusive);
/**
* Use {@link RLexSortedSet#countTail(String, boolean)}
*/
@Deprecated
int lexCountTail(String fromElement, boolean fromInclusive);
int countHead(String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSet#countHead(String, boolean)}
*/
@Deprecated
int lexCountHead(String toElement, boolean toInclusive);
Collection<String> rangeTail(String fromElement, boolean fromInclusive);
/**
* Use {@link RLexSortedSet#rangeTail(String, boolean)}
*/
@Deprecated
Collection<String> lexRangeTail(String fromElement, boolean fromInclusive);
Collection<String> rangeHead(String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSet#rangeHead(String, boolean)}
*/
@Deprecated
Collection<String> lexRangeHead(String toElement, boolean toInclusive);
Collection<String> range(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSet#range(String, boolean, String, boolean)}
*/
@Deprecated
Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
Collection<String> rangeTail(String fromElement, boolean fromInclusive, int offset, int count);
/**
* Use {@link RLexSortedSet#rangeTail(String, boolean, int, int)}
*/
@Deprecated
Collection<String> lexRangeTail(String fromElement, boolean fromInclusive, int offset, int count);
Collection<String> rangeHead(String toElement, boolean toInclusive, int offset, int count);
/**
* Use {@link RLexSortedSet#rangeHead(String, boolean, int, int)}
*/
@Deprecated
Collection<String> lexRangeHead(String toElement, boolean toInclusive, int offset, int count);
Collection<String> range(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count);
/**
* Use {@link RLexSortedSet#range(String, boolean, String, boolean, int, int)}
*/
@Deprecated
Collection<String> lexRange(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count);
int count(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSet#count(String, boolean, String, boolean)}
*/
@Deprecated
int lexCount(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
int rank(String o);
Collection<String> range(int startIndex, int endIndex);
/**
* Use {@link RLexSortedSet#range(int, int)}
*/
@Deprecated
Collection<String> valueRange(int startIndex, int endIndex);
}

@ -21,32 +21,110 @@ import io.netty.util.concurrent.Future;
public interface RLexSortedSetAsync extends RCollectionAsync<String> {
Future<Integer> removeRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSetAsync#removeRangeAsync(String, boolean, String, boolean)}
*/
@Deprecated
Future<Integer> removeRangeByLexAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
Future<Integer> removeRangeTailAsync(String fromElement, boolean fromInclusive);
/**
* Use {@link RLexSortedSetAsync#removeRangeTailAsync(String, boolean, String, boolean)}
*/
@Deprecated
Future<Integer> removeRangeTailByLexAsync(String fromElement, boolean fromInclusive);
Future<Integer> removeRangeHeadAsync(String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSetAsync#removeRangeHeadAsync(String, boolean)}
*/
@Deprecated
Future<Integer> removeRangeHeadByLexAsync(String toElement, boolean toInclusive);
Future<Integer> countTailAsync(String fromElement, boolean fromInclusive);
/**
* Use {@link RLexSortedSetAsync#countTailAsync(String, boolean)}
*/
@Deprecated
Future<Integer> lexCountTailAsync(String fromElement, boolean fromInclusive);
Future<Integer> countHeadAsync(String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSetAsync#countHeadAsync(String, boolean)}
*/
@Deprecated
Future<Integer> lexCountHeadAsync(String toElement, boolean toInclusive);
Future<Collection<String>> rangeTailAsync(String fromElement, boolean fromInclusive);
/**
* Use {@link RLexSortedSetAsync#rangeTailAsync(String, boolean)}
*/
@Deprecated
Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive);
Future<Collection<String>> rangeHeadAsync(String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSetAsync#rangeHeadAsync(String, boolean)}
*/
@Deprecated
Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive);
Future<Collection<String>> rangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSetAsync#rangeAsync(String, boolean, String, boolean)}
*/
@Deprecated
Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
Future<Collection<String>> rangeTailAsync(String fromElement, boolean fromInclusive, int offset, int count);
/**
* Use {@link RLexSortedSetAsync#rangeTailAsync(String, boolean, int, int)}
*/
@Deprecated
Future<Collection<String>> lexRangeTailAsync(String fromElement, boolean fromInclusive, int offset, int count);
Future<Collection<String>> rangeHeadAsync(String toElement, boolean toInclusive, int offset, int count);
/**
* Use {@link RLexSortedSetAsync#rangeHeadAsync(String, boolean, int, int)}
*/
@Deprecated
Future<Collection<String>> lexRangeHeadAsync(String toElement, boolean toInclusive, int offset, int count);
Future<Collection<String>> rangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count);
/**
* Use {@link RLexSortedSetAsync#rangeAsync(String, boolean, String, boolean, int, int)}
*/
@Deprecated
Future<Collection<String>> lexRangeAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive, int offset, int count);
Future<Integer> countAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
/**
* Use {@link RLexSortedSetAsync#countAsync(String, boolean, String, boolean)}
*/
@Deprecated
Future<Integer> lexCountAsync(String fromElement, boolean fromInclusive, String toElement, boolean toInclusive);
Future<Integer> rankAsync(String o);
Future<Collection<String>> rangeAsync(int startIndex, int endIndex);
/**
* Use {@link RLexSortedSetAsync#rangeAsync(int, int)}
*/
@Deprecated
Future<Collection<String>> valueRangeAsync(int startIndex, int endIndex);
}

@ -34,12 +34,12 @@ import org.junit.Before;
public class RedisClientTest {
@Before
public static void before() throws IOException, InterruptedException {
public void before() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisTestInstance();
}
@After
public static void after() throws InterruptedException {
public void after() throws InterruptedException {
RedisRunner.shutDownDefaultRedisTestInstance();
}

@ -222,14 +222,14 @@ public class RedisRunner {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
try {
while (p.isAlive() && (line = reader.readLine()) != null) {
while (p.isAlive() && (line = reader.readLine()) != null && !"true".equalsIgnoreCase(System.getProperty("travisEnv"))) {
System.out.println("REDIS PROCESS: " + line);
}
} catch (IOException ex) {
System.out.println("Exception: " + ex.getLocalizedMessage());
}
}).start();
Thread.sleep(3000);
Thread.sleep(1500);
return new RedisProcess(p, runner);
}
@ -681,7 +681,7 @@ public class RedisRunner {
public boolean deleteDBfileDir() {
File f = new File(defaultDir);
if (f.exists()) {
System.out.println("RedisRunner: Deleting directory " + defaultDir);
System.out.println("REDIS RUNNER: Deleting directory " + defaultDir);
return f.delete();
}
return false;
@ -692,7 +692,7 @@ public class RedisRunner {
if (f.exists()) {
makeRandomDefaultDir();
} else {
System.out.println("RedisRunner: Making directory " + f.getAbsolutePath());
System.out.println("REDIS RUNNER: Making directory " + f.getAbsolutePath());
f.mkdirs();
this.defaultDir = f.getAbsolutePath();
}
@ -709,7 +709,7 @@ public class RedisRunner {
}
public int stop() throws InterruptedException {
if (runner.isNosave()) {
if (runner.isNosave() && !runner.isRandomDir()) {
ArrayList<String> b = runner.getBindAddr();
RedisClient c = new RedisClient(b.size() > 0 ? b.get(0) : "localhost", runner.getPort());
c.connect()
@ -736,7 +736,7 @@ public class RedisRunner {
public static RedisRunner.RedisProcess startDefaultRedisTestInstance() throws IOException, InterruptedException {
if (defaultRedisInstance == null) {
System.out.println("REDIS PROCESS: Starting up default instance...");
System.out.println("REDIS RUNNER: Starting up default instance...");
defaultRedisInstance = new RedisRunner().nosave().randomDir().run();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
@ -750,14 +750,14 @@ public class RedisRunner {
public static int shutDownDefaultRedisTestInstance() throws InterruptedException {
if (defaultRedisInstance != null) {
System.out.println("REDIS PROCESS: Shutting down default instance...");
System.out.println("REDIS RUNNER: Shutting down default instance...");
try {
defaultRedisInstanceExitCode = defaultRedisInstance.stop();
} finally {
defaultRedisInstance = null;
}
} else {
System.out.println("REDIS PROCESS: Default instance is already down with an exit code " + defaultRedisInstanceExitCode);
System.out.println("REDIS RUNNER: Default instance is already down with an exit code " + defaultRedisInstanceExitCode);
}
return defaultRedisInstanceExitCode;
}

@ -59,40 +59,11 @@ public class RedissonBucketTest extends BaseTest {
assertThat(r1.trySet("4", 500, TimeUnit.MILLISECONDS)).isFalse();
assertThat(r1.get()).isEqualTo("3");
Thread.sleep(500);
Thread.sleep(1000);
assertThat(r1.get()).isNull();
}
@Test
public void testSaveBuckets() {
Map<String, Integer> buckets = new HashMap<String, Integer>();
buckets.put("12", 1);
buckets.put("41", 2);
redisson.saveBuckets(buckets);
RBucket<Object> r1 = redisson.getBucket("12");
assertThat(r1.get()).isEqualTo(1);
RBucket<Object> r2 = redisson.getBucket("41");
assertThat(r2.get()).isEqualTo(2);
}
@Test
public void testLoadBucketValues() {
RBucket<String> bucket1 = redisson.getBucket("test1");
bucket1.set("someValue1");
RBucket<String> bucket3 = redisson.getBucket("test3");
bucket3.set("someValue3");
Map<String, String> result = redisson.loadBucketValues("test1", "test2", "test3", "test4");
Map<String, String> expected = new HashMap<String, String>();
expected.put("test1", "someValue1");
expected.put("test3", "someValue3");
Assert.assertEquals(expected, result);
}
@Test
public void testExpire() throws InterruptedException {
RBucket<String> bucket = redisson.getBucket("test1");
@ -175,20 +146,4 @@ public class RedissonBucketTest extends BaseTest {
Assert.assertFalse(bucket.isExists());
}
@Test
public void testGetPattern() {
Collection<String> names = Arrays.asList("test:testGetPattern:one", "test:testGetPattern:two");
Collection<String> vals = Arrays.asList("one-val", "two-val");
redisson.getBucket("test:testGetPattern:one").set("one-val");
redisson.getBucket("test:testGetPattern:two").set("two-val");
List<RBucket<String>> buckets = redisson.getBuckets("test:testGetPattern:*");
Assert.assertEquals(2, buckets.size());
Assert.assertTrue(names.contains(buckets.get(0).getName()));
Assert.assertTrue(names.contains(buckets.get(1).getName()));
Assert.assertTrue(vals.contains(buckets.get(0).get()));
Assert.assertTrue(vals.contains(buckets.get(1).get()));
for (RBucket<String> bucket : buckets) {
bucket.delete();
}
}
}

@ -0,0 +1,91 @@
package org.redisson;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.*;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.core.RBucket;
public class RedissonBucketsTest extends BaseTest {
@Test
public void testGet() {
RBucket<String> bucket1 = redisson.getBucket("test1");
bucket1.set("someValue1");
RBucket<String> bucket3 = redisson.getBucket("test3");
bucket3.set("someValue3");
Map<String, String> result = redisson.getBuckets().get("test1", "test2", "test3", "test4");
Map<String, String> expected = new HashMap<String, String>();
expected.put("test1", "someValue1");
expected.put("test3", "someValue3");
Assert.assertEquals(expected, result);
}
@Test
public void testFind() {
Collection<String> names = Arrays.asList("test:testGetPattern:one", "test:testGetPattern:two");
Collection<String> vals = Arrays.asList("one-val", "two-val");
redisson.getBucket("test:testGetPattern:one").set("one-val");
redisson.getBucket("test:testGetPattern:two").set("two-val");
List<RBucket<String>> buckets = redisson.getBuckets().find("test:testGetPattern:*");
Assert.assertEquals(2, buckets.size());
Assert.assertTrue(names.contains(buckets.get(0).getName()));
Assert.assertTrue(names.contains(buckets.get(1).getName()));
Assert.assertTrue(vals.contains(buckets.get(0).get()));
Assert.assertTrue(vals.contains(buckets.get(1).get()));
for (RBucket<String> bucket : buckets) {
bucket.delete();
}
}
@Test
public void testSet() {
Map<String, Integer> buckets = new HashMap<String, Integer>();
buckets.put("12", 1);
buckets.put("41", 2);
redisson.getBuckets().set(buckets);
RBucket<Object> r1 = redisson.getBucket("12");
assertThat(r1.get()).isEqualTo(1);
RBucket<Object> r2 = redisson.getBucket("41");
assertThat(r2.get()).isEqualTo(2);
}
@Test
public void testTrySet() {
redisson.getBucket("12").set("341");
Map<String, Integer> buckets = new HashMap<String, Integer>();
buckets.put("12", 1);
buckets.put("41", 2);
assertThat(redisson.getBuckets().trySet(buckets)).isFalse();
RBucket<Object> r2 = redisson.getBucket("41");
assertThat(r2.get()).isNull();
Map<String, Integer> buckets2 = new HashMap<String, Integer>();
buckets2.put("61", 1);
buckets2.put("41", 2);
assertThat(redisson.getBuckets().trySet(buckets2)).isTrue();
RBucket<Object> r1 = redisson.getBucket("61");
assertThat(r1.get()).isEqualTo(1);
RBucket<Object> r3 = redisson.getBucket("41");
assertThat(r3.get()).isEqualTo(2);
}
}

@ -94,7 +94,7 @@ public class RedissonConcurrentMapTest extends BaseConcurrentTest {
}
assertMapSize(5, name);
redisson.flushdb();
redisson.getKeys().flushdb();
redisson.shutdown();
}

@ -1,16 +1,29 @@
package org.redisson;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.redisson.core.RCountDownLatch;
public class RedissonCountDownLatchConcurrentTest {
@Before
public void before() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisTestInstance();
}
@After
public void after() throws InterruptedException {
RedisRunner.shutDownDefaultRedisTestInstance();
}
@Test
public void testSingleCountDownAwait_SingleInstance() throws InterruptedException {
final int iterations = Runtime.getRuntime().availableProcessors()*3;

@ -0,0 +1,183 @@
package org.redisson;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.redisson.core.GeoEntry;
import org.redisson.core.GeoPosition;
import org.redisson.core.GeoUnit;
import org.redisson.core.RGeo;
public class RedissonGeoTest extends BaseTest {
@Test
public void testAdd() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.add(2.51, 3.12, "city1")).isEqualTo(1);
}
@Test
public void testAddEntries() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.add(new GeoEntry(3.11, 9.10321, "city1"), new GeoEntry(81.1231, 38.65478, "city2"))).isEqualTo(2);
}
@Test
public void testDist() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
assertThat(geo.dist("Palermo", "Catania", GeoUnit.METERS)).isEqualTo(166274.15156960033D);
}
@Test
public void testDistEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.dist("Palermo", "Catania", GeoUnit.METERS)).isNull();
}
@Test
public void testHash() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
Map<String, String> expected = new LinkedHashMap<String, String>();
expected.put("Palermo", "sqc8b49rny0");
expected.put("Catania", "sqdtr74hyu0");
assertThat(geo.hash("Palermo", "Catania")).isEqualTo(expected);
}
@Test
public void testHashEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.hash("Palermo", "Catania")).isEmpty();
}
@Test
public void testPos() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
Map<String, GeoPosition> expected = new LinkedHashMap<String, GeoPosition>();
expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
assertThat(geo.pos("test2", "Palermo", "test3", "Catania", "test1")).isEqualTo(expected);
}
@Test
public void testPosEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.pos("test2", "Palermo", "test3", "Catania", "test1")).isEmpty();
}
@Test
public void testRadius() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS)).containsExactly("Palermo", "Catania");
}
@Test
public void testRadiusEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusWithDistance() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
Map<String, Double> expected = new HashMap<String, Double>();
expected.put("Palermo", 190.4424);
expected.put("Catania", 56.4413);
assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
@Test
public void testRadiusWithDistanceEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusWithPosition() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
Map<String, GeoPosition> expected = new HashMap<String, GeoPosition>();
expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
@Test
public void testRadiusWithPositionEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusMember() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS)).containsExactly("Palermo", "Catania");
}
@Test
public void testRadiusMemberEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusMemberWithDistance() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
Map<String, Double> expected = new HashMap<String, Double>();
expected.put("Palermo", 0.0);
expected.put("Catania", 166.2742);
assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
@Test
public void testRadiusMemberWithDistanceEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS)).isEmpty();
}
@Test
public void testRadiusMemberWithPosition() {
RGeo<String> geo = redisson.getGeo("test");
geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania"));
Map<String, GeoPosition> expected = new HashMap<String, GeoPosition>();
expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299));
expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162));
assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(expected);
}
@Test
public void testRadiusMemberWithPositionEmpty() {
RGeo<String> geo = redisson.getGeo("test");
assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS)).isEmpty();
}
}

@ -58,7 +58,7 @@ public class RedissonKeysTest extends BaseTest {
assertThat(redisson.getKeys().randomKey()).isIn("test1", "test2");
redisson.getKeys().delete("test1");
Assert.assertEquals(redisson.getKeys().randomKey(), "test2");
redisson.flushdb();
redisson.getKeys().flushdb();
Assert.assertNull(redisson.getKeys().randomKey());
}

@ -1,7 +1,6 @@
package org.redisson;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import static org.assertj.core.api.Assertions.*;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.core.RLexSortedSet;
@ -20,12 +19,12 @@ public class RedissonLexSortedSetTest extends BaseTest {
Assert.assertTrue(set.add("f"));
Assert.assertTrue(set.add("g"));
Assert.assertEquals(0, (int)set.removeRangeTailByLex("z", false));
Assert.assertEquals(0, (int)set.removeRangeTail("z", false));
Assert.assertEquals(4, (int)set.removeRangeTailByLex("c", false));
MatcherAssert.assertThat(set, Matchers.contains("a", "b", "c"));
Assert.assertEquals(1, (int)set.removeRangeTailByLex("c", true));
MatcherAssert.assertThat(set, Matchers.contains("a", "b"));
Assert.assertEquals(4, (int)set.removeRangeTail("c", false));
assertThat(set).containsExactly("a", "b", "c");
Assert.assertEquals(1, (int)set.removeRangeTail("c", true));
assertThat(set).containsExactly("a", "b");
}
@ -40,10 +39,10 @@ public class RedissonLexSortedSetTest extends BaseTest {
set.add("f");
set.add("g");
Assert.assertEquals(2, (int)set.removeRangeHeadByLex("c", false));
MatcherAssert.assertThat(set, Matchers.contains("c", "d", "e", "f", "g"));
Assert.assertEquals(1, (int)set.removeRangeHeadByLex("c", true));
MatcherAssert.assertThat(set, Matchers.contains("d", "e", "f", "g"));
Assert.assertEquals(2, (int)set.removeRangeHead("c", false));
assertThat(set).containsExactly("c", "d", "e", "f", "g");
Assert.assertEquals(1, (int)set.removeRangeHead("c", true));
assertThat(set).containsExactly("d", "e", "f", "g");
}
@Test
@ -57,8 +56,8 @@ public class RedissonLexSortedSetTest extends BaseTest {
set.add("f");
set.add("g");
Assert.assertEquals(5, set.removeRangeByLex("aaa", true, "g", false));
MatcherAssert.assertThat(set, Matchers.contains("a", "g"));
Assert.assertEquals(5, set.removeRange("aaa", true, "g", false));
assertThat(set).containsExactly("a", "g");
}
@ -74,8 +73,8 @@ public class RedissonLexSortedSetTest extends BaseTest {
Assert.assertTrue(set.add("f"));
Assert.assertTrue(set.add("g"));
MatcherAssert.assertThat(set.lexRangeTail("c", false), Matchers.contains("d", "e", "f", "g"));
MatcherAssert.assertThat(set.lexRangeTail("c", true), Matchers.contains("c", "d", "e", "f", "g"));
assertThat(set.rangeTail("c", false)).containsExactly("d", "e", "f", "g");
assertThat(set.rangeTail("c", true)).containsExactly("c", "d", "e", "f", "g");
}
@ -90,8 +89,8 @@ public class RedissonLexSortedSetTest extends BaseTest {
set.add("f");
set.add("g");
MatcherAssert.assertThat(set.lexRangeHead("c", false), Matchers.contains("a", "b"));
MatcherAssert.assertThat(set.lexRangeHead("c", true), Matchers.contains("a", "b", "c"));
assertThat(set.rangeHead("c", false)).containsExactly("a", "b");
assertThat(set.rangeHead("c", true)).containsExactly("a", "b", "c");
}
@ -106,7 +105,7 @@ public class RedissonLexSortedSetTest extends BaseTest {
set.add("f");
set.add("g");
MatcherAssert.assertThat(set.lexRange("aaa", true, "g", false), Matchers.contains("b", "c", "d", "e", "f"));
assertThat(set.range("aaa", true, "g", false)).containsExactly("b", "c", "d", "e", "f");
}
@Test
@ -120,8 +119,8 @@ public class RedissonLexSortedSetTest extends BaseTest {
set.add("f");
set.add("g");
Assert.assertEquals(5, (int)set.lexCount("b", true, "f", true));
Assert.assertEquals(3, (int)set.lexCount("b", false, "f", false));
assertThat(set.count("b", true, "f", true)).isEqualTo(5);
assertThat(set.count("b", false, "f", false)).isEqualTo(3);
}
}

@ -102,7 +102,7 @@ public class RedissonSetMultimapCacheTest extends BaseTest {
multimap.put("1", "3");
multimap.expireKey("1", 1, TimeUnit.SECONDS);
Thread.sleep(1000);
Thread.sleep(1500);
assertThat(multimap.get("1").size()).isZero();
assertThat(multimap.get("1")).contains();

@ -10,9 +10,11 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.redisson.RedisRunner.RedisProcess;
import org.redisson.client.RedisConnectionException;
@ -28,6 +30,16 @@ public class RedissonTest {
RedissonClient redisson;
@Before
public void before() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisTestInstance();
}
@After
public void after() throws InterruptedException {
RedisRunner.shutDownDefaultRedisTestInstance();
}
public static class Dummy {
private String field;
}

@ -1,9 +1,12 @@
package org.redisson;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.redisson.core.BasePatternStatusListener;
import org.redisson.core.MessageListener;
@ -13,6 +16,16 @@ import org.redisson.core.RTopic;
public class RedissonTopicPatternTest {
@Before
public void before() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisTestInstance();
}
@After
public void after() throws InterruptedException {
RedisRunner.shutDownDefaultRedisTestInstance();
}
public static class Message {
private String name;

@ -1,10 +1,13 @@
package org.redisson;
import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.redisson.core.BaseStatusListener;
import org.redisson.core.MessageListener;
@ -13,6 +16,16 @@ import org.redisson.core.RTopic;
public class RedissonTopicTest {
@Before
public void before() throws IOException, InterruptedException {
RedisRunner.startDefaultRedisTestInstance();
}
@After
public void after() throws InterruptedException {
RedisRunner.shutDownDefaultRedisTestInstance();
}
public static class Message implements Serializable {
private String name;

Loading…
Cancel
Save