diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java index 4a127011e..2df2b6bc5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java @@ -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 sort(byte[] key, SortParameters params); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisServerCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisServerCommands.java new file mode 100644 index 000000000..d1aa2cc1c --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisServerCommands.java @@ -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 getConfig(String pattern); + + void setConfig(String param, String value); +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 935217db3..dd45b9b94 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -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 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 { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java index 7df52469f..fb16f3f4a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java @@ -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; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index fa3da3b31..a20158e04 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -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 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 { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java index 53bb8b1c2..b0041e954 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java @@ -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 map) { + Properties info = new Properties(); + info.putAll(map); + return info; + } } \ No newline at end of file