From bd3093b3d9fa62c9e520e0264b815a36205d1bc6 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 13:12:02 +0200 Subject: [PATCH 01/12] + minor integration test improvement --- .../data/keyvalue/redis/util/RedisMapTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisMapTests.java index ea74a089d..f82bd255e 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/RedisMapTests.java @@ -50,8 +50,8 @@ public class RedisMapTests extends AbstractRedisMapTests { jedisConnFactory.setPooling(false); jedisConnFactory.afterPropertiesSet(); - RedisTemplate stringTemplate = new RedisTemplate(jedisConnFactory); - RedisTemplate personTemplate = new RedisTemplate(jedisConnFactory); + RedisTemplate genericTemplate = new RedisTemplate(jedisConnFactory); + // JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(); // jredisConnFactory.setPooling(false); @@ -60,7 +60,8 @@ public class RedisMapTests extends AbstractRedisMapTests { // RedisTemplate stringTemplateJR = new RedisTemplate(jredisConnFactory); // RedisTemplate personTemplateJR = new RedisTemplate(jredisConnFactory); - return Arrays.asList(new Object[][] { { stringFactory, stringFactory, stringTemplate }, - { personFactory, personFactory, personTemplate } }); + return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate }, + { personFactory, personFactory, genericTemplate }, { stringFactory, personFactory, genericTemplate }, + { personFactory, stringFactory, genericTemplate } }); } } \ No newline at end of file From d3fd66ef796e5323310a889f3795c40edb5b1c51 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 14:43:58 +0200 Subject: [PATCH 02/12] + add initial draft for ConcurrentMap contract to RedisMap + add disabled integration tests (need to find a way to reuse the same connection) w/o transactions --- .../keyvalue/redis/core/RedisTemplate.java | 17 ++- .../keyvalue/redis/util/DefaultRedisMap.java | 109 ++++++++++++++++-- .../redis/util/RedisAtomicInteger.java | 4 +- .../keyvalue/redis/util/RedisAtomicLong.java | 4 +- .../data/keyvalue/redis/util/RedisMap.java | 7 +- .../redis/util/AbstractRedisMapTests.java | 80 ++++++++++--- 6 files changed, 185 insertions(+), 36 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 29b1b5336..e41c49e01 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; @@ -320,7 +321,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public Object exec() { - throw new UnsupportedOperationException(); + return execute(new RedisCallback() { + + @Override + public Object doInRedis(RedisConnection connection) throws DataAccessException { + return connection.exec(); + } + }); } @Override @@ -379,7 +386,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public void multi() { - throw new UnsupportedOperationException(); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) throws DataAccessException { + connection.multi(); + return null; + } + }, true); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java index 6b18ae8f7..d490ac7a4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java @@ -83,15 +83,6 @@ public class DefaultRedisMap implements RedisMap { return hashOps.increment(key, delta); } - @Override - public boolean putIfAbsent(K key, V value) { - if (!hashOps.hasKey(key)) { - put(key, value); - return true; - } - return false; - } - @Override public String getKey() { return hashOps.getKey(); @@ -203,4 +194,104 @@ public class DefaultRedisMap implements RedisMap { sb.append(getKey()); return sb.toString(); } + + @Override + public V putIfAbsent(K key, V value) { + throw new UnsupportedOperationException(); + + // RedisOperations ops = hashOps.getOperations(); + // + // for (;;) { + // ops.watch(getKey()); + // V v = get(key); + // if (v == null) { + // ops.multi(); + // put(key, value); + // if (ops.exec() != null) { + // return null; + // } + // } + // else { + // return v; + // } + // } + } + + @Override + public boolean remove(Object key, Object value) { + throw new UnsupportedOperationException(); + + // if (value == null){ + // throw new NullPointerException(); + // } + // + // RedisOperations ops = hashOps.getOperations(); + // + // for (;;) { + // ops.watch(getKey()); + // V v = get(key); + // if (value.equals(v)) { + // ops.multi(); + // remove(key); + // if (ops.exec() != null) { + // return true; + // } + // } + // else { + // return false; + // } + // } + } + + @Override + public boolean replace(K key, V oldValue, V newValue) { + throw new UnsupportedOperationException(); + + // if (newValue == null || oldValue == null) { + // throw new NullPointerException(); + // } + // + // RedisOperations ops = hashOps.getOperations(); + // + // for (;;) { + // ops.watch(getKey()); + // V v = get(key); + // if (oldValue.equals(v)) { + // ops.multi(); + // put(key, newValue); + // if (ops.exec() != null) { + // return true; + // } + // } + // else { + // return false; + // } + // } + } + + @Override + public V replace(K key, V value) { + throw new UnsupportedOperationException(); + + + // if (value == null) { + // throw new NullPointerException(); + // } + // + // RedisOperations ops = hashOps.getOperations(); + // + // for (;;) { + // ops.watch(getKey()); + // if (containsKey(key)) { + // ops.multi(); + // V oldValue = put(key, value); + // if (ops.exec() != null) { + // return oldValue; + // } + // } + // else { + // return null; + // } + // } + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java index 7fbd1ee00..39a08d63d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java @@ -100,7 +100,9 @@ public class RedisAtomicInteger extends Number implements Serializable { return true; } } - return false; + else { + return false; + } } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java index d7d32f56b..007062a3e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java @@ -101,7 +101,9 @@ public class RedisAtomicLong extends Number implements Serializable { return true; } } - return false; + else { + return false; + } } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java index cdbf4fd82..83e1ca52e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java @@ -15,16 +15,15 @@ */ package org.springframework.data.keyvalue.redis.util; -import java.util.Map; +import java.util.concurrent.ConcurrentMap; + /** * Map view of a Redis hash. * * @author Costin Leau */ -public interface RedisMap extends RedisStore, Map { - - boolean putIfAbsent(K key, V value); +public interface RedisMap extends RedisStore, ConcurrentMap { Integer increment(K key, int delta); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java index 3a5d210b8..ab67e738b 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java @@ -269,25 +269,6 @@ public abstract class AbstractRedisMapTests { assertEquals(v2, map.get(k2)); } - @Test - public void testPutIfAbsent() { - K k1 = getKey(); - K k2 = getKey(); - - V v1 = getValue(); - V v2 = getValue(); - - assertNull(map.get(k1)); - assertTrue(map.putIfAbsent(k1, v1)); - assertFalse(map.putIfAbsent(k1, v2)); - assertEquals(v1, map.get(k1)); - - assertTrue(map.putIfAbsent(k2, v2)); - assertFalse(map.putIfAbsent(k2, v1)); - - assertEquals(v2, map.get(k2)); - } - @Test public void testRemove() { K k1 = getKey(); @@ -375,4 +356,65 @@ public abstract class AbstractRedisMapTests { assertThat(values, hasItem(v1)); assertThat(values, not(hasItem(v2))); } + + + @Test(expected = UnsupportedOperationException.class) + public void testConcurrentPutIfAbsent() { + K k1 = getKey(); + K k2 = getKey(); + + V v1 = getValue(); + V v2 = getValue(); + + assertNull(map.get(k1)); + assertNull(map.putIfAbsent(k1, v1)); + assertEquals(v1, map.putIfAbsent(k1, v2)); + assertEquals(v1, map.get(k1)); + + assertNull(map.putIfAbsent(k2, v2)); + assertEquals(v2, map.putIfAbsent(k2, v1)); + + assertEquals(v2, map.get(k2)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testConcurrentRemove() { + K k1 = getKey(); + V v1 = getValue(); + V v2 = getValue(); + + map.put(k1, v1); + assertFalse(map.remove(k1, v1)); + assertEquals(v1, map.get(k1)); + assertTrue(map.remove(k1, v1)); + assertNull(map.get(k1)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testConcurrentReplaceTwoArgs() { + K k1 = getKey(); + V v1 = getValue(); + V v2 = getValue(); + + map.put(k1, v1); + + assertFalse(map.replace(k1, v2, v1)); + assertEquals(v1, map.get(k1)); + assertTrue(map.replace(k1, v1, v2)); + assertEquals(v2, map.get(k1)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testConcurrentReplaceOneArg() { + K k1 = getKey(); + V v1 = getValue(); + V v2 = getValue(); + + assertNull(map.replace(k1, v1)); + map.put(k1, v1); + assertNull(map.replace(getKey(), v1)); + assertEquals(v1, map.replace(k1, v2)); + assertEquals(v2, map.get(k1)); + + } } \ No newline at end of file From ae51a0c9b02b1982a0d210bc150d942d3ffa34cc Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 18:38:55 +0200 Subject: [PATCH 03/12] + add key operations contract (no impl yet) --- .../redis/core/BoundHashOperations.java | 2 + .../redis/core/BoundKeyOperations.java | 47 ++++++++++ .../redis/core/DefaultBoundKeyOperations.java | 92 +++++++++++++++++++ .../core/DefaultBoundListOperations.java | 8 +- .../redis/core/DefaultBoundSetOperations.java | 6 ++ .../core/DefaultBoundZSetOperations.java | 6 ++ .../keyvalue/redis/core/DefaultKeyBound.java | 10 +- .../keyvalue/redis/core/KeyOperations.java | 52 +++++++++++ 8 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java index 19ddc0966..a8a54df8b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java @@ -20,6 +20,8 @@ import java.util.Map; import java.util.Set; /** + * Hash operations bound to a certain key. + * * @author Costin Leau */ public interface BoundHashOperations extends KeyBound { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java new file mode 100644 index 000000000..ec35e56d6 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010 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.keyvalue.redis.core; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.DataType; + +/** + * Key operations bound to a certain value. + * + * @author Costin Leau + */ +public interface BoundKeyOperations extends KeyBound { + + Boolean exists(); + + void delete(); + + DataType type(); + + void rename(K newKey); + + Boolean renameIfAbsent(K newKey); + + Boolean expire(long timeout, TimeUnit unit); + + Boolean expireAt(Date date); + + long getExpire(); + + void persist(); +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java new file mode 100644 index 000000000..ee92bd670 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -0,0 +1,92 @@ +/* + * Copyright 2010 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.keyvalue.redis.core; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.DataType; + + +/** + * Default implementation for {@link BoundKeyOperations}. + * + * @author Costin Leau + */ +class DefaultBoundKeyOperations extends DefaultKeyBound implements BoundKeyOperations { + + private final KeyOperations keyOps; + + /** + * Constructs a new DefaultBoundKeyOperations instance. + * + * @param key + */ + public DefaultBoundKeyOperations(K key, KeyOperations keyOps) { + super(key); + this.keyOps = keyOps; + } + + @Override + public void delete() { + keyOps.delete(getKey()); + } + + @Override + public Boolean exists() { + return keyOps.exists(getKey()); + } + + @Override + public Boolean expire(long timeout, TimeUnit unit) { + return keyOps.expire(getKey(), timeout, unit); + } + + @Override + public Boolean expireAt(Date date) { + return keyOps.expireAt(getKey(), date); + } + + @Override + public long getExpire() { + return keyOps.getExpire(getKey()); + } + + @Override + public void persist() { + keyOps.persist(getKey()); + } + + @Override + public void rename(K newKey) { + keyOps.rename(getKey(), newKey); + setKey(newKey); + } + + @Override + public Boolean renameIfAbsent(K newKey) { + if (keyOps.renameIfAbsent(getKey(), newKey)) { + setKey(newKey); + return Boolean.TRUE; + } + return Boolean.FALSE; + } + + @Override + public DataType type() { + return keyOps.type(getKey()); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index b2a413cc0..64e9f47b0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -23,10 +23,16 @@ import java.util.List; * * @author Costin Leau */ -public class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations { +class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations { private final ListOperations ops; + /** + * Constructs a new DefaultBoundListOperations instance. + * + * @param key + * @param template + */ public DefaultBoundListOperations(K key, RedisTemplate template) { super(key); this.ops = template.listOps(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java index 3354a626d..910af3682 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java @@ -28,6 +28,12 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun private final SetOperations ops; + /** + * Constructs a new DefaultBoundSetOperations instance. + * + * @param key + * @param template + */ DefaultBoundSetOperations(K key, RedisTemplate template) { super(key); this.ops = template.setOps(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java index 3769f8045..e0d7f9ba9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java @@ -27,6 +27,12 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou private final ZSetOperations ops; + /** + * Constructs a new DefaultBoundZSetOperations instance. + * + * @param key + * @param template + */ public DefaultBoundZSetOperations(K key, RedisTemplate template) { super(key); this.ops = template.zSetOps(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java index 3ffb5477b..20df1b616 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java @@ -21,16 +21,20 @@ package org.springframework.data.keyvalue.redis.core; * * @author Costin Leau */ -public class DefaultKeyBound implements KeyBound { +class DefaultKeyBound implements KeyBound { - private final K key; + private K key; public DefaultKeyBound(K key) { - this.key = key; + setKey(key); } @Override public K getKey() { return key; } + + protected void setKey(K key) { + this.key = key; + } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java new file mode 100644 index 000000000..66588cfc6 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010 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.keyvalue.redis.core; + +import java.util.Date; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.DataType; + +/** + * Redis operations available for all keys. + * + * @author Costin Leau + */ +public interface KeyOperations { + + Boolean exists(K key); + + void delete(K key); + + DataType type(K key); + + Set keys(String pattern); + + K randomKey(); + + void rename(K oldKey, K newKey); + + Boolean renameIfAbsent(K oldKey, K newKey); + + Boolean expire(K key, long timeout, TimeUnit unit); + + Boolean expireAt(K key, Date date); + + void persist(K key); + + long getExpire(K key); +} \ No newline at end of file From cbc061cf4e4122a68315d4725d5eac4b5a539d4f Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 20:38:38 +0200 Subject: [PATCH 04/12] + add String/Value operations contract --- .../redis/core/BoundValueOperations.java | 37 +++ .../redis/core/DefaultBoundKeyOperations.java | 92 ------- .../core/DefaultBoundValueOperations.java | 67 +++++ .../keyvalue/redis/core/RedisOperations.java | 33 ++- .../keyvalue/redis/core/RedisTemplate.java | 231 +++++++++++++----- ...eyOperations.java => ValueOperations.java} | 33 ++- .../keyvalue/redis/util/DefaultRedisMap.java | 3 +- .../redis/util/RedisAtomicInteger.java | 33 +-- .../keyvalue/redis/util/RedisAtomicLong.java | 32 +-- 9 files changed, 353 insertions(+), 208 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/{KeyOperations.java => ValueOperations.java} (60%) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java new file mode 100644 index 000000000..3af2455a4 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java @@ -0,0 +1,37 @@ +/* + * Copyright 2010 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.keyvalue.redis.core; + +import java.util.concurrent.TimeUnit; + +/** + * @author Costin Leau + */ +public interface BoundValueOperations extends KeyBound { + + void set(V value); + + void set(V value, long timeout, TimeUnit unit); + + Boolean setIfAbsent(V value); + + V get(); + + V getAndSet(V value); + + V increment(int delta); + +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java deleted file mode 100644 index ee92bd670..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2010 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.keyvalue.redis.core; - -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import org.springframework.data.keyvalue.redis.connection.DataType; - - -/** - * Default implementation for {@link BoundKeyOperations}. - * - * @author Costin Leau - */ -class DefaultBoundKeyOperations extends DefaultKeyBound implements BoundKeyOperations { - - private final KeyOperations keyOps; - - /** - * Constructs a new DefaultBoundKeyOperations instance. - * - * @param key - */ - public DefaultBoundKeyOperations(K key, KeyOperations keyOps) { - super(key); - this.keyOps = keyOps; - } - - @Override - public void delete() { - keyOps.delete(getKey()); - } - - @Override - public Boolean exists() { - return keyOps.exists(getKey()); - } - - @Override - public Boolean expire(long timeout, TimeUnit unit) { - return keyOps.expire(getKey(), timeout, unit); - } - - @Override - public Boolean expireAt(Date date) { - return keyOps.expireAt(getKey(), date); - } - - @Override - public long getExpire() { - return keyOps.getExpire(getKey()); - } - - @Override - public void persist() { - keyOps.persist(getKey()); - } - - @Override - public void rename(K newKey) { - keyOps.rename(getKey(), newKey); - setKey(newKey); - } - - @Override - public Boolean renameIfAbsent(K newKey) { - if (keyOps.renameIfAbsent(getKey(), newKey)) { - setKey(newKey); - return Boolean.TRUE; - } - return Boolean.FALSE; - } - - @Override - public DataType type() { - return keyOps.type(getKey()); - } -} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java new file mode 100644 index 000000000..2afc97e48 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -0,0 +1,67 @@ +/* + * Copyright 2010 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.keyvalue.redis.core; + +import java.util.concurrent.TimeUnit; + +/** + * @author Costin Leau + */ +class DefaultBoundValueOperations extends DefaultKeyBound implements BoundValueOperations { + + private final ValueOperations ops; + + /** + * Constructs a new DefaultBoundValueOperations instance. + * + * @param key + * @param template + */ + public DefaultBoundValueOperations(K key, RedisTemplate template) { + super(key); + this.ops = template.valueOps(); + } + + @Override + public V get() { + return ops.get(getKey()); + } + + @Override + public V getAndSet(V value) { + return ops.getAndSet(getKey(), value); + } + + @Override + public V increment(int delta) { + return ops.increment(getKey(), delta); + } + + @Override + public void set(V value, long timeout, TimeUnit unit) { + ops.set(getKey(), value, timeout, unit); + } + + @Override + public void set(V value) { + ops.set(getKey(), value); + } + + @Override + public Boolean setIfAbsent(V value) { + return ops.setIfAbsent(getKey(), value); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index 5168bca7f..d67ce65a1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -15,6 +15,13 @@ */ package org.springframework.data.keyvalue.redis.core; +import java.util.Collection; +import java.util.Date; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.DataType; + /** * Basic set of Redis operations, implemented by {@link RedisTemplate}. @@ -23,11 +30,27 @@ package org.springframework.data.keyvalue.redis.core; */ public interface RedisOperations { - void set(K key, V value); + Boolean exists(K key); - V get(K key); + void delete(Collection key); - V getAndSet(K key, V newValue); + DataType type(K key); + + Set keys(String pattern); + + K randomKey(); + + void rename(K oldKey, K newKey); + + Boolean renameIfAbsent(K oldKey, K newKey); + + Boolean expire(K key, long timeout, TimeUnit unit); + + Boolean expireAt(K key, Date date); + + void persist(K key); + + long getExpire(K key); void watch(K... keys); @@ -35,9 +58,9 @@ public interface RedisOperations { Object exec(); - Integer increment(K key, int delta); + ValueOperations valueOps(); - void delete(K... keys); + BoundValueOperations forValue(K key); ListOperations listOps(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index e41c49e01..9be0a90d5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -22,13 +22,16 @@ import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; @@ -212,7 +215,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } } - private byte[] rawKey(K key) { + private byte[] rawKey(Object key) { return (key != null ? keySerializer.serialize(key) : null); } @@ -230,6 +233,17 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return rawKeys; } + private byte[][] rawKeys(Collection keys) { + final byte[][] rawKeys = new byte[keys.size()][]; + + int i = 0; + for (K key : keys) { + rawKeys[i++] = rawKey(key); + } + + return rawKeys; + } + private byte[] rawHashKey(HK value) { return (value != null ? hashKeySerializer.serialize(value) : null); } @@ -298,9 +312,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // utility methods for the template internal methods private abstract class ValueDeserializingRedisCallback implements RedisCallback { - private K key; + private Object key; - public ValueDeserializingRedisCallback(K key) { + public ValueDeserializingRedisCallback(Object key) { this.key = key; } @@ -331,52 +345,166 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public BoundListOperations forList(K key) { - return new DefaultBoundListOperations(key, this); - } + public void delete(Collection keys) { + final byte[][] rawKeys = rawKeys(keys); - @Override - public V get(final K key) { - return execute(new ValueDeserializingRedisCallback(key) { + execute(new RedisCallback() { @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.get(rawKey); + public Object doInRedis(RedisConnection connection) { + connection.del(rawKeys); + return null; } }, true); } @Override - public V getAndSet(K key, V newValue) { - final byte[] rawValue = rawValue(newValue); - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.getSet(rawKey, rawValue); - } - }, true); + public Boolean exists(K key) { + throw new UnsupportedOperationException(); } @Override - public Integer increment(K key, final int delta) { - final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { - @Override - public Integer doInRedis(RedisConnection connection) { - if (delta == 1) { - return connection.incr(rawKey); - } + public Boolean expire(K key, long timeout, TimeUnit unit) { + throw new UnsupportedOperationException(); + } - if (delta == -1) { - return connection.decr(rawKey); - } + @Override + public Boolean expireAt(K key, Date date) { + throw new UnsupportedOperationException(); + } - if (delta < 0) { - return connection.decrBy(rawKey, delta); - } + // + // Value operations + // - return connection.incrBy(rawKey, delta); - } - }, true); + @Override + public long getExpire(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public Set keys(String pattern) { + throw new UnsupportedOperationException(); + } + + @Override + public void persist(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public K randomKey() { + throw new UnsupportedOperationException(); + } + + @Override + public void rename(K oldKey, K newKey) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean renameIfAbsent(K oldKey, K newKey) { + throw new UnsupportedOperationException(); + } + + @Override + public DataType type(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public BoundValueOperations forValue(K key) { + return new DefaultBoundValueOperations(key, this); + } + + @Override + public ValueOperations valueOps() { + return new DefaultValueOperations(); + } + + private class DefaultValueOperations implements ValueOperations { + + @Override + public V get(final Object key) { + + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.get(rawKey); + } + }, true); + } + + @Override + public V getAndSet(K key, V newValue) { + final byte[] rawValue = rawValue(newValue); + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.getSet(rawKey, rawValue); + } + }, true); + } + + @Override + public V increment(K key, final int delta) { + final byte[] rawKey = rawKey(key); + // TODO add conversion service in here ? + return (V) execute(new RedisCallback() { + @Override + public Integer doInRedis(RedisConnection connection) { + if (delta == 1) { + return connection.incr(rawKey); + } + + if (delta == -1) { + return connection.decr(rawKey); + } + + if (delta < 0) { + return connection.decrBy(rawKey, delta); + } + + return connection.incrBy(rawKey, delta); + } + }, true); + } + + @Override + public Collection multiGet(Set keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void multiSet(Map m) { + throw new UnsupportedOperationException(); + } + + @Override + public void multiSetIfAbsent(Map m) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(K key, V value) { + final byte[] rawValue = rawValue(value); + execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + connection.set(rawKey, rawValue); + return null; + } + }, true); + } + + @Override + public void set(K key, V value, long timeout, TimeUnit unit) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean setIfAbsent(K key, V value) { + throw new UnsupportedOperationException(); + } } @Override @@ -384,6 +512,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return new DefaultListOperations(); } + @Override + public BoundListOperations forList(K key) { + return new DefaultBoundListOperations(key, this); + } + + @Override public void multi() { execute(new RedisCallback() { @@ -395,18 +529,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override - public void set(K key, V value) { - final byte[] rawValue = rawValue(value); - execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - connection.set(rawKey, rawValue); - return null; - } - }, true); - } - @Override public void watch(K... keys) { final byte[][] rawKeys = rawKeys(keys); @@ -420,19 +542,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override - public void delete(K... keys) { - final byte[][] rawKeys = rawKeys(keys); - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.del(rawKeys); - return null; - } - }, true); - } - // // List operations // diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java similarity index 60% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java index 66588cfc6..83eb2880c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java @@ -15,38 +15,33 @@ */ package org.springframework.data.keyvalue.redis.core; -import java.util.Date; +import java.util.Collection; +import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.springframework.data.keyvalue.redis.connection.DataType; - /** - * Redis operations available for all keys. + * Redis operations for simple (or in Redis terminology 'string') values. * * @author Costin Leau */ -public interface KeyOperations { +public interface ValueOperations { - Boolean exists(K key); + void set(K key, V value); - void delete(K key); + void set(K key, V value, long timeout, TimeUnit unit); - DataType type(K key); + Boolean setIfAbsent(K key, V value); - Set keys(String pattern); + void multiSet(Map m); - K randomKey(); + void multiSetIfAbsent(Map m); - void rename(K oldKey, K newKey); + V get(Object key); - Boolean renameIfAbsent(K oldKey, K newKey); + V getAndSet(K key, V value); - Boolean expire(K key, long timeout, TimeUnit unit); + Collection multiGet(Set keys); - Boolean expireAt(K key, Date date); - - void persist(K key); - - long getExpire(K key); -} \ No newline at end of file + V increment(K key, int delta); +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java index d490ac7a4..05939c438 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java @@ -16,6 +16,7 @@ package org.springframework.data.keyvalue.redis.util; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; @@ -95,7 +96,7 @@ public class DefaultRedisMap implements RedisMap { @Override public void clear() { - getOperations().delete(getKey()); + getOperations().delete(Collections.singleton(getKey())); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java index 39a08d63d..e557b9fca 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java @@ -18,6 +18,7 @@ package org.springframework.data.keyvalue.redis.util; import java.io.Serializable; import org.springframework.data.keyvalue.redis.core.RedisOperations; +import org.springframework.data.keyvalue.redis.core.ValueOperations; /** * Atomic integer backed by Redis. @@ -29,7 +30,8 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations; public class RedisAtomicInteger extends Number implements Serializable { private final String key; - private RedisOperations operations; + private ValueOperations operations; + private RedisOperations generalOps; /** * Constructs a new RedisAtomicInteger instance with an initial value of zero. @@ -50,8 +52,9 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public RedisAtomicInteger(String redisCounter, RedisOperations operations, int initialValue) { this.key = redisCounter; - this.operations = operations; - operations.set(redisCounter, initialValue); + this.operations = operations.valueOps(); + this.generalOps = operations; + this.operations.set(redisCounter, initialValue); } /** @@ -92,11 +95,11 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public boolean compareAndSet(int expect, int update) { for (;;) { - operations.watch(key); + generalOps.watch(key); if (expect == get()) { - operations.multi(); + generalOps.multi(); set(update); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return true; } } @@ -112,11 +115,11 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public int getAndIncrement() { for (;;) { - operations.watch(key); + generalOps.watch(key); int value = get(); - operations.multi(); + generalOps.multi(); operations.increment(key, 1); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return value; } } @@ -129,11 +132,11 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public int getAndDecrement() { for (;;) { - operations.watch(key); + generalOps.watch(key); int value = get(); - operations.multi(); + generalOps.multi(); operations.increment(key, -1); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return value; } } @@ -147,11 +150,11 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public int getAndAdd(int delta) { for (;;) { - operations.watch(key); + generalOps.watch(key); int value = get(); - operations.multi(); + generalOps.multi(); set(value + delta); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return value; } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java index 007062a3e..8829e336a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java @@ -18,6 +18,7 @@ package org.springframework.data.keyvalue.redis.util; import java.io.Serializable; import org.springframework.data.keyvalue.redis.core.RedisOperations; +import org.springframework.data.keyvalue.redis.core.ValueOperations; /** * Atomic long backed by Redis. @@ -29,7 +30,8 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations; public class RedisAtomicLong extends Number implements Serializable { private final String key; - private RedisOperations operations; + private ValueOperations operations; + private RedisOperations generalOps; /** * Constructs a new RedisAtomicLong instance with an initial value of zero. @@ -50,8 +52,8 @@ public class RedisAtomicLong extends Number implements Serializable { */ public RedisAtomicLong(String redisCounter, RedisOperations operations, long initialValue) { this.key = redisCounter; - this.operations = operations; - operations.set(redisCounter, initialValue); + this.operations = operations.valueOps(); + this.operations.set(redisCounter, initialValue); } /** @@ -93,11 +95,11 @@ public class RedisAtomicLong extends Number implements Serializable { */ public boolean compareAndSet(long expect, long update) { for (;;) { - operations.watch(key); + generalOps.watch(key); if (expect == get()) { - operations.multi(); + generalOps.multi(); set(update); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return true; } } @@ -114,11 +116,11 @@ public class RedisAtomicLong extends Number implements Serializable { */ public long getAndIncrement() { for (;;) { - operations.watch(key); + generalOps.watch(key); long value = get(); - operations.multi(); + generalOps.multi(); operations.increment(key, 1); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return value; } } @@ -131,11 +133,11 @@ public class RedisAtomicLong extends Number implements Serializable { */ public long getAndDecrement() { for (;;) { - operations.watch(key); + generalOps.watch(key); long value = get(); - operations.multi(); + generalOps.multi(); operations.increment(key, -1); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return value; } } @@ -149,11 +151,11 @@ public class RedisAtomicLong extends Number implements Serializable { */ public long getAndAdd(long delta) { for (;;) { - operations.watch(key); + generalOps.watch(key); long value = get(); - operations.multi(); + generalOps.multi(); set(value + delta); - if (operations.exec() != null) { + if (generalOps.exec() != null) { return value; } } From a20fabd7f393f1d1f9308485fbcf38cc5a518ac5 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 20:44:44 +0200 Subject: [PATCH 05/12] + add expireAt on RedisConnection --- .../keyvalue/redis/connection/RedisCommands.java | 2 ++ .../redis/connection/jedis/JedisConnection.java | 13 +++++++++++++ .../redis/connection/jredis/JredisConnection.java | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java index 6e1497c4e..8b227f9d6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java @@ -44,6 +44,8 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red Boolean expire(byte[] key, int seconds); + Boolean expireAt(byte[] key, long unixTime); + Boolean persist(byte[] key); Integer ttl(byte[] key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 25672176b..e878174df 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -190,6 +190,19 @@ public class JedisConnection implements RedisConnection { } } + @Override + public Boolean expireAt(byte[] key, long unixTime) { + try { + if (isQueueing()) { + transaction.expireAt(key, unixTime); + return null; + } + return (jedis.expireAt(key, unixTime) == 1); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + @Override public Collection keys(byte[] pattern) { try { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 94bced134..2cc0810d1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -134,6 +134,15 @@ public class JredisConnection implements RedisConnection { } } + @Override + public Boolean expireAt(byte[] key, long unixTime) { + try { + return jredis.expireat(JredisUtils.convert(charset, key), unixTime); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } + } + @Override public Collection keys(byte[] pattern) { try { From 5afb74596a7c7310de698dfd910ed6e119adf62d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 20:57:10 +0200 Subject: [PATCH 06/12] + updated some of the redis operations signatures --- .../keyvalue/redis/core/RedisOperations.java | 2 +- .../keyvalue/redis/core/RedisTemplate.java | 113 ++++++++++++++++-- 2 files changed, 103 insertions(+), 12 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index d67ce65a1..b1ff55ed4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -36,7 +36,7 @@ public interface RedisOperations { DataType type(K key); - Set keys(String pattern); + Set keys(K pattern); K randomKey(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 9be0a90d5..cd83d47af 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -279,6 +279,19 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return values; } + @SuppressWarnings("unchecked") + private Collection deserializeKeys(Collection rawKeys, Class type) { + Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawKeys.size()) + : new LinkedHashSet(rawKeys.size())); + for (byte[] bs : rawKeys) { + if (bs != null) { + values.add((K) hashValueSerializer.deserialize(bs)); + } + } + + return values; + } + @SuppressWarnings("unchecked") private K deserializeKey(byte[] value) { return (K) deserialize(value, keySerializer); @@ -359,17 +372,40 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public Boolean exists(K key) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.exists(rawKey); + } + }, true); } @Override public Boolean expire(K key, long timeout, TimeUnit unit) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + final int rawTimeout = (int) unit.toSeconds(timeout); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.expire(rawKey, rawTimeout); + } + }, true); } @Override public Boolean expireAt(K key, Date date) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + final long rawTimeout = date.getTime(); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.expireAt(rawKey, rawTimeout); + } + }, true); } // @@ -378,37 +414,92 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public long getExpire(K key) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return Long.valueOf(connection.ttl(rawKey)); + } + }, true); } @Override - public Set keys(String pattern) { - throw new UnsupportedOperationException(); + public Set keys(K pattern) { + final byte[] rawKey = rawKey(pattern); + + Collection rawKeys = execute(new RedisCallback>() { + @Override + public Collection doInRedis(RedisConnection connection) { + return connection.keys(rawKey); + } + }, true); + + return (Set) deserializeKeys(rawKeys, Set.class); } @Override public void persist(K key) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.persist(rawKey); + return null; + } + }, true); } @Override public K randomKey() { - throw new UnsupportedOperationException(); + byte[] rawKey = execute(new RedisCallback() { + @Override + public byte[] doInRedis(RedisConnection connection) { + return connection.randomKey(); + } + }, true); + + return deserializeKey(rawKey); } @Override public void rename(K oldKey, K newKey) { - throw new UnsupportedOperationException(); + final byte[] rawOldKey = rawKey(oldKey); + final byte[] rawNewKey = rawKey(newKey); + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.rename(rawOldKey, rawNewKey); + return null; + } + }, true); } @Override public Boolean renameIfAbsent(K oldKey, K newKey) { - throw new UnsupportedOperationException(); + final byte[] rawOldKey = rawKey(oldKey); + final byte[] rawNewKey = rawKey(newKey); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.renameNX(rawOldKey, rawNewKey); + } + }, true); } @Override public DataType type(K key) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public DataType doInRedis(RedisConnection connection) { + return connection.type(rawKey); + } + }, true); } @Override From 5e1427f29e67f21ddb3518a5c784b43813a97472 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 21:18:52 +0200 Subject: [PATCH 07/12] + add missing implementations --- .../keyvalue/redis/core/RedisTemplate.java | 78 +++++++++++++++++-- .../util/AbstractRedisCollectionTests.java | 3 +- .../redis/util/AbstractRedisMapTests.java | 3 +- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index cd83d47af..a9b1a9dcc 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -562,17 +562,67 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public Collection multiGet(Set keys) { - throw new UnsupportedOperationException(); + if (keys.isEmpty()) { + return Collections.emptyList(); + } + + final byte[][] rawKeys = new byte[keys.size()][]; + + int counter = 0; + for (K hashKey : keys) { + rawKeys[counter++] = rawKey(hashKey); + } + + List rawValues = execute(new RedisCallback>() { + @Override + public List doInRedis(RedisConnection connection) { + return connection.mGet(rawKeys); + } + }, true); + + return (List) values(rawValues, List.class); } @Override public void multiSet(Map m) { - throw new UnsupportedOperationException(); + if (m.isEmpty()) { + return; + } + + final Map rawKeys = new LinkedHashMap(m.size()); + + for (Map.Entry entry : m.entrySet()) { + rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue())); + } + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.mSet(rawKeys); + return null; + } + }, true); } @Override public void multiSetIfAbsent(Map m) { - throw new UnsupportedOperationException(); + if (m.isEmpty()) { + return; + } + + final Map rawKeys = new LinkedHashMap(m.size()); + + for (Map.Entry entry : m.entrySet()) { + rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue())); + } + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.mSetNX(rawKeys); + return null; + } + }, true); } @Override @@ -589,12 +639,30 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public void set(K key, V value, long timeout, TimeUnit unit) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + final long rawTimeout = unit.toSeconds(timeout); + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) throws DataAccessException { + connection.setEx(rawKey, (int) rawTimeout, rawValue); + return null; + } + }, true); } @Override public Boolean setIfAbsent(K key, V value) { - throw new UnsupportedOperationException(); + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) throws DataAccessException { + return connection.setNX(rawKey, rawValue); + } + }, true); } } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java index b58e17318..8ab30cf04 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisCollectionTests.java @@ -22,6 +22,7 @@ import static org.junit.matchers.JUnitMatchers.*; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -101,7 +102,7 @@ public abstract class AbstractRedisCollectionTests { @After public void tearDown() throws Exception { // remove the collection entirely since clear() doesn't always work - collection.getOperations().delete(collection.getKey()); + collection.getOperations().delete(Collections.singleton(collection.getKey())); template.execute(new RedisCallback() { @Override diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java index ab67e738b..ca50514b0 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java @@ -21,6 +21,7 @@ import static org.junit.matchers.JUnitMatchers.*; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -101,7 +102,7 @@ public abstract class AbstractRedisMapTests { @After public void tearDown() throws Exception { // remove the collection entirely since clear() doesn't always work - map.getOperations().delete(map.getKey()); + map.getOperations().delete(Collections.singleton(map.getKey())); template.execute(new RedisCallback() { @Override From 53e585040acd2780f660aabcf9493edef818ea4d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 21:37:39 +0200 Subject: [PATCH 08/12] + remove generified vargs signature from public interface --- .../data/keyvalue/redis/core/RedisOperations.java | 2 +- .../data/keyvalue/redis/core/RedisTemplate.java | 2 +- .../data/keyvalue/redis/util/RedisAtomicInteger.java | 9 +++++---- .../data/keyvalue/redis/util/RedisAtomicLong.java | 9 +++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index b1ff55ed4..ca2783b05 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -52,7 +52,7 @@ public interface RedisOperations { long getExpire(K key); - void watch(K... keys); + void watch(Collection keys); void multi(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index a9b1a9dcc..ce02e8235 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -689,7 +689,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public void watch(K... keys) { + public void watch(Collection keys) { final byte[][] rawKeys = rawKeys(keys); execute(new RedisCallback() { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java index e557b9fca..fd922dbc0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicInteger.java @@ -16,6 +16,7 @@ package org.springframework.data.keyvalue.redis.util; import java.io.Serializable; +import java.util.Collections; import org.springframework.data.keyvalue.redis.core.RedisOperations; import org.springframework.data.keyvalue.redis.core.ValueOperations; @@ -95,7 +96,7 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public boolean compareAndSet(int expect, int update) { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); if (expect == get()) { generalOps.multi(); set(update); @@ -115,7 +116,7 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public int getAndIncrement() { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); int value = get(); generalOps.multi(); operations.increment(key, 1); @@ -132,7 +133,7 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public int getAndDecrement() { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); int value = get(); generalOps.multi(); operations.increment(key, -1); @@ -150,7 +151,7 @@ public class RedisAtomicInteger extends Number implements Serializable { */ public int getAndAdd(int delta) { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); int value = get(); generalOps.multi(); set(value + delta); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java index 8829e336a..aced40361 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisAtomicLong.java @@ -16,6 +16,7 @@ package org.springframework.data.keyvalue.redis.util; import java.io.Serializable; +import java.util.Collections; import org.springframework.data.keyvalue.redis.core.RedisOperations; import org.springframework.data.keyvalue.redis.core.ValueOperations; @@ -95,7 +96,7 @@ public class RedisAtomicLong extends Number implements Serializable { */ public boolean compareAndSet(long expect, long update) { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); if (expect == get()) { generalOps.multi(); set(update); @@ -116,7 +117,7 @@ public class RedisAtomicLong extends Number implements Serializable { */ public long getAndIncrement() { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); long value = get(); generalOps.multi(); operations.increment(key, 1); @@ -133,7 +134,7 @@ public class RedisAtomicLong extends Number implements Serializable { */ public long getAndDecrement() { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); long value = get(); generalOps.multi(); operations.increment(key, -1); @@ -151,7 +152,7 @@ public class RedisAtomicLong extends Number implements Serializable { */ public long getAndAdd(long delta) { for (;;) { - generalOps.watch(key); + generalOps.watch(Collections.singleton(key)); long value = get(); generalOps.multi(); set(value + delta); From d542a0c3fd74430fbc0335215dc1fdbbc868ee77 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 21:40:54 +0200 Subject: [PATCH 09/12] + renamed length to size on List contract --- .../data/keyvalue/redis/core/DefaultBoundListOperations.java | 2 +- .../data/keyvalue/redis/core/ListOperations.java | 2 +- .../springframework/data/keyvalue/redis/core/RedisTemplate.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index 64e9f47b0..51c8168c4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -61,7 +61,7 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou @Override public Integer length() { - return ops.length(getKey()); + return ops.size(getKey()); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java index 42e613bb2..92d3073ce 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java @@ -28,7 +28,7 @@ public interface ListOperations { void trim(K key, int start, int end); - Integer length(K key); + Integer size(K key); Integer leftPush(K key, V value); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index ce02e8235..6de3a5ed2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -763,7 +763,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer length(K key) { + public Integer size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { @Override From bcbb6d67ae9d1481a00b5f3604a2944bba21d3d2 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 30 Nov 2010 21:42:56 +0200 Subject: [PATCH 10/12] + renamed length to size on Hash ops --- .../data/keyvalue/redis/core/DefaultBoundHashOperations.java | 2 +- .../data/keyvalue/redis/core/HashOperations.java | 2 +- .../springframework/data/keyvalue/redis/core/RedisTemplate.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java index c7870393c..9d5d650b0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java @@ -76,7 +76,7 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement @Override public Integer length() { - return ops.length(getKey()); + return ops.size(getKey()); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java index 213d4550d..39407c43c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java @@ -38,7 +38,7 @@ public interface HashOperations { Set keys(H key); - Integer length(H key); + Integer size(H key); void multiSet(H key, Map m); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 6de3a5ed2..bd34d1a00 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -1287,7 +1287,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer length(K key) { + public Integer size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { From 9b0067ce72a39f5951c6a29bfb551b2939fb5960 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 2 Dec 2010 14:04:36 +0200 Subject: [PATCH 11/12] + replaced usage of int/Integers to long/Long for consistent results between x86/x64 Redis instances + updated some method names to be consistent between interfaces + converted return types from primitives to objects + updated to Jedis 1.5.0-RC1 --- spring-data-redis/pom.xml | 8 +- .../redis/connection/RedisCommands.java | 8 +- .../redis/connection/RedisHashCommands.java | 4 +- .../redis/connection/RedisListCommands.java | 16 +- .../redis/connection/RedisSetCommands.java | 2 +- .../redis/connection/RedisStringCommands.java | 14 +- .../redis/connection/RedisZSetCommands.java | 32 ++-- .../connection/jedis/JedisConnection.java | 140 +++++++++--------- .../jedis/JedisConnectionFactory.java | 19 ++- .../redis/connection/jedis/JedisUtils.java | 4 +- .../connection/jredis/JredisConnection.java | 114 +++++++------- .../redis/core/BoundHashOperations.java | 4 +- .../redis/core/BoundListOperations.java | 16 +- .../redis/core/BoundSetOperations.java | 6 +- .../redis/core/BoundValueOperations.java | 2 +- .../redis/core/BoundZSetOperations.java | 16 +- .../core/DefaultBoundHashOperations.java | 4 +- .../core/DefaultBoundListOperations.java | 16 +- .../redis/core/DefaultBoundSetOperations.java | 6 +- .../core/DefaultBoundValueOperations.java | 2 +- .../core/DefaultBoundZSetOperations.java | 16 +- .../keyvalue/redis/core/HashOperations.java | 4 +- .../keyvalue/redis/core/ListOperations.java | 16 +- .../keyvalue/redis/core/RedisTemplate.java | 88 +++++------ .../keyvalue/redis/core/SetOperations.java | 6 +- .../keyvalue/redis/core/ValueOperations.java | 2 +- .../keyvalue/redis/core/ZSetOperations.java | 16 +- .../keyvalue/redis/util/DefaultRedisList.java | 8 +- .../keyvalue/redis/util/DefaultRedisMap.java | 4 +- .../keyvalue/redis/util/DefaultRedisSet.java | 2 +- .../keyvalue/redis/util/DefaultRedisZSet.java | 12 +- .../data/keyvalue/redis/util/RedisList.java | 2 +- .../data/keyvalue/redis/util/RedisMap.java | 2 +- .../data/keyvalue/redis/util/RedisZSet.java | 10 +- .../AbstractConnectionIntegrationTests.java | 6 +- .../redis/util/AbstractRedisMapTests.java | 2 +- .../redis/util/AbstractRedisZSetTest.java | 12 +- spring-data-redis/template.mf | 3 +- 38 files changed, 320 insertions(+), 324 deletions(-) diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 7447c7a8e..dfc296837 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -13,7 +13,7 @@ 02112010 - 1.4.0 + 1.5.0-RC1 @@ -115,12 +115,6 @@ compile - - org.springframework.commons - spring-commons-serializer - 1.0.0.M1 - compile - diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java index 8b227f9d6..e52c2bd4a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java @@ -28,7 +28,7 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red Boolean exists(byte[] key); - Integer del(byte[]... keys); + Long del(byte[]... keys); DataType type(byte[] key); @@ -40,15 +40,15 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red Boolean renameNX(byte[] oldName, byte[] newName); - Integer dbSize(); + Long dbSize(); - Boolean expire(byte[] key, int seconds); + Boolean expire(byte[] key, long seconds); Boolean expireAt(byte[] key, long unixTime); Boolean persist(byte[] key); - Integer ttl(byte[] key); + Long ttl(byte[] key); void select(int dbIndex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisHashCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisHashCommands.java index 13a15de10..03fc2ba70 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisHashCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisHashCommands.java @@ -37,13 +37,13 @@ public interface RedisHashCommands { void hMSet(byte[] key, Map hashes); - Integer hIncrBy(byte[] key, byte[] field, int delta); + Long hIncrBy(byte[] key, byte[] field, long delta); Boolean hExists(byte[] key, byte[] field); Boolean hDel(byte[] key, byte[] field); - Integer hLen(byte[] key); + Long hLen(byte[] key); Set hKeys(byte[] key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java index 31094e9a9..030040eb9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisListCommands.java @@ -25,21 +25,21 @@ import java.util.List; */ public interface RedisListCommands { - Integer rPush(byte[] key, byte[] value); + Long rPush(byte[] key, byte[] value); - Integer lPush(byte[] key, byte[] value); + Long lPush(byte[] key, byte[] value); - Integer lLen(byte[] key); + Long lLen(byte[] key); - List lRange(byte[] key, int start, int end); + List lRange(byte[] key, long start, long end); - void lTrim(byte[] key, int start, int end); + void lTrim(byte[] key, long start, long end); - byte[] lIndex(byte[] key, int index); + byte[] lIndex(byte[] key, long index); - void lSet(byte[] key, int index, byte[] value); + void lSet(byte[] key, long index, byte[] value); - Integer lRem(byte[] key, int count, byte[] value); + Long lRem(byte[] key, long count, byte[] value); byte[] lPop(byte[] key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSetCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSetCommands.java index f2a28da88..184cf57ae 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSetCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSetCommands.java @@ -33,7 +33,7 @@ public interface RedisSetCommands { Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value); - Integer sCard(byte[] key); + Long sCard(byte[] key); Boolean sIsMember(byte[] key, byte[] value); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java index 53391a170..49fc1d5ab 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java @@ -36,21 +36,21 @@ public interface RedisStringCommands { Boolean setNX(byte[] key, byte[] value); - void setEx(byte[] key, int seconds, byte[] value); + void setEx(byte[] key, long seconds, byte[] value); void mSet(Map tuple); void mSetNX(Map tuple); - Integer incr(byte[] key); + Long incr(byte[] key); - Integer incrBy(byte[] key, int value); + Long incrBy(byte[] key, long value); - Integer decr(byte[] key); + Long decr(byte[] key); - Integer decrBy(byte[] key, int value); + Long decrBy(byte[] key, long value); - Integer append(byte[] key, byte[] value); + Long append(byte[] key, byte[] value); - byte[] substr(byte[] key, int start, int end); + byte[] substr(byte[] key, long start, long end); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisZSetCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisZSetCommands.java index 76eb7ea43..223f53d31 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisZSetCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisZSetCommands.java @@ -42,41 +42,41 @@ public interface RedisZSetCommands { Double zIncrBy(byte[] key, double increment, byte[] value); - Integer zRank(byte[] key, byte[] value); + Long zRank(byte[] key, byte[] value); - Integer zRevRank(byte[] key, byte[] value); + Long zRevRank(byte[] key, byte[] value); - Set zRange(byte[] key, int start, int end); + Set zRange(byte[] key, long start, long end); - Set zRangeWithScore(byte[] key, int start, int end); + Set zRangeWithScore(byte[] key, long start, long end); - Set zRevRange(byte[] key, int start, int end); + Set zRevRange(byte[] key, long start, long end); - Set zRevRangeWithScore(byte[] key, int start, int end); + Set zRevRangeWithScore(byte[] key, long start, long end); Set zRangeByScore(byte[] key, double min, double max); Set zRangeByScoreWithScore(byte[] key, double min, double max); - Set zRangeByScore(byte[] key, double min, double max, int offset, int count); + Set zRangeByScore(byte[] key, double min, double max, long offset, long count); - Set zRangeByScoreWithScore(byte[] key, double min, double max, int offset, int count); + Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count); - Integer zCount(byte[] key, double min, double max); + Long zCount(byte[] key, double min, double max); - Integer zCard(byte[] key); + Long zCard(byte[] key); Double zScore(byte[] key, byte[] value); - Integer zRemRange(byte[] key, int start, int end); + Long zRemRange(byte[] key, long start, long end); - Integer zRemRangeByScore(byte[] key, double min, double max); + Long zRemRangeByScore(byte[] key, double min, double max); - Integer zUnionStore(byte[] destKey, byte[]... sets); + Long zUnionStore(byte[] destKey, byte[]... sets); - Integer zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); + Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); - Integer zInterStore(byte[] destKey, byte[]... sets); + Long zInterStore(byte[] destKey, byte[]... sets); - Integer zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); + Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index e878174df..f1e483e13 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -108,7 +108,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer dbSize() { + public Long dbSize() { try { if (isQueueing()) { transaction.dbSize(); @@ -134,7 +134,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer del(byte[]... keys) { + public Long del(byte[]... keys) { try { if (isQueueing()) { transaction.del(keys); @@ -178,10 +178,10 @@ public class JedisConnection implements RedisConnection { } @Override - public Boolean expire(byte[] key, int seconds) { + public Boolean expire(byte[] key, long seconds) { try { if (isQueueing()) { - transaction.expire(key, seconds); + transaction.expire(key, (int) seconds); return null; } return (jedis.expire(key, (int) seconds) == 1); @@ -289,7 +289,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer ttl(byte[] key) { + public Long ttl(byte[] key) { try { if (isQueueing()) { transaction.ttl(key); @@ -381,7 +381,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer append(byte[] key, byte[] value) { + public Long append(byte[] key, byte[] value) { try { if (isQueueing()) { transaction.append(key, value); @@ -431,12 +431,12 @@ public class JedisConnection implements RedisConnection { } @Override - public void setEx(byte[] key, int time, byte[] value) { + public void setEx(byte[] key, long time, byte[] value) { try { if (isQueueing()) { - transaction.setex(key, time, value); + transaction.setex(key, (int) time, value); } - jedis.setex(key, time, value); + jedis.setex(key, (int) time, value); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -455,20 +455,20 @@ public class JedisConnection implements RedisConnection { } @Override - public byte[] substr(byte[] key, int start, int end) { + public byte[] substr(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.substr(key, start, end); + transaction.substr(key, (int) start, (int) end); return null; } - return jedis.substr(key, start, end); + return jedis.substr(key, (int) start, (int) end); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer decr(byte[] key) { + public Long decr(byte[] key) { try { if (isQueueing()) { transaction.decr(key); @@ -481,20 +481,20 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer decrBy(byte[] key, int value) { + public Long decrBy(byte[] key, long value) { try { if (isQueueing()) { - transaction.decrBy(key, value); + transaction.decrBy(key, (int) value); return null; } - return jedis.decrBy(key, value); + return jedis.decrBy(key, (int) value); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer incr(byte[] key) { + public Long incr(byte[] key) { try { if (isQueueing()) { transaction.incr(key); @@ -507,13 +507,13 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer incrBy(byte[] key, int value) { + public Long incrBy(byte[] key, long value) { try { if (isQueueing()) { - transaction.incrBy(key, value); + transaction.incrBy(key, (int) value); return null; } - return jedis.incrBy(key, value); + return jedis.incrBy(key, (int) value); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -525,7 +525,7 @@ public class JedisConnection implements RedisConnection { @Override - public Integer lPush(byte[] key, byte[] value) { + public Long lPush(byte[] key, byte[] value) { try { if (isQueueing()) { transaction.lpush(key, value); @@ -538,7 +538,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer rPush(byte[] key, byte[] value) { + public Long rPush(byte[] key, byte[] value) { try { if (isQueueing()) { transaction.rpush(key, value); @@ -575,20 +575,20 @@ public class JedisConnection implements RedisConnection { } @Override - public byte[] lIndex(byte[] key, int index) { + public byte[] lIndex(byte[] key, long index) { try { if (isQueueing()) { - transaction.lindex(key, index); + transaction.lindex(key, (int) index); return null; } - return jedis.lindex(key, index); + return jedis.lindex(key, (int) index); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer lLen(byte[] key) { + public Long lLen(byte[] key) { try { if (isQueueing()) { transaction.llen(key); @@ -614,50 +614,50 @@ public class JedisConnection implements RedisConnection { } @Override - public List lRange(byte[] key, int start, int end) { + public List lRange(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.lrange(key, start, end); + transaction.lrange(key, (int) start, (int) end); return null; } - return jedis.lrange(key, start, end); + return jedis.lrange(key, (int) start, (int) end); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer lRem(byte[] key, int count, byte[] value) { + public Long lRem(byte[] key, long count, byte[] value) { try { if (isQueueing()) { - transaction.lrem(key, count, value); + transaction.lrem(key, (int) count, value); return null; } - return jedis.lrem(key, count, value); + return jedis.lrem(key, (int) count, value); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public void lSet(byte[] key, int index, byte[] value) { + public void lSet(byte[] key, long index, byte[] value) { try { if (isQueueing()) { - transaction.lset(key, index, value); + transaction.lset(key, (int) index, value); } - jedis.lset(key, index, value); + jedis.lset(key, (int) index, value); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public void lTrim(byte[] key, int start, int end) { + public void lTrim(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.ltrim(key, start, end); + transaction.ltrim(key, (int) start, (int) end); } - jedis.ltrim(key, start, end); + jedis.ltrim(key, (int) start, (int) end); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -708,7 +708,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer sCard(byte[] key) { + public Long sCard(byte[] key) { try { if (isQueueing()) { transaction.scard(key); @@ -891,7 +891,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zCard(byte[] key) { + public Long zCard(byte[] key) { try { if (isQueueing()) { transaction.zcard(key); @@ -904,7 +904,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zCount(byte[] key, double min, double max) { + public Long zCount(byte[] key, double min, double max) { try { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -929,7 +929,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -943,7 +943,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zInterStore(byte[] destKey, byte[]... sets) { + public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -955,26 +955,26 @@ public class JedisConnection implements RedisConnection { } @Override - public Set zRange(byte[] key, int start, int end) { + public Set zRange(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.zrange(key, start, end); + transaction.zrange(key, (int) start, (int) end); return null; } - return jedis.zrange(key, start, end); + return jedis.zrange(key, (int) start, (int) end); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Set zRangeWithScore(byte[] key, int start, int end) { + public Set zRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.zrangeWithScores(key, start, end); + transaction.zrangeWithScores(key, (int) start, (int) end); return null; } - return JedisUtils.convertJedisTuple(jedis.zrangeWithScores(key, start, end)); + return JedisUtils.convertJedisTuple(jedis.zrangeWithScores(key, (int) start, (int) end)); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1005,44 +1005,44 @@ public class JedisConnection implements RedisConnection { } @Override - public Set zRevRangeWithScore(byte[] key, int start, int end) { + public Set zRevRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.zrangeWithScores(key, start, end); + transaction.zrangeWithScores(key, (int) start, (int) end); return null; } - return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, start, end)); + return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, (int) start, (int) end)); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Set zRangeByScore(byte[] key, double min, double max, int offset, int count) { + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { throw new UnsupportedOperationException(); } - return jedis.zrangeByScore(key, min, max, offset, count); + return jedis.zrangeByScore(key, min, max, (int) offset, (int) count); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Set zRangeByScoreWithScore(byte[] key, double min, double max, int offset, int count) { + public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { throw new UnsupportedOperationException(); } - return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, min, max, offset, count)); + return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count)); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer zRank(byte[] key, byte[] value) { + public Long zRank(byte[] key, byte[] value) { try { if (isQueueing()) { transaction.zrank(key, value); @@ -1068,19 +1068,19 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zRemRange(byte[] key, int start, int end) { + public Long zRemRange(byte[] key, long start, long end) { try { if (isQueueing()) { throw new UnsupportedOperationException(); } - return jedis.zremrangeByRank(key, start, end); + return jedis.zremrangeByRank(key, (int) start, (int) end); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer zRemRangeByScore(byte[] key, double min, double max) { + public Long zRemRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -1092,20 +1092,20 @@ public class JedisConnection implements RedisConnection { } @Override - public Set zRevRange(byte[] key, int start, int end) { + public Set zRevRange(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.zrevrange(key, start, end); + transaction.zrevrange(key, (int) start, (int) end); return null; } - return jedis.zrevrange(key, start, end); + return jedis.zrevrange(key, (int) start, (int) end); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public Integer zRevRank(byte[] key, byte[] value) { + public Long zRevRank(byte[] key, byte[] value) { try { if (isQueueing()) { transaction.zrevrank(key, value); @@ -1131,7 +1131,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -1145,7 +1145,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer zUnionStore(byte[] destKey, byte[]... sets) { + public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -1239,13 +1239,13 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer hIncrBy(byte[] key, byte[] field, int delta) { + public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isQueueing()) { - transaction.hincrBy(key, field, delta); + transaction.hincrBy(key, field, (int) delta); return null; } - return jedis.hincrBy(key, field, delta); + return jedis.hincrBy(key, field, (int) delta); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1265,7 +1265,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Integer hLen(byte[] key) { + public Long hLen(byte[] key) { try { if (isQueueing()) { transaction.hlen(key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index 33e8e6d82..527f236bf 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -16,13 +16,13 @@ package org.springframework.data.keyvalue.redis.connection.jedis; -import java.util.concurrent.TimeoutException; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.pool.impl.GenericObjectPool; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.util.Assert; @@ -99,8 +99,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, return pool.getResource(); } return new Jedis(getShardInfo()); - } catch (TimeoutException ex) { - throw JedisUtils.convertJedisAccessException(ex); + } catch (Exception ex) { + throw new DataAccessResourceFailureException("Cannot get Jedis connection", ex); } } @@ -115,15 +115,18 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, if (usePool) { int size = getPoolSize(); - pool = new JedisPool(shardInfo); - pool.setResourcesNumber(size); - pool.init(); + pool = new JedisPool(new GenericObjectPool.Config(), shardInfo.getHost(), shardInfo.getPort(), + shardInfo.getTimeout(), shardInfo.getPassword()); } } public void destroy() { if (usePool && pool != null) { - pool.destroy(); + try { + pool.destroy(); + } catch (Exception ex) { + log.warn("Cannot properly close Jedis pool", ex); + } pool = null; } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java index fd20c36f8..924e9e382 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java @@ -70,8 +70,8 @@ public abstract class JedisUtils { return status != null && (OK_CODE.equals(status) || OK_MULTI_CODE.equals(status)); } - static Boolean convertCodeReply(Integer code) { - return (code != null ? code == 1 : null); + static Boolean convertCodeReply(Number code) { + return (code != null ? code.intValue() == 1 : null); } static Set convertJedisTuple(Set tuples) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 2cc0810d1..d4f939d0c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -76,9 +76,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer dbSize() { + public Long dbSize() { try { - return Integer.valueOf((int) jredis.dbsize()); + return jredis.dbsize(); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -94,9 +94,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer del(byte[]... keys) { + public Long del(byte[]... keys) { try { - return Integer.valueOf((int) jredis.del(JredisUtils.convertMultiple(charset, keys))); + return jredis.del(JredisUtils.convertMultiple(charset, keys)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -126,9 +126,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Boolean expire(byte[] key, int seconds) { + public Boolean expire(byte[] key, long seconds) { try { - return jredis.expire(JredisUtils.convert(charset, key), seconds); + return jredis.expire(JredisUtils.convert(charset, key), (int) seconds); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -195,9 +195,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer ttl(byte[] key) { + public Long ttl(byte[] key) { try { - return Integer.valueOf((int) jredis.ttl(JredisUtils.convert(charset, key))); + return jredis.ttl(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -254,9 +254,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer append(byte[] key, byte[] value) { + public Long append(byte[] key, byte[] value) { try { - return Integer.valueOf((int) jredis.append(JredisUtils.convert(charset, key), value)); + return jredis.append(JredisUtils.convert(charset, key), value); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -290,7 +290,7 @@ public class JredisConnection implements RedisConnection { } @Override - public void setEx(byte[] key, int seconds, byte[] value) { + public void setEx(byte[] key, long seconds, byte[] value) { throw new UnsupportedOperationException(); } @@ -304,7 +304,7 @@ public class JredisConnection implements RedisConnection { } @Override - public byte[] substr(byte[] key, int start, int end) { + public byte[] substr(byte[] key, long start, long end) { try { return jredis.substr(JredisUtils.convert(charset, key), (long) start, (long) end); } catch (RedisException ex) { @@ -313,36 +313,36 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer decr(byte[] key) { + public Long decr(byte[] key) { try { - return (int) jredis.decr(JredisUtils.convert(charset, key)); + return jredis.decr(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public Integer decrBy(byte[] key, int value) { + public Long decrBy(byte[] key, long value) { try { - return (int) jredis.decrby(JredisUtils.convert(charset, key), value); + return jredis.decrby(JredisUtils.convert(charset, key), (int) value); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public Integer incr(byte[] key) { + public Long incr(byte[] key) { try { - return (int) jredis.incr(JredisUtils.convert(charset, key)); + return jredis.incr(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public Integer incrBy(byte[] key, int value) { + public Long incrBy(byte[] key, long value) { try { - return (int) jredis.incrby(JredisUtils.convert(charset, key), value); + return jredis.incrby(JredisUtils.convert(charset, key), (int) value); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -363,7 +363,7 @@ public class JredisConnection implements RedisConnection { } @Override - public byte[] lIndex(byte[] key, int index) { + public byte[] lIndex(byte[] key, long index) { try { return jredis.lindex(JredisUtils.convert(charset, key), (long) index); } catch (RedisException ex) { @@ -372,9 +372,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer lLen(byte[] key) { + public Long lLen(byte[] key) { try { - return Integer.valueOf((int) jredis.llen(JredisUtils.convert(charset, key))); + return jredis.llen(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -390,7 +390,7 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer lPush(byte[] key, byte[] value) { + public Long lPush(byte[] key, byte[] value) { try { jredis.lpush(JredisUtils.convert(charset, key), value); return null; @@ -400,7 +400,7 @@ public class JredisConnection implements RedisConnection { } @Override - public List lRange(byte[] key, int start, int end) { + public List lRange(byte[] key, long start, long end) { try { List lrange = jredis.lrange(JredisUtils.convert(charset, key), start, end); @@ -411,16 +411,16 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer lRem(byte[] key, int count, byte[] value) { + public Long lRem(byte[] key, long count, byte[] value) { try { - return Integer.valueOf((int) jredis.lrem(JredisUtils.convert(charset, key), value, count)); + return jredis.lrem(JredisUtils.convert(charset, key), value, (int) count); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public void lSet(byte[] key, int index, byte[] value) { + public void lSet(byte[] key, long index, byte[] value) { try { jredis.lset(JredisUtils.convert(charset, key), index, value); } catch (RedisException ex) { @@ -429,7 +429,7 @@ public class JredisConnection implements RedisConnection { } @Override - public void lTrim(byte[] key, int start, int end) { + public void lTrim(byte[] key, long start, long end) { try { jredis.ltrim(JredisUtils.convert(charset, key), start, end); } catch (RedisException ex) { @@ -456,7 +456,7 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer rPush(byte[] key, byte[] value) { + public Long rPush(byte[] key, byte[] value) { try { jredis.rpush(JredisUtils.convert(charset, key), value); return null; @@ -479,9 +479,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer sCard(byte[] key) { + public Long sCard(byte[] key) { try { - return Integer.valueOf((int) jredis.scard(JredisUtils.convert(charset, key))); + return jredis.scard(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -630,18 +630,18 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer zCard(byte[] key) { + public Long zCard(byte[] key) { try { - return Integer.valueOf((int) jredis.zcard(JredisUtils.convert(charset, key))); + return jredis.zcard(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public Integer zCount(byte[] key, double min, double max) { + public Long zCount(byte[] key, double min, double max) { try { - return Integer.valueOf((int) jredis.zcount(JredisUtils.convert(charset, key), min, max)); + return jredis.zcount(JredisUtils.convert(charset, key), min, max); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -657,17 +657,17 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } @Override - public Integer zInterStore(byte[] destKey, byte[]... sets) { + public Long zInterStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } @Override - public Set zRange(byte[] key, int start, int end) { + public Set zRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrange(JredisUtils.convert(charset, key), (long) start, (long) end)); } catch (RedisException ex) { @@ -676,7 +676,7 @@ public class JredisConnection implements RedisConnection { } @Override - public Set zRangeWithScore(byte[] key, int start, int end) { + public Set zRangeWithScore(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } @@ -696,19 +696,19 @@ public class JredisConnection implements RedisConnection { } @Override - public Set zRangeByScore(byte[] key, double min, double max, int offset, int count) { + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } @Override - public Set zRangeByScoreWithScore(byte[] key, double min, double max, int offset, int count) { + public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } @Override - public Integer zRank(byte[] key, byte[] value) { + public Long zRank(byte[] key, byte[] value) { try { - return Integer.valueOf((int) jredis.zrank(JredisUtils.convert(charset, key), value)); + return jredis.zrank(JredisUtils.convert(charset, key), value); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -724,25 +724,25 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer zRemRange(byte[] key, int start, int end) { + public Long zRemRange(byte[] key, long start, long end) { try { - return Integer.valueOf((int) jredis.zremrangebyrank(JredisUtils.convert(charset, key), start, end)); + return jredis.zremrangebyrank(JredisUtils.convert(charset, key), start, end); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public Integer zRemRangeByScore(byte[] key, double min, double max) { + public Long zRemRangeByScore(byte[] key, double min, double max) { try { - return Integer.valueOf((int) jredis.zremrangebyscore(JredisUtils.convert(charset, key), min, max)); + return jredis.zremrangebyscore(JredisUtils.convert(charset, key), min, max); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } } @Override - public Set zRevRange(byte[] key, int start, int end) { + public Set zRevRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrevrange(JredisUtils.convert(charset, key), start, end)); } catch (RedisException ex) { @@ -751,14 +751,14 @@ public class JredisConnection implements RedisConnection { } @Override - public Set zRevRangeWithScore(byte[] key, int start, int end) { + public Set zRevRangeWithScore(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } @Override - public Integer zRevRank(byte[] key, byte[] value) { + public Long zRevRank(byte[] key, byte[] value) { try { - return Integer.valueOf((int) jredis.zrevrank(JredisUtils.convert(charset, key), value)); + return jredis.zrevrank(JredisUtils.convert(charset, key), value); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } @@ -779,12 +779,12 @@ public class JredisConnection implements RedisConnection { // @Override - public Integer zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } @Override - public Integer zUnionStore(byte[] destKey, byte[]... sets) { + public Long zUnionStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } @@ -825,7 +825,7 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer hIncrBy(byte[] key, byte[] field, int delta) { + public Long hIncrBy(byte[] key, byte[] field, long delta) { throw new UnsupportedOperationException(); } @@ -840,9 +840,9 @@ public class JredisConnection implements RedisConnection { } @Override - public Integer hLen(byte[] key) { + public Long hLen(byte[] key) { try { - return Integer.valueOf((int) jredis.hlen(JredisUtils.convert(charset, key))); + return jredis.hlen(JredisUtils.convert(charset, key)); } catch (RedisException ex) { throw JredisUtils.convertJredisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java index a8a54df8b..00aea0816 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java @@ -30,7 +30,7 @@ public interface BoundHashOperations extends KeyBound { boolean hasKey(Object key); - Integer increment(HK key, int delta); + Long increment(HK key, long delta); HV get(Object key); @@ -44,7 +44,7 @@ public interface BoundHashOperations extends KeyBound { Collection values(); - Integer length(); + Long size(); void delete(Object key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java index ebca7cc13..d28f3d1e3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java @@ -26,23 +26,23 @@ public interface BoundListOperations extends KeyBound { RedisOperations getOperations(); - List range(int start, int end); + List range(long start, long end); - void trim(int start, int end); + void trim(long start, long end); - Integer length(); + Long size(); - Integer leftPush(V value); + Long leftPush(V value); - Integer rightPush(V value); + Long rightPush(V value); V leftPop(); V rightPop(); - Integer remove(int i, Object value); + Long remove(long i, Object value); - V index(int index); + V index(long index); - void set(int index, V value); + void set(long index, V value); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java index 3a9ae4b07..337aa8232 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java @@ -41,11 +41,11 @@ public interface BoundSetOperations extends KeyBound { Boolean add(V value); - boolean isMember(Object o); + Boolean isMember(Object o); Set members(); - boolean remove(Object o); + Boolean remove(Object o); - int size(); + Long size(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java index 3af2455a4..8c64d2a56 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java @@ -32,6 +32,6 @@ public interface BoundValueOperations extends KeyBound { V getAndSet(V value); - V increment(int delta); + V increment(long delta); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java index 8db4ba749..a5d71a9b2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java @@ -30,27 +30,27 @@ public interface BoundZSetOperations extends KeyBound { void intersectAndStore(K destKey, K... keys); - Set range(int start, int end); + Set range(long start, long end); Set rangeByScore(double min, double max); - Set reverseRange(int start, int end); + Set reverseRange(long start, long end); - void removeRange(int start, int end); + void removeRange(long start, long end); void removeRangeByScore(double min, double max); void unionAndStore(K destKey, K... keys); - boolean add(V value, double score); + Boolean add(V value, double score); - Integer rank(Object o); + Long rank(Object o); - Integer reverseRank(Object o); + Long reverseRank(Object o); - boolean remove(Object o); + Boolean remove(Object o); - int size(); + Long size(); Double score(Object o); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java index 9d5d650b0..3b626cf88 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java @@ -65,7 +65,7 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement } @Override - public Integer increment(HK key, int delta) { + public Long increment(HK key, long delta) { return ops.increment(getKey(), key, delta); } @@ -75,7 +75,7 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement } @Override - public Integer length() { + public Long size() { return ops.size(getKey()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index 51c8168c4..2d8a4e4bd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -45,7 +45,7 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou } @Override - public V index(int index) { + public V index(long index) { return ops.index(getKey(), index); } @@ -55,22 +55,22 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou } @Override - public Integer leftPush(V value) { + public Long leftPush(V value) { return ops.leftPush(getKey(), value); } @Override - public Integer length() { + public Long size() { return ops.size(getKey()); } @Override - public List range(int start, int end) { + public List range(long start, long end) { return ops.range(getKey(), start, end); } @Override - public Integer remove(int i, Object value) { + public Long remove(long i, Object value) { return ops.remove(getKey(), i, value); } @@ -80,17 +80,17 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou } @Override - public Integer rightPush(V value) { + public Long rightPush(V value) { return ops.rightPush(getKey(), value); } @Override - public void trim(int start, int end) { + public void trim(long start, long end) { ops.trim(getKey(), start, end); } @Override - public void set(int index, V value) { + public void set(long index, V value) { ops.set(getKey(), index, value); } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java index 910af3682..48358634f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java @@ -70,7 +70,7 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun } @Override - public boolean isMember(Object o) { + public Boolean isMember(Object o) { return ops.isMember(getKey(), o); } @@ -80,12 +80,12 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun } @Override - public boolean remove(Object o) { + public Boolean remove(Object o) { return ops.remove(getKey(), o); } @Override - public int size() { + public Long size() { return ops.size(getKey()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java index 2afc97e48..d5813550c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -46,7 +46,7 @@ class DefaultBoundValueOperations extends DefaultKeyBound implements Bo } @Override - public V increment(int delta) { + public V increment(long delta) { return ops.increment(getKey(), delta); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java index e0d7f9ba9..a0468dfe8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java @@ -39,7 +39,7 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou } @Override - public boolean add(V value, double score) { + public Boolean add(V value, double score) { return ops.add(getKey(), value, score); } @@ -54,7 +54,7 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou } @Override - public Set range(int start, int end) { + public Set range(long start, long end) { return ops.range(getKey(), start, end); } @@ -64,12 +64,12 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou } @Override - public Integer rank(Object o) { + public Long rank(Object o) { return ops.rank(getKey(), o); } @Override - public Integer reverseRank(Object o) { + public Long reverseRank(Object o) { return ops.reverseRank(getKey(), o); } @@ -79,12 +79,12 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou } @Override - public boolean remove(Object o) { + public Boolean remove(Object o) { return ops.remove(getKey(), o); } @Override - public void removeRange(int start, int end) { + public void removeRange(long start, long end) { ops.removeRange(getKey(), start, end); } @@ -94,12 +94,12 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou } @Override - public Set reverseRange(int start, int end) { + public Set reverseRange(long start, long end) { return ops.reverseRange(getKey(), start, end); } @Override - public int size() { + public Long size() { return ops.size(getKey()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java index 39407c43c..7668648a3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java @@ -34,11 +34,11 @@ public interface HashOperations { Collection multiGet(H key, Set hashKeys); - Integer increment(H key, HK hashKey, int delta); + Long increment(H key, HK hashKey, long delta); Set keys(H key); - Integer size(H key); + Long size(H key); void multiSet(H key, Map m); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java index 92d3073ce..31c644940 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ListOperations.java @@ -24,21 +24,21 @@ import java.util.List; */ public interface ListOperations { - List range(K key, int start, int end); + List range(K key, long start, long end); - void trim(K key, int start, int end); + void trim(K key, long start, long end); - Integer size(K key); + Long size(K key); - Integer leftPush(K key, V value); + Long leftPush(K key, V value); - Integer rightPush(K key, V value); + Long rightPush(K key, V value); - void set(K key, int index, V value); + void set(K key, long index, V value); - Integer remove(K key, int i, Object value); + Long remove(K key, long i, Object value); - V index(K key, int index); + V index(K key, long index); V leftPop(K key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index bd34d1a00..e1150bcf0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -537,12 +537,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public V increment(K key, final int delta) { + public V increment(K key, final long delta) { final byte[] rawKey = rawKey(key); // TODO add conversion service in here ? - return (V) execute(new RedisCallback() { + return (V) execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { if (delta == 1) { return connection.incr(rawKey); } @@ -731,7 +731,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public V index(K key, final int index) { + public V index(K key, final long index) { return execute(new ValueDeserializingRedisCallback(key) { @Override protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { @@ -751,30 +751,30 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer leftPush(K key, V value) { + public Long leftPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.lPush(rawKey, rawValue); } }, true); } @Override - public Integer size(K key) { + public Long size(K key) { final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.lLen(rawKey); } }, true); } @Override - public List range(K key, final int start, final int end) { + public List range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback>() { @Override @@ -785,12 +785,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer remove(K key, final int count, Object value) { + public Long remove(K key, final long count, Object value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.lRem(rawKey, count, rawValue); } }, true); @@ -807,19 +807,19 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer rightPush(K key, V value) { + public Long rightPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.rPush(rawKey, rawValue); } }, true); } @Override - public void set(K key, final int index, V value) { + public void set(K key, final long index, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { @Override @@ -831,7 +831,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public void trim(K key, final int start, final int end) { + public void trim(K key, final long start, final long end) { execute(new ValueDeserializingRedisCallback(key) { @Override protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { @@ -943,7 +943,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public boolean isMember(K key, Object o) { + public Boolean isMember(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { @@ -968,7 +968,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public boolean remove(K key, Object o) { + public Boolean remove(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { @@ -980,11 +980,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public int size(K key) { + public Long size(K key) { final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.sCard(rawKey); } }, true); @@ -1034,7 +1034,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation private class DefaultZSetOperations implements ZSetOperations { @Override - public boolean add(final K key, final V value, final double score) { + public Boolean add(final K key, final V value, final double score) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); @@ -1065,7 +1065,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Set range(K key, final int start, final int end) { + public Set range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { @@ -1093,33 +1093,33 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer rank(K key, Object o) { + public Long rank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.zRank(rawKey, rawValue); } }, true); } @Override - public Integer reverseRank(K key, Object o) { + public Long reverseRank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.zRevRank(rawKey, rawValue); } }, true); } @Override - public boolean remove(K key, Object o) { + public Boolean remove(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); @@ -1132,7 +1132,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public void removeRange(K key, final int start, final int end) { + public void removeRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { @Override @@ -1156,7 +1156,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Set reverseRange(K key, final int start, final int end) { + public Set reverseRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { @@ -1183,12 +1183,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public int size(K key) { + public Long size(K key) { final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.zCard(rawKey); } }, true); @@ -1259,13 +1259,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer increment(K key, HK hashKey, final int delta) { + public Long increment(K key, HK hashKey, final long delta) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.hIncrBy(rawKey, rawHashKey, delta); } }, true); @@ -1287,12 +1287,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public Integer size(K key) { + public Long size(K key) { final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Integer doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { return connection.hLen(rawKey); } }, true); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SetOperations.java index 5f55f7e30..71346b082 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SetOperations.java @@ -41,12 +41,12 @@ public interface SetOperations { Boolean add(K key, V value); - boolean isMember(K key, Object o); + Boolean isMember(K key, Object o); Set members(K key); - boolean remove(K key, Object o); + Boolean remove(K key, Object o); - int size(K key); + Long size(K key); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java index 83eb2880c..5c26bfae1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java @@ -43,5 +43,5 @@ public interface ValueOperations { Collection multiGet(Set keys); - V increment(K key, int delta); + V increment(K key, long delta); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ZSetOperations.java index d4d7059c8..90afb22c5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ZSetOperations.java @@ -27,29 +27,29 @@ public interface ZSetOperations { void intersectAndStore(K key, K destKey, K... keys); - Set range(K key, int start, int end); + Set range(K key, long start, long end); Set rangeByScore(K key, double min, double max); - Set reverseRange(K key, int start, int end); + Set reverseRange(K key, long start, long end); - void removeRange(K key, int start, int end); + void removeRange(K key, long start, long end); void removeRangeByScore(K key, double min, double max); void unionAndStore(K key, K destKey, K... keys); - boolean add(K key, V value, double score); + Boolean add(K key, V value, double score); - Integer rank(K key, Object o); + Long rank(K key, Object o); - Integer reverseRank(K key, Object o); + Long reverseRank(K key, Object o); Double score(K key, Object o); - boolean remove(K key, Object o); + Boolean remove(K key, Object o); - int size(K key); + Long size(K key); RedisOperations getOperations(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisList.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisList.java index be73bc5e7..238435bf9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisList.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisList.java @@ -62,7 +62,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R } @Override - public List range(int start, int end) { + public List range(long start, long end) { return listOps.range(start, end); } @@ -83,7 +83,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R @Override public int size() { - return listOps.length(); + return listOps.size().intValue(); } @@ -100,8 +100,8 @@ public class DefaultRedisList extends AbstractRedisCollection implements R @Override public boolean remove(Object o) { - Integer result = listOps.remove(0, o); - return (result != null && result.intValue() > 0); + Long result = listOps.remove(0, o); + return (result != null && result.longValue() > 0); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java index 05939c438..eef36ac7c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java @@ -80,7 +80,7 @@ public class DefaultRedisMap implements RedisMap { } @Override - public Integer increment(K key, int delta) { + public Long increment(K key, long delta) { return hashOps.increment(key, delta); } @@ -161,7 +161,7 @@ public class DefaultRedisMap implements RedisMap { @Override public int size() { - return hashOps.length(); + return hashOps.size().intValue(); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisSet.java index af7d86741..8cdef359d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisSet.java @@ -125,7 +125,7 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re @Override public int size() { - return boundSetOps.size(); + return boundSetOps.size().intValue(); } private String[] extractKeys(RedisSet... sets) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisZSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisZSet.java index 476e7daaf..56a7316f1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisZSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisZSet.java @@ -96,12 +96,12 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R } @Override - public Set range(int start, int end) { + public Set range(long start, long end) { return boundZSetOps.range(start, end); } @Override - public Set reverseRange(int start, int end) { + public Set reverseRange(long start, long end) { return boundZSetOps.reverseRange(start, end); } @@ -111,7 +111,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R } @Override - public RedisZSet remove(int start, int end) { + public RedisZSet remove(long start, long end) { boundZSetOps.removeRange(start, end); return this; } @@ -160,7 +160,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R @Override public int size() { - return boundZSetOps.size(); + return boundZSetOps.size().intValue(); } @Override @@ -185,12 +185,12 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R } @Override - public Integer rank(Object o) { + public Long rank(Object o) { return boundZSetOps.rank(o); } @Override - public Integer reverseRank(Object o) { + public Long reverseRank(Object o) { return boundZSetOps.reverseRank(o); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisList.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisList.java index 7512550ae..1ec480930 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisList.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisList.java @@ -26,7 +26,7 @@ import java.util.Queue; */ public interface RedisList extends RedisStore, List, Queue { - List range(int start, int end); + List range(long start, long end); RedisList trim(int start, int end); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java index 83e1ca52e..a4ad7e0ef 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisMap.java @@ -25,5 +25,5 @@ import java.util.concurrent.ConcurrentMap; */ public interface RedisMap extends RedisStore, ConcurrentMap { - Integer increment(K key, int delta); + Long increment(K key, long delta); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisZSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisZSet.java index ea18abd5b..eaa4d84a4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisZSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/RedisZSet.java @@ -32,13 +32,13 @@ public interface RedisZSet extends RedisStore, Set { RedisZSet unionAndStore(String destKey, RedisZSet... sets); - Set range(int start, int end); + Set range(long start, long end); - Set reverseRange(int start, int end); + Set reverseRange(long start, long end); Set rangeByScore(double min, double max); - RedisZSet remove(int start, int end); + RedisZSet remove(long start, long end); RedisZSet removeByScore(double min, double max); @@ -78,7 +78,7 @@ public interface RedisZSet extends RedisStore, Set { * @param o object * @return rank of the given object */ - Integer rank(Object o); + Long rank(Object o); /** * Returns the rank (position) of the given element in the set, in descending order. @@ -87,7 +87,7 @@ public interface RedisZSet extends RedisStore, Set { * @param o object * @return reverse rank of the given object */ - Integer reverseRank(Object o); + Long reverseRank(Object o); /** * Returns the default score used by this set. diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index 3292d160c..c290db065 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -23,8 +23,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.data.keyvalue.redis.Person; -import org.springframework.data.keyvalue.redis.connection.RedisConnection; -import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; public abstract class AbstractConnectionIntegrationTests { @@ -46,9 +44,9 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testLPush() throws Exception { - Integer index = connection.lPush(listName.getBytes(), "bar".getBytes()); + Long index = connection.lPush(listName.getBytes(), "bar".getBytes()); if (index != null) { - assertEquals((Integer) (index + 1), connection.lPush(listName.getBytes(), "bar".getBytes())); + assertEquals((Long) (index + 1), connection.lPush(listName.getBytes(), "bar".getBytes())); } } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java index ca50514b0..d59934262 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisMapTests.java @@ -202,7 +202,7 @@ public abstract class AbstractRedisMapTests { V v1 = getValue(); map.put(k1, v1); - Integer value = map.increment(k1, 1); + Long value = map.increment(k1, 1); System.out.println("Value is " + value); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisZSetTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisZSetTest.java index b436c54c8..8bc86952d 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisZSetTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/util/AbstractRedisZSetTest.java @@ -136,9 +136,9 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t2, 4); zSet.add(t3, 5); - assertEquals(Integer.valueOf(0), zSet.rank(t1)); - assertEquals(Integer.valueOf(1), zSet.rank(t2)); - assertEquals(Integer.valueOf(2), zSet.rank(t3)); + assertEquals(Long.valueOf(0), zSet.rank(t1)); + assertEquals(Long.valueOf(1), zSet.rank(t2)); + assertEquals(Long.valueOf(2), zSet.rank(t3)); assertNull(zSet.rank(getT())); } @@ -152,9 +152,9 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t2, 4); zSet.add(t3, 5); - assertEquals(Integer.valueOf(0), zSet.reverseRank(t3)); - assertEquals(Integer.valueOf(1), zSet.reverseRank(t2)); - assertEquals(Integer.valueOf(2), zSet.reverseRank(t1)); + assertEquals(Long.valueOf(0), zSet.reverseRank(t3)); + assertEquals(Long.valueOf(1), zSet.reverseRank(t2)); + assertEquals(Long.valueOf(2), zSet.reverseRank(t1)); assertNull(zSet.rank(getT())); } diff --git a/spring-data-redis/template.mf b/spring-data-redis/template.mf index 3e484e2bf..2d82470a1 100644 --- a/spring-data-redis/template.mf +++ b/spring-data-redis/template.mf @@ -1,5 +1,5 @@ Bundle-SymbolicName: org.springframework.data.redis -Bundle-Name: Spring Datastore Redis Support +Bundle-Name: Spring Data Redis Support Bundle-Vendor: SpringSource Bundle-ManifestVersion: 2 Import-Package: @@ -22,4 +22,5 @@ Import-Template: org.springframework.transaction.support.*;version="[3.0.0, 4.0.0)", redis.clients.jedis.*;version="[1.0.0, 2.0.0)", redis.clients.util.*;version="[1.0.0, 2.0.0)", + org.apache.commons.pool.impl.*;version="[1.0.0, 3.0.0)" From 55600f170253e261a250d619e90b7217ac2e7c70 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 2 Dec 2010 14:05:11 +0200 Subject: [PATCH 12/12] + update jar plugin to fix ignored manifest on latest Maven installs --- pom.xml | 2 +- spring-data-keyvalue-parent/pom.xml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78ccfb3dd..de846da55 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.springframework.data spring-data-keyvalue-dist - Spring Datastore Key-Value Distribution + Spring Data Key-Value Distribution 1.0.0.BUILD-SNAPSHOT pom diff --git a/spring-data-keyvalue-parent/pom.xml b/spring-data-keyvalue-parent/pom.xml index 660068a1f..32c0d9b2a 100644 --- a/spring-data-keyvalue-parent/pom.xml +++ b/spring-data-keyvalue-parent/pom.xml @@ -382,6 +382,19 @@ junit:junit + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + +