+ fixed compilations problems
- removed DefaultRedisMap for now
This commit is contained in:
@@ -15,13 +15,10 @@
|
||||
*/
|
||||
package org.springframework.datastore.redis.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.datastore.redis.serializer.RedisSerializer;
|
||||
|
||||
/**
|
||||
* Utility class used mainly for type conversion by the default collection implementations.
|
||||
*
|
||||
@@ -29,15 +26,6 @@ import org.springframework.datastore.redis.serializer.RedisSerializer;
|
||||
*/
|
||||
abstract class CollectionUtils {
|
||||
|
||||
static <E> List<E> deserializeAsList(List<String> input, RedisSerializer serializer) {
|
||||
List<E> result = new ArrayList<E>(input.size());
|
||||
for (String string : input) {
|
||||
E item = serializer.deserialize(string);
|
||||
result.add(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> Collection<E> reverse(Collection<? extends E> c) {
|
||||
Object[] reverse = new Object[c.size()];
|
||||
|
||||
@@ -21,13 +21,14 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.datastore.redis.connection.RedisCommands;
|
||||
import org.springframework.datastore.redis.core.RedisOperations;
|
||||
|
||||
/**
|
||||
* Default {@link RedisMap} implementation.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class DefaultRedisMap implements RedisMap {
|
||||
public class DefaultRedisMap<K, V> implements RedisMap<K, V> {
|
||||
|
||||
private class DefaultRedisMapEntry implements Map.Entry<String, String> {
|
||||
|
||||
@@ -60,7 +61,9 @@ public class DefaultRedisMap implements RedisMap {
|
||||
}
|
||||
|
||||
protected final String redisKey;
|
||||
protected final RedisCommands commands;
|
||||
protected final RedisOperations<String, ?> operations;
|
||||
private final MapOperations<String, K, V> mapOps;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultRedisMap</code> instance.
|
||||
@@ -68,9 +71,15 @@ public class DefaultRedisMap implements RedisMap {
|
||||
* @param key
|
||||
* @param operations
|
||||
*/
|
||||
public DefaultRedisMap(String key, RedisCommands commands) {
|
||||
public DefaultRedisMap(String key, RedisOperations<K, V> operations) {
|
||||
this.redisKey = key;
|
||||
this.commands = commands;
|
||||
this.operations = operations;
|
||||
this.maps = operations.forMap(key);
|
||||
}
|
||||
|
||||
public DefaultRedisList(String key, RedisOperations<String, E> operations) {
|
||||
super(key, operations);
|
||||
listOps = operations.listOps();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,9 +22,9 @@ import java.util.Map;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface RedisMap extends RedisStore, Map<String, String> {
|
||||
public interface RedisMap<K, V> extends RedisStore<String>, Map<K, V> {
|
||||
|
||||
boolean putIfAbsent(String key, String value);
|
||||
|
||||
Integer increment(String key, int delta);
|
||||
boolean putIfAbsent(K key, V value);
|
||||
|
||||
Integer increment(K key, int delta);
|
||||
}
|
||||
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.datastore.redis.Person;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
|
||||
public abstract class AbstractConnectionIntegrationTests {
|
||||
|
||||
@@ -46,17 +44,16 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testLPush() throws Exception {
|
||||
Integer index = connection.lPush(listName, "bar");
|
||||
Integer index = connection.lPush(listName.getBytes(), "bar".getBytes());
|
||||
if (index != null) {
|
||||
assertEquals((Integer) (index + 1), connection.lPush(listName, "bar"));
|
||||
assertEquals((Integer) (index + 1), connection.lPush(listName.getBytes(), "bar".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() {
|
||||
connection.set("foo", "blah blah");
|
||||
String value = connection.get("foo");
|
||||
Assert.assertEquals("blah blah", value);
|
||||
connection.set("foo".getBytes(), "blah blah".getBytes());
|
||||
Assert.assertEquals("blah blah".getBytes(), connection.get("foo".getBytes()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -125,9 +125,9 @@ public class SimpleRedisSerializerTest {
|
||||
@Test
|
||||
public void testStringEncodedSerialization() {
|
||||
String value = UUID.randomUUID().toString();
|
||||
assertEquals(value, serializer.deserialize(serializer.serializeAsString(value)));
|
||||
assertEquals(value, serializer.deserialize(serializer.serializeAsString(value)));
|
||||
assertEquals(value, serializer.deserialize(serializer.serializeAsString(value)));
|
||||
assertEquals(value, serializer.deserialize(serializer.serialize(value)));
|
||||
assertEquals(value, serializer.deserialize(serializer.serialize(value)));
|
||||
assertEquals(value, serializer.deserialize(serializer.serialize(value)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,6 +135,6 @@ public class SimpleRedisSerializerTest {
|
||||
String value = UUID.randomUUID().toString();
|
||||
Person p1 = new Person(value, value, 1, new Address(value, 2));
|
||||
assertEquals(p1, serializer.deserialize(serializer.serialize(p1)));
|
||||
assertEquals(p1, serializer.deserialize(serializer.serializeAsString(p1)));
|
||||
assertEquals(p1, serializer.deserialize(serializer.serialize(p1)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user