Merge branch 'DATAREDIS-117' of github.com:porcelijn/spring-data-redis into porcelijn-DATAREDIS-117
Conflicts: src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java
This commit is contained in:
@@ -1048,14 +1048,14 @@ public class JedisConnection implements RedisConnection {
|
||||
public Long decrBy(byte[] key, long value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.decrBy(key, (int) value);
|
||||
transaction.decrBy(key, value);
|
||||
return null;
|
||||
}
|
||||
if (isPipelined()) {
|
||||
pipeline.decrBy(key, (int) value);
|
||||
pipeline.decrBy(key, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.decrBy(key, (int) value);
|
||||
return jedis.decrBy(key, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -1082,14 +1082,14 @@ public class JedisConnection implements RedisConnection {
|
||||
public Long incrBy(byte[] key, long value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.incrBy(key, (int) value);
|
||||
transaction.incrBy(key, value);
|
||||
return null;
|
||||
}
|
||||
if (isPipelined()) {
|
||||
pipeline.incrBy(key, (int) value);
|
||||
pipeline.incrBy(key, value);
|
||||
return null;
|
||||
}
|
||||
return jedis.incrBy(key, (int) value);
|
||||
return jedis.incrBy(key, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -2254,14 +2254,14 @@ public class JedisConnection implements RedisConnection {
|
||||
public Long hIncrBy(byte[] key, byte[] field, long delta) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.hincrBy(key, field, (int) delta);
|
||||
transaction.hincrBy(key, field, delta);
|
||||
return null;
|
||||
}
|
||||
if (isPipelined()) {
|
||||
pipeline.hincrBy(key, field, (int) delta);
|
||||
pipeline.hincrBy(key, field, delta);
|
||||
return null;
|
||||
}
|
||||
return jedis.hincrBy(key, field, (int) delta);
|
||||
return jedis.hincrBy(key, field, delta);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -2437,4 +2437,4 @@ public class JedisConnection implements RedisConnection {
|
||||
throw new RedisSubscribedConnectionException("Cannot execute command - connection is subscribed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
public void setUp() throws Exception {
|
||||
ConnectionFactoryTracker.add(template.getConnectionFactory());
|
||||
super.setUp();
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -161,4 +160,4 @@ public class RedisCacheTest extends AbstractNativeCacheTest<RedisTemplate> {
|
||||
assertNotNull(cache);
|
||||
assertTrue(redisCM.getCacheNames().contains(cacheName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
try {
|
||||
connection.decr((String) null);
|
||||
} catch (Exception ex) {
|
||||
// excepted
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -38,4 +40,30 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
|
||||
protected RedisConnectionFactory getConnectionFactory() {
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrDecrBy() {
|
||||
String key = "test.count";
|
||||
long largeNumber = 0x123456789L; // > 32bits
|
||||
connection.set(key.getBytes(), "0".getBytes());
|
||||
connection.incrBy(key.getBytes(), largeNumber);
|
||||
assertEquals(largeNumber, Long.valueOf(new String(connection.get(key.getBytes()))).longValue());
|
||||
connection.decrBy(key.getBytes(), largeNumber);
|
||||
assertEquals(0, Long.valueOf(new String(connection.get(key.getBytes()))).longValue());
|
||||
connection.decrBy(key.getBytes(), 2*largeNumber);
|
||||
assertEquals(-2*largeNumber, Long.valueOf(new String(connection.get(key.getBytes()))).longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashIncrDecrBy() {
|
||||
byte[] key = "test.hcount".getBytes();
|
||||
byte[] hkey = "hashkey".getBytes();
|
||||
|
||||
long largeNumber = 0x123456789L; // > 32bits
|
||||
connection.hSet(key, hkey, "0".getBytes());
|
||||
connection.hIncrBy(key, hkey, largeNumber);
|
||||
assertEquals(largeNumber, Long.valueOf(new String(connection.hGet(key, hkey))).longValue());
|
||||
connection.hIncrBy(key, hkey, -2*largeNumber);
|
||||
assertEquals(-largeNumber, Long.valueOf(new String(connection.hGet(key, hkey))).longValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user