+ add move command

+ extract RedisKeyCommands and RedisConnectionCommands interfaces to map RedisConnection to the Redis docs
This commit is contained in:
Costin Leau
2011-03-17 19:40:29 +02:00
parent 2f7bd89c97
commit 5f2875fda6
8 changed files with 140 additions and 39 deletions

View File

@@ -308,6 +308,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.persist(key);
}
public Boolean move(byte[] key, int dbIndex) {
return delegate.move(key, dbIndex);
}
public String ping() {
return delegate.ping();
}
@@ -838,6 +842,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.persist(serialize(key));
}
@Override
public Boolean move(String key, int dbIndex) {
return delegate.move(serialize(key), dbIndex);
}
@Override
public void pSubscribe(MessageListener listener, String... patterns) {
delegate.pSubscribe(listener, serializeMulti(patterns));

View File

@@ -16,47 +16,13 @@
package org.springframework.data.keyvalue.redis.connection;
import java.util.List;
import java.util.Set;
/**
* Interface for the commands supported by Redis.
*
* @author Costin Leau
*/
public interface RedisCommands extends RedisTxCommands, RedisStringCommands, RedisListCommands, RedisSetCommands,
RedisZSetCommands, RedisHashCommands, RedisServerCommands, RedisPubSubCommands {
Boolean exists(byte[] key);
Long del(byte[]... keys);
DataType type(byte[] key);
Set<byte[]> keys(byte[] pattern);
byte[] randomKey();
void rename(byte[] oldName, byte[] newName);
Boolean renameNX(byte[] oldName, byte[] newName);
Boolean expire(byte[] key, long seconds);
Boolean expireAt(byte[] key, long unixTime);
Boolean persist(byte[] key);
Long ttl(byte[] key);
void select(int dbIndex);
byte[] echo(byte[] message);
String ping();
// sort commands
List<byte[]> sort(byte[] key, SortParameters params);
Long sort(byte[] key, SortParameters params, byte[] storeKey);
public interface RedisCommands extends RedisKeyCommands, RedisStringCommands, RedisListCommands, RedisSetCommands,
RedisZSetCommands, RedisHashCommands, RedisTxCommands, RedisPubSubCommands, RedisConnectionCommands,
RedisServerCommands {
}

View File

@@ -0,0 +1,28 @@
/*
* 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;
public interface RedisConnectionCommands {
public abstract void select(int dbIndex);
public abstract byte[] echo(byte[] message);
public abstract String ping();
}

View File

@@ -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;
import java.util.List;
import java.util.Set;
public interface RedisKeyCommands {
public abstract Boolean exists(byte[] key);
public abstract Long del(byte[]... keys);
public abstract DataType type(byte[] key);
public abstract Set<byte[]> keys(byte[] pattern);
public abstract byte[] randomKey();
public abstract void rename(byte[] oldName, byte[] newName);
public abstract Boolean renameNX(byte[] oldName, byte[] newName);
public abstract Boolean expire(byte[] key, long seconds);
public abstract Boolean expireAt(byte[] key, long unixTime);
public abstract Boolean persist(byte[] key);
public abstract Boolean move(byte[] key, int dbIndex);
public abstract Long ttl(byte[] key);
// sort commands
public abstract List<byte[]> sort(byte[] key, SortParameters params);
public abstract Long sort(byte[] key, SortParameters params, byte[] storeKey);
}

View File

@@ -60,6 +60,8 @@ public interface StringRedisConnection extends RedisConnection {
Boolean persist(String key);
Boolean move(String key, int dbIndex);
Long ttl(String key);
String echo(String message);

View File

@@ -625,6 +625,23 @@ public class JedisConnection implements RedisConnection {
}
}
@Override
public Boolean move(byte[] key, int dbIndex) {
try {
if (isQueueing()) {
client.move(key, dbIndex);
return null;
}
if (isPipelined()) {
client.move(key, dbIndex);
return null;
}
return (jedis.move(key, dbIndex) == 1);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
@Override
public byte[] randomKey() {
try {

View File

@@ -321,6 +321,16 @@ public class JredisConnection implements RedisConnection {
throw new UnsupportedOperationException();
}
@Override
public Boolean move(byte[] key, int dbIndex) {
try {
return jredis.move(JredisUtils.decode(key), dbIndex);
} catch (Exception ex) {
throw convertJredisAccessException(ex);
}
}
@Override
public byte[] randomKey() {
try {

View File

@@ -33,8 +33,8 @@ import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException;
import org.springframework.data.keyvalue.redis.connection.DataType;
import org.springframework.data.keyvalue.redis.connection.MessageListener;
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
import org.springframework.data.keyvalue.redis.connection.SortParameters;
import org.springframework.data.keyvalue.redis.connection.RedisSubscribedConnectionException;
import org.springframework.data.keyvalue.redis.connection.SortParameters;
import org.springframework.data.keyvalue.redis.connection.Subscription;
/**
@@ -495,6 +495,21 @@ public class RjcConnection implements RedisConnection {
}
}
@Override
public Boolean move(byte[] key, int dbIndex) {
String stringKey = RjcUtils.decode(key);
try {
if (isPipelined()) {
pipeline.move(stringKey, dbIndex);
return null;
}
return session.move(stringKey, dbIndex);
} catch (Exception ex) {
throw convertRjcAccessException(ex);
}
}
@Override
public byte[] randomKey() {
try {
@@ -2037,7 +2052,7 @@ public class RjcConnection implements RedisConnection {
subscription = new RjcSubscription(listener, subscriber, pubSubMonitor);
subscription.subscribe(channels);
synchronized (pubSubMonitor) {
pubSubMonitor.wait();
}