DATAKV-46
+ first round of bug fixes for SJC + added integration tests + update OSGi template + update get/set method signatures in the process
This commit is contained in:
@@ -396,8 +396,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
return delegate.setNX(key, value);
|
||||
}
|
||||
|
||||
public void setRange(byte[] key, long start, byte[] value) {
|
||||
delegate.setRange(key, start, value);
|
||||
public void setRange(byte[] key, byte[] value, long start) {
|
||||
delegate.setRange(key, value, start);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
@@ -683,7 +683,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRange(String key, int start, int end) {
|
||||
public String getRange(String key, long start, long end) {
|
||||
return deserialize(delegate.getRange(serialize(key), start, end));
|
||||
}
|
||||
|
||||
@@ -919,8 +919,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRange(String key, int start, int end) {
|
||||
delegate.setRange(serialize(key), start, end);
|
||||
public void setRange(String key, long start, String value) {
|
||||
delegate.setRange(serialize(key), serialize(value), start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,7 +54,7 @@ public interface RedisStringCommands {
|
||||
|
||||
byte[] getRange(byte[] key, long begin, long end);
|
||||
|
||||
void setRange(byte[] key, long offset, byte[] value);
|
||||
void setRange(byte[] key, byte[] value, long offset);
|
||||
|
||||
Boolean getBit(byte[] key, long offset);
|
||||
|
||||
|
||||
@@ -95,9 +95,9 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
|
||||
Long append(String key, String value);
|
||||
|
||||
String getRange(String key, int start, int end);
|
||||
String getRange(String key, long start, long end);
|
||||
|
||||
void setRange(String key, int start, int end);
|
||||
void setRange(String key, long offset, String value);
|
||||
|
||||
Boolean getBit(String key, long offset);
|
||||
|
||||
|
||||
@@ -1033,7 +1033,7 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRange(byte[] key, long start, byte[] value) {
|
||||
public void setRange(byte[] key, byte[] value, long start) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -518,7 +518,7 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRange(byte[] key, long start, byte[] value) {
|
||||
public void setRange(byte[] key, byte[] value, long start) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class RjcConnection implements RedisConnection {
|
||||
|
||||
public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) {
|
||||
SingleDataSource connectionDataSource = new SingleDataSource(connection);
|
||||
session = new SessionFactoryImpl().create();
|
||||
session = new SessionFactoryImpl(connectionDataSource).create();
|
||||
client = new Client(connection);
|
||||
subscriber = new RedisNodeSubscriber(connectionDataSource);
|
||||
|
||||
@@ -638,7 +638,7 @@ public class RjcConnection implements RedisConnection {
|
||||
@Override
|
||||
public void set(byte[] key, byte[] value) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(value);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
@@ -655,7 +655,7 @@ public class RjcConnection implements RedisConnection {
|
||||
@Override
|
||||
public byte[] getSet(byte[] key, byte[] value) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(value);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
@@ -671,7 +671,7 @@ public class RjcConnection implements RedisConnection {
|
||||
@Override
|
||||
public Long append(byte[] key, byte[] value) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(value);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
@@ -870,7 +870,7 @@ public class RjcConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRange(byte[] key, long offset, byte[] value) {
|
||||
public void setRange(byte[] key, byte[] value, long offset) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String stringValue = RjcUtils.decode(value);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class DecodeUtils {
|
||||
}
|
||||
|
||||
public static byte[] encode(String string) {
|
||||
return Base64.decode(string);
|
||||
return (string == null ? null : Base64.decode(string));
|
||||
}
|
||||
|
||||
public static Map<byte[], byte[]> encodeMap(Map<String, byte[]> map) {
|
||||
@@ -66,7 +66,7 @@ public abstract class DecodeUtils {
|
||||
Set<byte[]> set = new LinkedHashSet<byte[]>(keys.size());
|
||||
|
||||
for (String string : keys) {
|
||||
set.add(Base64.decode(string));
|
||||
set.add(encode(string));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public abstract class DecodeUtils {
|
||||
List<byte[]> set = new ArrayList<byte[]>(keys.size());
|
||||
|
||||
for (String string : keys) {
|
||||
set.add(Base64.decode(string));
|
||||
set.add(encode(string));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -28,21 +28,21 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
|
||||
|
||||
void set(V value);
|
||||
|
||||
void set(V value, long offset);
|
||||
|
||||
void set(V value, long timeout, TimeUnit unit);
|
||||
|
||||
Boolean setIfAbsent(V value);
|
||||
|
||||
V get();
|
||||
|
||||
String get(long start, long end);
|
||||
|
||||
V getAndSet(V value);
|
||||
|
||||
Long increment(long delta);
|
||||
|
||||
Integer append(String value);
|
||||
|
||||
String get(int start, int end);
|
||||
|
||||
void set(int start, int end);
|
||||
|
||||
Long size();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class DefaultBoundValueOperations<K, V> extends DefaultBoundKeyOperations<K> imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(int start, int end) {
|
||||
public String get(long start, long end) {
|
||||
return ops.get(getKey(), start, end);
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ class DefaultBoundValueOperations<K, V> extends DefaultBoundKeyOperations<K> imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int start, int end) {
|
||||
ops.set(getKey(), start, end);
|
||||
public void set(V value, long offset) {
|
||||
ops.set(getKey(), value, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -96,7 +96,7 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(K key, final int start, final int end) {
|
||||
public String get(K key, final long start, final long end) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
byte[] rawReturn = execute(new RedisCallback<byte[]>() {
|
||||
@@ -217,13 +217,14 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
|
||||
|
||||
|
||||
@Override
|
||||
public void set(K key, final int start, final int end) {
|
||||
public void set(K key, final V value, final long offset) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawValue = rawValue(value);
|
||||
|
||||
execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) {
|
||||
connection.setRange(rawKey, start, end);
|
||||
connection.setRange(rawKey, rawValue, offset);
|
||||
return null;
|
||||
}
|
||||
}, true);
|
||||
|
||||
@@ -377,7 +377,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
* Sets the string value serializer to be used by this template (when the arguments or return types
|
||||
* are always strings). Defaults to {@link StringRedisSerializer}.
|
||||
*
|
||||
* @see ValueOperations#get(Object, int, int)
|
||||
* @see ValueOperations#get(Object, long, long)
|
||||
* @param stringSerializer The stringValueSerializer to set.
|
||||
*/
|
||||
public void setStringSerializer(RedisSerializer<String> stringSerializer) {
|
||||
|
||||
@@ -47,9 +47,9 @@ public interface ValueOperations<K, V> {
|
||||
|
||||
Integer append(K key, String value);
|
||||
|
||||
String get(K key, int start, int end);
|
||||
String get(K key, long start, long end);
|
||||
|
||||
void set(K key, int start, int end);
|
||||
void set(K key, V value, long offset);
|
||||
|
||||
Long size(K key);
|
||||
|
||||
|
||||
@@ -69,16 +69,19 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testLPush() throws Exception {
|
||||
Long index = connection.lPush(listName.getBytes(), "bar".getBytes());
|
||||
byte[] val = "bar".getBytes();
|
||||
Long index = connection.lPush(listName.getBytes(), val);
|
||||
if (index != null) {
|
||||
assertEquals((Long) (index + 1), connection.lPush(listName.getBytes(), "bar".getBytes()));
|
||||
assertEquals((Long) (index + 1), connection.lPush(listName.getBytes(), val));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGet() {
|
||||
connection.set("foo".getBytes(), "blahblah".getBytes());
|
||||
assertEquals("blahblah", new String(connection.get("foo".getBytes())));
|
||||
String key = "foo";
|
||||
String value = "blabla";
|
||||
connection.set(key.getBytes(), value.getBytes());
|
||||
assertEquals(value, new String(connection.get(key.getBytes())));
|
||||
}
|
||||
|
||||
private boolean isJredis() {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.connection.rjc;
|
||||
|
||||
import org.idevlab.rjc.Session;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.keyvalue.redis.SettingsUtils;
|
||||
import org.springframework.data.keyvalue.redis.connection.AbstractConnectionIntegrationTests;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class RjcConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||
|
||||
RjcConnectionFactory factory;
|
||||
|
||||
public RjcConnectionIntegrationTests() {
|
||||
factory = new RjcConnectionFactory();
|
||||
factory.setPort(SettingsUtils.getPort());
|
||||
factory.setHostName(SettingsUtils.getHost());
|
||||
|
||||
factory.setUsePool(true);
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RedisConnectionFactory getConnectionFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRaw() throws Exception {
|
||||
Session jr = (Session) factory.getConnection().getNativeConnection();
|
||||
|
||||
System.out.println(jr.dbSize());
|
||||
System.out.println(jr.exists("foobar"));
|
||||
jr.set("foobar", "barfoo");
|
||||
System.out.println(jr.get("foobar"));
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ Import-Template:
|
||||
org.jredis.ri.alphazero.*;version="[1.0.0, 2.0.0)",
|
||||
redis.clients.jedis.*;version=${jedis.range},
|
||||
redis.clients.util.*;version=${jedis.range},
|
||||
org.idevlab.rjc.*;version=${rjc.range},
|
||||
org.apache.commons.pool.impl.*;version="[1.0.0, 3.0.0)",
|
||||
org.codehaus.jackson.*;version=${jackson.range},
|
||||
org.apache.commons.beanutils.*;version="[1.8.0, 2.0.0)"
|
||||
|
||||
org.apache.commons.beanutils.*;version=1.8.5
|
||||
Reference in New Issue
Block a user