Redis 基於Java的參數動態配置操作

來源:互聯網
上載者:User

鑒於redis的list,hash,set,string等類型的操作,很多人都已經熟練使用,就簡單介紹一下動態參數修改,主從切換,持久化設定,系統資訊監控.

Redis 中文文檔裡面, 有控制台操作的詳細的說明,http://redis.readthedocs.org/en/latest/index.html

下面的內容是java的api應用.

 
  1. package redis;  
  2.   
  3. import java.util.List;  
  4. import java.util.UUID;  
  5.   
  6. import redis.clients.jedis.Jedis;  
  7. import redis.clients.jedis.ShardedJedis;  
  8. import redis.clients.util.ShardInfo;  
  9.   
  10. /** 
  11.  * @author Andy 
  12.  */  
  13. public class RedisMasterSlaveTest {  
  14.   
  15.     private static final String HOST = "";  
  16.     private static final int PORT = 0;  
  17.   
  18.     /** 
  19.      * 添加測試資料 
  20.      */  
  21.     private static void setData(Jedis jedis) {  
  22.   
  23.         for (int i = 0; i < 100; i++) {  
  24.             final String a = UUID.randomUUID().toString();  
  25.             jedis.set(a, a);  
  26.         }  
  27.     }  
  28.   
  29.     /** 
  30.      * dbsize 資料庫key總數 
  31.      */  
  32.     private static long getDBSize(Jedis jedis) {  
  33.         return jedis.dbSize();  
  34.     }  
  35.   
  36.     /** 
  37.      * 查詢持久化策略 
  38.      */  
  39.     private static List<String> getSaveConfig(Jedis jedis) {  
  40.         return jedis.configGet("save");  
  41.     }  
  42.   
  43.     /** 
  44.      * 設定持久化策略 
  45.      */  
  46.     private static String setSaveConfig(Jedis jedis) {  
  47.         String celue_1 = "800 1";  
  48.         String celue_2 = "400 2";  
  49.         return jedis.configSet("save", celue_1 + " " + celue_2);  
  50.     }  
  51.   
  52.     /** 
  53.      * 阻塞IO後持久化資料然後關閉redis (shutdown) 
  54.      */  
  55.     private static String shutdown(Jedis jedis) {  
  56.         return jedis.shutdown();  
  57.     }  
  58.   
  59.     /** 
  60.      * 將此redis設定為master主庫 
  61.      */  
  62.     private static String slaveofNoOne(Jedis jedis) {  
  63.         return jedis.slaveofNoOne();  
  64.     }  
  65.   
  66.     /** 
  67.      * 將此redis根據host/port設定為slaveof從庫 
  68.      */  
  69.     private static String slaveof(Jedis jedis) {  
  70.         return jedis.slaveof(HOST, PORT);  
  71.     }  
  72.   
  73.     /** 
  74.      * 查詢redis的info資訊 
  75.      */  
  76.     private static String info(Jedis jedis) {  
  77.         return jedis.info();  
  78.     }  
  79.   
  80.     /** 
  81.      * select? 
  82.      */  
  83.     private static String select(Jedis jedis) {  
  84.         return jedis.select(1);  
  85.     }  
  86.   
  87. }  

有一個  重設系統參數 的方法,測試了一下,沒用.所以就沒寫.

select方法,沒使用過,有使用過的朋友可以跟帖介紹一下~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.