diff --git a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java index 17f477223..c34ef5dbc 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -19,7 +19,8 @@ package org.springframework.data.redis.core; import java.util.Collection; import java.util.Set; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.RedisZSetCommands.Limit; +import org.springframework.data.redis.connection.RedisZSetCommands.Range; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; /** @@ -53,9 +54,26 @@ public interface BoundZSetOperations extends BoundKeyOperations { Set> reverseRangeByScoreWithScores(double min, double max); - Set rangeByLex(RedisZSetCommands.Range range); + /** + * Get all elements with lexicographical ordering with a value between {@link Range#getMin()} and + * {@link Range#getMax()}. + * + * @param range must not be {@literal null}. + * @since 1.7 + */ + Set rangeByLex(Range range); - Set rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit); + /** + * Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at + * {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getMin()} and + * {@link Range#getMax()}. + * + * @param range must not be {@literal null}. + * @param limit can be {@literal null}. + * @return + * @since 1.7 + */ + Set rangeByLex(Range range, Limit limit); void removeRange(long start, long end); diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java index e5797c870..79ff62419 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -20,7 +20,8 @@ import java.util.Collection; import java.util.Set; import org.springframework.data.redis.connection.DataType; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.RedisZSetCommands.Limit; +import org.springframework.data.redis.connection.RedisZSetCommands.Range; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; /** @@ -97,13 +98,21 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl return ops.reverseRangeWithScores(getKey(), start, end); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.BoundZSetOperations#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range) + */ @Override - public Set rangeByLex(RedisZSetCommands.Range range) { - return ops.rangeByLex(getKey(), range); + public Set rangeByLex(Range range) { + return rangeByLex(range, null); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.BoundZSetOperations#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) + */ @Override - public Set rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit) { + public Set rangeByLex(Range range, Limit limit) { return ops.rangeByLex(getKey(), range, limit); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java index bfe2cd1cf..a098f5d48 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -22,7 +22,8 @@ import java.util.Set; import org.springframework.core.convert.converter.Converter; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.RedisZSetCommands.Limit; +import org.springframework.data.redis.connection.RedisZSetCommands.Range; import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; /** @@ -143,23 +144,21 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.ZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range) + */ @Override - public Set rangeByLex(K key, final RedisZSetCommands.Range range) { - - final byte[] rawKey = rawKey(key); - - Set rawValues = execute(new RedisCallback>() { - - public Set doInRedis(RedisConnection connection) { - return connection.zRangeByLex(rawKey, range); - } - }, true); - - return deserializeValues(rawValues); + public Set rangeByLex(K key, final Range range) { + return rangeByLex(key, range, null); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.ZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) + */ @Override - public Set rangeByLex(K key, final RedisZSetCommands.Range range, final RedisZSetCommands.Limit limit) { + public Set rangeByLex(K key, final Range range, final Limit limit) { final byte[] rawKey = rawKey(key); diff --git a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java index ad6fec441..880a5ea59 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -19,7 +19,8 @@ package org.springframework.data.redis.core; import java.util.Collection; import java.util.Set; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.RedisZSetCommands.Limit; +import org.springframework.data.redis.connection.RedisZSetCommands.Range; /** * Redis ZSet/sorted set specific operations. @@ -55,9 +56,28 @@ public interface ZSetOperations { Set> reverseRangeWithScores(K key, long start, long end); - Set rangeByLex(K key, RedisZSetCommands.Range range); + /** + * Get all elements with lexicographical ordering from {@literal ZSET} at {@code key} with a value between + * {@link Range#getMin()} and {@link Range#getMax()}. + * + * @param key must not be {@literal null}. + * @param range must not be {@literal null}. + * @since 1.7 + */ + Set rangeByLex(K key, Range range); - Set rangeByLex(K key, RedisZSetCommands.Range range, RedisZSetCommands.Limit limit); + /** + * Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at + * {@link Limit#getOffset()} with lexicographical ordering from {@literal ZSET} at {@code key} with a value between + * {@link Range#getMin()} and {@link Range#getMax()}. + * + * @param key must not be {@literal null} + * @param range must not be {@literal null}. + * @param limit can be {@literal null}. + * @return + * @since 1.7 + */ + Set rangeByLex(K key, Range range, Limit limit); Set rangeByScore(K key, double min, double max); diff --git a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java index 3e7bdc019..4bf94a699 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java +++ b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -22,7 +22,8 @@ import java.util.Set; import org.springframework.core.convert.converter.Converter; import org.springframework.data.redis.connection.DataType; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.RedisZSetCommands.Limit; +import org.springframework.data.redis.connection.RedisZSetCommands.Range; import org.springframework.data.redis.core.BoundZSetOperations; import org.springframework.data.redis.core.ConvertingCursor; import org.springframework.data.redis.core.Cursor; @@ -116,13 +117,21 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return boundZSetOps.reverseRange(start, end); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.support.collections.RedisZSet#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range) + */ @Override - public Set rangeByLex(RedisZSetCommands.Range range) { + public Set rangeByLex(Range range) { return boundZSetOps.rangeByLex(range); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.support.collections.RedisZSet#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) + */ @Override - public Set rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit) { + public Set rangeByLex(Range range, Limit limit) { return boundZSetOps.rangeByLex(range, limit); } diff --git a/src/main/java/org/springframework/data/redis/support/collections/RedisZSet.java b/src/main/java/org/springframework/data/redis/support/collections/RedisZSet.java index caacf3ba8..f3ce4b3d8 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/RedisZSet.java +++ b/src/main/java/org/springframework/data/redis/support/collections/RedisZSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2016 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. @@ -22,7 +22,9 @@ import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedSet; -import org.springframework.data.redis.connection.RedisZSetCommands; +import org.springframework.data.redis.connection.RedisZSetCommands.Limit; +import org.springframework.data.redis.connection.RedisZSetCommands.Range; +import org.springframework.data.redis.core.BoundZSetOperations; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; /** @@ -33,6 +35,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple; * * @author Costin Leau * @author Mark Paluch + * @auhtor Christoph Strobl */ public interface RedisZSet extends RedisCollection, Set { @@ -48,9 +51,29 @@ public interface RedisZSet extends RedisCollection, Set { Set reverseRange(long start, long end); - Set rangeByLex(RedisZSetCommands.Range range); + /** + * Get all elements with lexicographical ordering with a value between {@link Range#getMin()} and + * {@link Range#getMax()}. + * + * @param range must not be {@literal null}. + * @return + * @see BoundZSetOperations#rangeByLex(Range) + * @since 1.7 + */ + Set rangeByLex(Range range); - Set rangeByLex(RedisZSetCommands.Range range, RedisZSetCommands.Limit limit); + /** + * Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at + * {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getMin()} and + * {@link Range#getMax()}. + * + * @param range must not be {@literal null}. + * @param limit can be {@literal null}. + * @return + * @see BoundZSetOperations#rangeByLex(Range, Limit) + * @since 1.7 + */ + Set rangeByLex(Range range, Limit limit); Set rangeByScore(double min, double max); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java index c35dcc3d8..a434a10bf 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 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. @@ -17,9 +17,9 @@ package org.springframework.data.redis.core; import static org.hamcrest.core.AnyOf.*; import static org.hamcrest.core.IsEqual.*; -import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.hamcrest.core.IsInstanceOf.*; import static org.junit.Assert.*; -import static org.junit.Assume.assumeThat; +import static org.junit.Assume.*; import static org.springframework.data.redis.matcher.RedisTestMatchers.*; import java.util.Collection; @@ -179,8 +179,10 @@ public class DefaultZSetOperationsTests { @Test public void testRangeByLexUnbounded() { - assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + valueFactory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); K key = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -203,8 +205,10 @@ public class DefaultZSetOperationsTests { @Test public void testRangeByLexBounded() { - assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + valueFactory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); K key = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -227,8 +231,10 @@ public class DefaultZSetOperationsTests { @Test public void testRangeByLexUnboundedWithLimit() { - assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + valueFactory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); K key = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -252,8 +258,10 @@ public class DefaultZSetOperationsTests { @Test public void testRangeByLexBoundedWithLimit() { - assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + valueFactory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); K key = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -263,8 +271,8 @@ public class DefaultZSetOperationsTests { zSetOps.add(key, value1, 1.9); zSetOps.add(key, value2, 3.7); zSetOps.add(key, value3, 5.8); - Set tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1), - RedisZSetCommands.Limit.limit().count(1).offset(1)); + Set tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1), RedisZSetCommands.Limit + .limit().count(1).offset(1)); assertEquals(1, tuples.size()); V tuple = tuples.iterator().next(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java index 8ead1934d..f95fc867d 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2016 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. @@ -332,8 +332,10 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe @Test public void testRangeByLexUnbounded() { - assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + factory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); T t1 = getT(); T t2 = getT(); @@ -355,8 +357,10 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe @Test public void testRangeByLexBounded() { - assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + factory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); T t1 = getT(); T t2 = getT(); @@ -378,8 +382,10 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe @Test public void testRangeByLexUnboundedWithLimit() { - assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + factory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); T t1 = getT(); T t2 = getT(); @@ -388,8 +394,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t1, 1); zSet.add(t2, 2); zSet.add(t3, 3); - Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), - RedisZSetCommands.Limit.limit().count(1).offset(1)); + Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), RedisZSetCommands.Limit.limit().count(1) + .offset(1)); assertEquals(1, tuples.size()); T tuple = tuples.iterator().next(); @@ -402,8 +408,10 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe @Test public void testRangeByLexBoundedWithLimit() { - assumeThat(factory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), - instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); + assumeThat( + factory, + anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class), + instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class))); T t1 = getT(); T t2 = getT(); @@ -412,8 +420,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t1, 1); zSet.add(t2, 2); zSet.add(t3, 3); - Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1), - RedisZSetCommands.Limit.limit().count(1).offset(1)); + Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1), RedisZSetCommands.Limit.limit().count(1) + .offset(1)); assertEquals(1, tuples.size()); T tuple = tuples.iterator().next(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java index 9a82b84b2..216ebb00c 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java +++ b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 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. @@ -233,7 +233,8 @@ public abstract class CollectionTestParams { { personFactory, jackson2JsonPersonTemplateJR }, { rawFactory, rawTemplateJR }, // srp - { stringFactory, stringTemplateSRP }, { personFactory, personTemplateSRP }, + { stringFactory, stringTemplateSRP }, + { personFactory, personTemplateSRP }, { stringFactory, xstreamStringTemplateSRP }, { personFactory, xstreamPersonTemplateSRP }, { personFactory, jsonPersonTemplateSRP },