Redis 基于Java的参数动态配置操作
鉴于redis的list,hash,set,string等类型的操作,很多人都已经熟练使用,就简单介绍一下动态参数修改,主从切换,持久化设置,系统信息监控.
Redis 中文文档里面, 有控制台操作的详细的说明,http://redis.readthedocs.org/en/latest/index.html
下面的内容是java的api应用.
- package redis;
-
- import java.util.List;
- import java.util.UUID;
-
- import redis.clients.jedis.Jedis;
- import redis.clients.jedis.ShardedJedis;
- import redis.clients.util.ShardInfo;
-
-
-
-
- public class RedisMasterSlaveTest {
-
- private static final String HOST = "";
- private static final int PORT = 0;
-
-
-
-
- private static void setData(Jedis jedis) {
-
- for (int i = 0; i < 100; i++) {
- final String a = UUID.randomUUID().toString();
- jedis.set(a, a);
- }
- }
-
-
-
-
- private static long getDBSize(Jedis jedis) {
- return jedis.dbSize();
- }
-
-
-
-
- private static List<String> getSaveConfig(Jedis jedis) {
- return jedis.configGet("save");
- }
-
-
-
-
- private static String setSaveConfig(Jedis jedis) {
- String celue_1 = "800 1";
- String celue_2 = "400 2";
- return jedis.configSet("save", celue_1 + " " + celue_2);
- }
-
-
-
-
- private static String shutdown(Jedis jedis) {
- return jedis.shutdown();
- }
-
-
-
-
- private static String slaveofNoOne(Jedis jedis) {
- return jedis.slaveofNoOne();
- }
-
-
-
-
- private static String slaveof(Jedis jedis) {
- return jedis.slaveof(HOST, PORT);
- }
-
-
-
-
- private static String info(Jedis jedis) {
- return jedis.info();
- }
-
-
-
-
- private static String select(Jedis jedis) {
- return jedis.select(1);
- }
-
- }
|
有一个 重置系统参数 的方法,测试了一下,没用.所以就没写.
select方法,没使用过,有使用过的朋友可以跟帖介绍一下~
更多关于Redis的详细信息,或者下载地址请点这里
评论暂时关闭