Dynamic configuration of Redis Parameters Based on Java

Source: Internet
Author: User

In view of redis list, hash, set, string and other types of operations, many people are familiar with the use of, a brief introduction to dynamic parameter modification, master-slave switchover, persistent settings, system information monitoring.

Redis Chinese document, there is a detailed description of the console operation, http://redis.readthedocs.org/en/latest/index.html

The following content is the java api application.

 
  1. PackageRedis;
  2. ImportJava. util. List;
  3. ImportJava. util. UUID;
  4. ImportRedis. clients. jedis. Jedis;
  5. ImportRedis. clients. jedis. ShardedJedis;
  6. ImportRedis. clients. util. ShardInfo;
  7. /** 
  8. * @ Author Andy 
  9. */
  10. Public ClassRedisMasterSlaveTest {
  11. Private Static FinalString HOST ="";
  12. Private Static Final IntPORT =0;
  13. /** 
  14. * Add Test Data 
  15. */
  16. Private Static VoidSetData (Jedis jedis ){
  17. For(IntI =0; I <100; I ++ ){
  18. FinalString a = UUID. randomUUID (). toString ();
  19. Jedis. set (a, );
  20. }
  21. }
  22. /** 
  23. * Dbsize total number of database keys 
  24. */
  25. Private Static LongGetDBSize (Jedis jedis ){
  26. ReturnJedis. dbSize ();
  27. }
  28. /** 
  29. * Query persistence policies 
  30. */
  31. Private StaticList <String> getSaveConfig (Jedis jedis ){
  32. ReturnJedis. configGet ("Save");
  33. }
  34. /** 
  35. * Set persistence policies 
  36. */
  37. Private StaticString setSaveConfig (Jedis jedis ){
  38. String celue_1 =800 1";
  39. String celue_2 =400 2";
  40. ReturnJedis. configSet ("Save", Celue_1 +""+ Celue_2 );
  41. }
  42. /** 
  43. * Persistence of data after IO blocking and shutdown redis) 
  44. */
  45. Private StaticString shutdown (Jedis jedis ){
  46. ReturnJedis. shutdown ();
  47. }
  48. /** 
  49. * Set redis as the master database 
  50. */
  51. Private StaticString slaveofNoOne (Jedis jedis ){
  52. ReturnJedis. slaveofNoOne ();
  53. }
  54. /** 
  55. * Set this redis instance to slaveof slave Database Based on host/port. 
  56. */
  57. Private StaticString slaveof (Jedis jedis ){
  58. ReturnJedis. slaveof (HOST, PORT );
  59. }
  60. /** 
  61. * Query the info information of redis. 
  62. */
  63. Private StaticString info (Jedis jedis ){
  64. ReturnJedis.info ();
  65. }
  66. /** 
  67. * Select? 
  68. */
  69. Private StaticString select (Jedis jedis ){
  70. ReturnJedis. select (1);
  71. }
  72. }

There is a way to reset the system parameters. After testing, it is useless, so it is not written.

The select method has not been used. If you have used it, you can follow the instructions to introduce it ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.