ValueOps#increment properly handles negative vals

DATAREDIS-88
This commit is contained in:
Costin Leau
2012-05-23 18:38:23 +03:00
parent ff8184c264
commit 27d7e5dd0b
2 changed files with 11 additions and 6 deletions

View File

@@ -73,10 +73,6 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
return connection.decr(rawKey);
}
if (delta < 0) {
return connection.decrBy(rawKey, delta);
}
return connection.incrBy(rawKey, delta);
}
}, true);
@@ -109,8 +105,6 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
return deserializeString(rawReturn);
}
@SuppressWarnings("unchecked")
public List<V> multiGet(Collection<K> keys) {
if (keys.isEmpty()) {
return Collections.emptyList();

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
@@ -56,4 +57,14 @@ public class TemplateTest {
public void testKeys() throws Exception {
assertTrue(template.keys("*") != null);
}
@Test
public void testIncrement() throws Exception {
StringRedisTemplate sr = new StringRedisTemplate(template.getConnectionFactory());
String key = "test.template.inc";
ValueOperations<String, String> valueOps = sr.opsForValue();
valueOps.set(key, "10");
valueOps.increment(key, -10);
assertEquals(0, Integer.valueOf(valueOps.get(key)).intValue());
}
}