鑒於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;
-
- /**
- * @author Andy
- */
- 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);
- }
- }
-
- /**
- * dbsize 資料庫key總數
- */
- 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);
- }
-
- /**
- * 阻塞IO後持久化資料然後關閉redis (shutdown)
- */
- private static String shutdown(Jedis jedis) {
- return jedis.shutdown();
- }
-
- /**
- * 將此redis設定為master主庫
- */
- private static String slaveofNoOne(Jedis jedis) {
- return jedis.slaveofNoOne();
- }
-
- /**
- * 將此redis根據host/port設定為slaveof從庫
- */
- private static String slaveof(Jedis jedis) {
- return jedis.slaveof(HOST, PORT);
- }
-
- /**
- * 查詢redis的info資訊
- */
- private static String info(Jedis jedis) {
- return jedis.info();
- }
-
- /**
- * select?
- */
- private static String select(Jedis jedis) {
- return jedis.select(1);
- }
-
- }
|
有一個 重設系統參數 的方法,測試了一下,沒用.所以就沒寫.
select方法,沒使用過,有使用過的朋友可以跟帖介紹一下~