DATAREDIS-197 - Expose bit-related ops via ValueOperations.

Polishing. Added -S switch to gradlew in makefile for better Stacktrace reporting.

Original pull request: #96.
This commit is contained in:
David Liu
2014-08-21 07:19:25 +08:00
committed by Thomas Darimont
parent ba1d22847d
commit 9ecad07587
4 changed files with 70 additions and 5 deletions

View File

@@ -95,5 +95,5 @@ stop: redis-stop sentinel-stop
test:
$(MAKE) start
sleep 2
$(PWD)/gradlew clean build -DrunLongTests=true
$(PWD)/gradlew clean build -DrunLongTests=true -S
$(MAKE) stop

View File

@@ -244,4 +244,29 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
}
}, true);
}
@Override
public Boolean setBit(K key, final long offset, final boolean value) {
final byte[] rawKey = rawKey(key);
return execute(new RedisCallback<Boolean>() {
public Boolean doInRedis(RedisConnection connection) {
return connection.setBit(rawKey, offset, value);
}
}, true);
}
@Override
public Boolean getBit(K key, final long offset) {
final byte[] rawKey = rawKey(key);
return execute(new RedisCallback<Boolean>() {
public Boolean doInRedis(RedisConnection connection) {
return connection.getBit(rawKey, offset);
}
}, true);
}
}

View File

@@ -66,4 +66,22 @@ public interface ValueOperations<K, V> {
Long size(K key);
RedisOperations<K, V> getOperations();
/**
* @since 1.5
* @param key
* @param offset
* @param value
* @return
*/
Boolean setBit(K key, long offset, boolean value);
/**
* @since 1.5
* @param key
* @param offset
* @return
*/
Boolean getBit(K key, long offset);
}

View File

@@ -15,10 +15,14 @@
*/
package org.springframework.data.redis.core;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.springframework.data.redis.SpinBarrier.waitFor;
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -45,6 +49,8 @@ import org.springframework.data.redis.connection.RedisConnection;
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author David Liu
* @author Thomas Darimont
*/
@RunWith(Parameterized.class)
public class DefaultValueOperationsTests<K, V> {
@@ -274,4 +280,20 @@ public class DefaultValueOperationsTests<K, V> {
assumeTrue(key1 instanceof byte[]);
assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key1));
}
/**
* @see DATAREDIS-197
*/
@Test
public void testSetAndGetBit() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
K key1 = keyFactory.instance();
int bitOffset = 65;
valueOps.setBit(key1, bitOffset, true);
assertEquals(true, valueOps.getBit(key1, bitOffset));
}
}