Skip to content

Commit

Permalink
DATAREDIS-197 - Expose bit-related ops via ValueOperations.
Browse files Browse the repository at this point in the history
Polishing. Added -S switch to gradlew in makefile for better Stacktrace reporting.

Original pull request: #96.
  • Loading branch information
liujiong1982 authored and Thomas Darimont committed Sep 30, 2014
1 parent ba1d228 commit 9ecad07
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,29 @@ public Long doInRedis(RedisConnection connection) {
}
}, 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +49,8 @@
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author David Liu
* @author Thomas Darimont
*/
@RunWith(Parameterized.class)
public class DefaultValueOperationsTests<K, V> {
Expand Down Expand Up @@ -274,4 +280,20 @@ public void testDeserializeKey() {
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));
}

}

0 comments on commit 9ecad07

Please sign in to comment.