+ add support for most Redis server commands
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface RedisCommands extends RedisTxCommands, RedisStringCommands, RedisListCommands, RedisSetCommands,
|
||||
RedisZSetCommands, RedisHashCommands {
|
||||
RedisZSetCommands, RedisHashCommands, RedisServerCommands {
|
||||
|
||||
Boolean exists(byte[] key);
|
||||
|
||||
@@ -41,8 +41,6 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red
|
||||
|
||||
Boolean renameNX(byte[] oldName, byte[] newName);
|
||||
|
||||
Long dbSize();
|
||||
|
||||
Boolean expire(byte[] key, long seconds);
|
||||
|
||||
Boolean expireAt(byte[] key, long unixTime);
|
||||
@@ -53,7 +51,9 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red
|
||||
|
||||
void select(int dbIndex);
|
||||
|
||||
void flushDb();
|
||||
byte[] echo(byte[] message);
|
||||
|
||||
String ping();
|
||||
|
||||
// sort commands
|
||||
List<byte[]> sort(byte[] key, SortParameters params);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.Properties;
|
||||
|
||||
/**
|
||||
* Server-specific commands supported by Redis.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface RedisServerCommands {
|
||||
|
||||
void bgWriteAof();
|
||||
|
||||
void bgSave();
|
||||
|
||||
Long lastSave();
|
||||
|
||||
Long dbSize();
|
||||
|
||||
void flushDb();
|
||||
|
||||
void flushAll();
|
||||
|
||||
Properties info();
|
||||
|
||||
void shutdown();
|
||||
|
||||
List<String> getConfig(String pattern);
|
||||
|
||||
void setConfig(String param, String value);
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -177,6 +178,126 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushAll() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.flushAll();
|
||||
}
|
||||
jedis.flushAll();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bgSave() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
jedis.bgsave();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bgWriteAof() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
jedis.bgrewriteaof();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getConfig(String param) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.configGet(param);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties info() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return JedisUtils.info(jedis.info());
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lastSave() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.lastsave();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfig(String param, String value) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
jedis.configSet(param, value);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
jedis.shutdown();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] echo(byte[] message) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.echo(message);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ping() {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.ping();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long del(byte[]... keys) {
|
||||
try {
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.springframework.data.keyvalue.redis.connection.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@@ -177,4 +179,14 @@ public abstract class JedisUtils {
|
||||
Assert.notNull("list positions are mandatory");
|
||||
return (POSITION.AFTER.equals(where) ? LIST_POSITION.AFTER : LIST_POSITION.BEFORE);
|
||||
}
|
||||
|
||||
static Properties info(String string) {
|
||||
Properties info = new Properties();
|
||||
try {
|
||||
info.load(new StringReader(string));
|
||||
} catch (Exception ex) {
|
||||
throw new UncategorizedRedisException("Cannot read Redis info", ex);
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jredis.JRedis;
|
||||
@@ -112,6 +113,15 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
@Override
|
||||
public void flushDb() {
|
||||
try {
|
||||
jredis.flushdb();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushAll() {
|
||||
try {
|
||||
jredis.flushall();
|
||||
} catch (RedisException ex) {
|
||||
@@ -119,6 +129,75 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] echo(byte[] message) {
|
||||
try {
|
||||
return jredis.echo(message);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ping() {
|
||||
try {
|
||||
jredis.ping();
|
||||
return "PONG";
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bgSave() {
|
||||
try {
|
||||
jredis.bgsave();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bgWriteAof() {
|
||||
try {
|
||||
jredis.bgrewriteaof();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getConfig(String pattern) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties info() {
|
||||
try {
|
||||
return JredisUtils.info(jredis.info());
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lastSave() {
|
||||
try {
|
||||
return jredis.lastsave();
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfig(String param, String value) {
|
||||
throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long del(byte[]... keys) {
|
||||
try {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jredis.RedisException;
|
||||
import org.jredis.RedisType;
|
||||
@@ -141,4 +142,10 @@ public abstract class JredisUtils {
|
||||
|
||||
return jredisSort;
|
||||
}
|
||||
|
||||
static Properties info(Map<String, String> map) {
|
||||
Properties info = new Properties();
|
||||
info.putAll(map);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user