Redis 是完全开源免费的,遵守BSD协议,先进的key - value持久化产品。它通常被称为数据结构服务器,因为值(value)可以是 字符串(String)哈希(Map),列表(list)集合(sets) 和 有序集合(sorted sets)等类型。下面是使用spring-data-redis分别针对key和value的操作。

1.Key(键)

  1. public class KeysTest extends RedisCommon {
  2. private static StringRedisTemplate template;
  3. private static String key = "key1";
  4.  
  5. public static void main(String[] args) {
  6. log.info("-----------Starting Redis keys testing-----------");
  7. ApplicationContext ctx = SpringApplication.run(KeysTest.class, args);
  8. template = ctx.getBean(StringRedisTemplate.class);
  9. KeysTest keysTest = ctx.getBean(KeysTest.class);
  10. keysTest.initValue();
  11.  
  12. log.info("KeysTest @##@ randomKey: " + template.randomKey());
  13.  
  14. keysTest.expireKey(key, 2);
  15. // keysTest.persistKey(key, 2);
  16.  
  17. String newkey = "newKey";
  18. // template.rename(key, newkey);
  19. template.renameIfAbsent(key, newkey);
  20.  
  21. Set<String> keys = template.keys("*");
  22. log.info("KeysTest @##@ keys:" + keys);
  23. for (String key : keys) {
  24. log.info("KeysTest @##@ " + key + " expire:"
  25. + template.getExpire(key));
  26. // template.getExpire(key, TimeUnit.SECONDS);
  27. }
  28.  
  29. int dbIndex = 1;// ref:http://redisdoc.com/key/move.html
  30. log.info("KeysTest @##@ move " + key + " to db" + dbIndex + ": "
  31. + template.move(key, 1));
  32.  
  33. // template.delete(key);
  34. template.delete(keys);
  35. log.info("KeysTest @##@ delete keys: " + keys);
  36.  
  37. // template.exec();
  38. // template.multi();
  39. // template.discard();
  40.  
  41. // template.slaveOf(host, port);
  42. // template.slaveOfNoOne();
  43.  
  44. // template.watch(key);
  45. // template.watch(keys);
  46. // template.unwatch();
  47. log.info("-----------End Redis keys testing-----------");
  48. }
  49.  
  50. public void initValue() {
  51. String value = "hello,redis";
  52. template.opsForValue().set(key, value);
  53. Set<String> keys = new HashSet<String>() {
  54. private static final long serialVersionUID = -4402948387930279259L;
  55. {
  56. this.add("key2");
  57. this.add("key3");
  58. this.add("key4");
  59. }
  60. };
  61. try {
  62. byte[] bytes = template.dump(key);
  63. log.info("KeysTest # key dump:" + new String(bytes));
  64. for (String k : keys) {
  65. template.restore(k, bytes, 0, TimeUnit.SECONDS);
  66. }
  67. } catch (Exception e) {
  68. e.printStackTrace();
  69. }
  70. }
  71.  
  72. public boolean expireKey(String key, long expiretime) {
  73. log.info("KeysTest @##@ has " + key + " : " + template.hasKey(key));
  74. log.info("KeysTest @##@ expire " + key + " for " + expiretime
  75. + " seconds : "
  76. + template.expire(key, expiretime, TimeUnit.SECONDS));
  77. // template.expireAt(key, new Date());
  78. try {
  79. Thread.sleep((expiretime + 1) * 1000);
  80. } catch (InterruptedException e) {
  81. e.printStackTrace();
  82. }
  83. boolean result = template.hasKey(key);
  84. log.info("KeysTest @##@ has " + key + " : " + result);
  85. return result;
  86. }
  87.  
  88. public boolean persistKey(String key, long expiretime) {
  89. log.info("KeysTest @##@ has " + key + " : " + template.hasKey(key));
  90. log.info("KeysTest @##@ expire " + key + " for " + expiretime
  91. + " seconds : "
  92. + template.expire(key, expiretime, TimeUnit.SECONDS));
  93. log.info("KeysTest @##@ persist " + key + " : " + template.persist(key));
  94. try {
  95. Thread.sleep((expiretime + 1) * 1000);
  96. } catch (InterruptedException e) {
  97. e.printStackTrace();
  98. }
  99. return template.hasKey(key);
  100. }
  101.  
  102. }

2.String(字符串)

  1. public class StringsTest extends RedisCommon {
  2. private static StringRedisTemplate template;
  3. private static String key = "strKey";
  4.  
  5. public static void main(String[] args) throws InterruptedException {
  6. log.info("-----------Starting Redis Strings testing-----------");
  7. ApplicationContext ctx = SpringApplication.run(StringsTest.class, args);
  8. template = ctx.getBean(StringRedisTemplate.class);
  9. StringsTest stringsTest = ctx.getBean(StringsTest.class);
  10.  
  11. String value = "hello, redis";
  12. template.opsForValue().set(key, value);
  13. log.info("StringsTest @##@ " + key + "'s value: " + template.opsForValue().get(key));
  14. log.info("StringsTest @##@ " + key + "'s size: " + template.opsForValue().size(key));
  15.  
  16. stringsTest.getRange(key, 0, 5);
  17.  
  18. template.opsForValue().getAndSet(key, "hello, redis world");
  19. log.info("StringsTest @##@ " + key + "'s value after getAndSet: " + template.opsForValue().get(key));
  20.  
  21. stringsTest.multiOperation();
  22.  
  23. stringsTest.incrementDouble();
  24.  
  25. stringsTest.incrementLong();
  26. }
  27.  
  28. public void getRange(String key, int start, int end){
  29. log.info("StringsTest @##@ " + key + "'s value: " + template.opsForValue().get(key));
  30. log.info("StringsTest @##@ " + key + " range from "+start +" to " + end +" value is: " + template.opsForValue().get(key, start, end));
  31. }
  32.  
  33. public void multiOperation(){
  34. Map<String, String> m = new HashMap<>();
  35. Set<String> keys = new HashSet<>();
  36. for(int i=0;i< 4;i++){
  37. m.put("key" + i, "value" + i);
  38. keys.add("key" + i);
  39. }
  40. template.opsForValue().multiSet(m);
  41. log.info("StringsTest @##@ multiSet : done.");
  42. log.info("StringsTest @##@ multiGet : " + template.opsForValue().multiGet(keys));
  43. }
  44.  
  45. public void incrementDouble() {
  46. String hashKey = UUID.randomUUID().toString();
  47. Double value1 = template.opsForValue().increment(hashKey, 30.5d);
  48. log.info(hashKey + " has value :" + value1);
  49. double d = 30.2d;
  50. Double value2 = template.opsForValue().increment(hashKey, d);
  51. log.info(hashKey + " has value: " + value2 + ", after increment " + d);
  52. }
  53.  
  54. public void incrementLong() {
  55. String hashKey = UUID.randomUUID().toString();
  56. long value1 = template.opsForValue().increment(hashKey, 30l);
  57. log.info(hashKey + " has value :" + value1);
  58. long l = 25l;
  59. long value2 = template.opsForValue().increment(hashKey, l);
  60. log.info(hashKey + " has value: " + value2 + ", after increment " + l);
  61. }
  62. }

3.Hash(哈希表)

  1. public class HashTest extends RedisCommon {
  2. private static RedisTemplate<String, Map<String, UserInfo>> userTemplate;
  3. private static RedisTemplate<String, Map<String, Double>> doubleTemplate;
  4. private static RedisTemplate<String, Map<String, Long>> longTemplate;
  5. private static String key = "UserInfo";
  6.  
  7. public static void main(String[] args) throws InterruptedException {
  8. log.info("-----------Starting Redis hash testing-----------");
  9. ApplicationContext ctx = SpringApplication.run(HashTest.class, args);
  10. RedisConnectionFactory connectionFactory = ctx
  11. .getBean(RedisConnectionFactory.class);
  12. userTemplate = new RedisTemplate<>();
  13. userTemplate.setConnectionFactory(connectionFactory);
  14. userTemplate.setKeySerializer(userTemplate.getStringSerializer());
  15. userTemplate.setHashKeySerializer(userTemplate.getStringSerializer());
  16. userTemplate
  17. .setHashValueSerializer(new JacksonJsonRedisSerializer<UserInfo>(
  18. UserInfo.class));
  19. userTemplate.afterPropertiesSet();
  20.  
  21. doubleTemplate = new RedisTemplate<>();
  22. doubleTemplate.setConnectionFactory(connectionFactory);
  23. doubleTemplate.setKeySerializer(doubleTemplate.getStringSerializer());
  24. doubleTemplate.setHashKeySerializer(doubleTemplate.getStringSerializer());
  25. doubleTemplate.setHashValueSerializer(doubleTemplate.getDefaultSerializer());
  26. doubleTemplate.afterPropertiesSet();
  27.  
  28. longTemplate = new RedisTemplate<>();
  29. longTemplate.setConnectionFactory(connectionFactory);
  30. longTemplate.setKeySerializer(longTemplate.getStringSerializer());
  31. longTemplate.setHashKeySerializer(longTemplate.getStringSerializer());
  32. longTemplate.setHashValueSerializer(new LongSerializer());
  33. longTemplate.afterPropertiesSet();
  34.  
  35. HashTest hashTest = ctx.getBean(HashTest.class);
  36. // hashTest.insert();
  37. // hashTest.batchInsert();
  38. // hashTest.insertIfAbsent();
  39. // hashTest.findAll();
  40. // hashTest.findOne();
  41. // hashTest.findAllKeys();
  42. // hashTest.incrementDouble();
  43. hashTest.incrementLong();
  44. }
  45.  
  46. public void insert() {
  47. UserInfo info = new UserInfo();
  48. info.setName("Tomy");
  49. info.setAge(20);
  50. info.setBirthday(new Date());
  51. info.setId(UUID.randomUUID().toString());
  52. userTemplate.opsForHash().put(key, info.getId(), info);
  53. log.info("insert User[" + info + "] success!");
  54. log.info("User Hash size is : " + userTemplate.opsForHash().size(key));
  55. }
  56.  
  57. public void batchInsert() {
  58. Map<String, UserInfo> users = new HashMap<>();
  59. for (int i = 1; i <= 3; i++) {
  60. UserInfo info = new UserInfo();
  61. info.setName("Tomy" + i);
  62. info.setAge(20 + i);
  63. info.setBirthday(new Date());
  64. info.setId(UUID.randomUUID().toString());
  65. users.put(info.getId(), info);
  66. }
  67. userTemplate.opsForHash().putAll(key, users);
  68. log.info("batchInsert Users[" + users + "] success!");
  69. log.info("User Hash size is : " + userTemplate.opsForHash().size(key));
  70. }
  71.  
  72. public void insertIfAbsent() {
  73. UserInfo info = new UserInfo();
  74. info.setName("Tomy4");
  75. info.setAge(20);
  76. info.setBirthday(new Date());
  77. info.setId(UUID.randomUUID().toString());
  78. userTemplate.opsForHash().putIfAbsent(key, info.getId(), info);
  79. log.info("insertIfAbsent User[" + info + "] success!");
  80. log.info("User Hash size is : " + userTemplate.opsForHash().size(key));
  81. }
  82.  
  83. public void findAll() {
  84. Map<Object, Object> users = userTemplate.opsForHash().entries(key);
  85. log.info("All User[" + users + "]");
  86. log.info("findAll User size is : " + users.size());
  87. }
  88.  
  89. public UserInfo findOne() {
  90. String hashKey = "2ca66275-88ab-49e5-8651-b987e55d9347";
  91. Object userInfo = userTemplate.opsForHash().get(key, hashKey);
  92. // boolean have = userTemplate.opsForHash().hasKey(hashKey, hashKey);
  93. log.info("find one : " + userInfo);
  94. return userInfo != null ? (UserInfo) userInfo : null;
  95. }
  96.  
  97. public Set<Object> findAllKeys() {
  98. Set<Object> users = userTemplate.opsForHash().keys(key);
  99. log.info("find : " + users.size() + " users :" + users);
  100. return users;
  101. }
  102.  
  103. public void scan() {
  104. userTemplate.opsForHash().scan(key, ScanOptions.NONE);
  105. }
  106.  
  107. public void incrementDouble() {
  108. String hashKey = UUID.randomUUID().toString();
  109. Double value1 = doubleTemplate.opsForHash().increment(key, hashKey,
  110. Double.valueOf("30"));
  111. log.info(key + ":" + hashKey + " has value :" + value1);
  112. Double delta = Double.valueOf("30.3");
  113. Double value2 = doubleTemplate.opsForHash().increment(key, hashKey, delta);
  114. log.info(key + ":" + hashKey + " has value: " + value2 + ", after increment " + delta);
  115. }
  116.  
  117. public void incrementLong() {
  118. String hashKey = UUID.randomUUID().toString();
  119. long value1 = doubleTemplate.opsForHash().increment(key, hashKey, 30l);
  120. log.info(key + ":" + hashKey + " has value :" + value1);
  121. long delta = 20l;
  122. long value2 = doubleTemplate.opsForHash().increment(key, hashKey, delta);
  123. log.info(key + ":" + hashKey + " has value: " + value2 + ", after increment " + delta);
  124. }
  125.  
  126. }

4.List(列表)

  1. public class ListsTest extends RedisCommon {
  2. private static RedisTemplate<String, UserInfo> userTemplate;
  3.  
  4. public static void main(String[] args) throws InterruptedException {
  5. log.info("-----------Starting Redis Lists testing-----------");
  6. ApplicationContext ctx = SpringApplication.run(ListsTest.class, args);
  7. RedisConnectionFactory connectionFactory = ctx
  8. .getBean(RedisConnectionFactory.class);
  9. userTemplate = new RedisTemplate<>();
  10. userTemplate.setConnectionFactory(connectionFactory);
  11. userTemplate.setKeySerializer(userTemplate.getStringSerializer());
  12. userTemplate.setValueSerializer(new JacksonJsonRedisSerializer<UserInfo>(
  13. UserInfo.class));
  14. userTemplate.afterPropertiesSet();
  15.  
  16. String key = "UserInfo";
  17.  
  18. ListsTest listsTest = ctx.getBean(ListsTest.class);
  19. listsTest.leftpush(key);
  20. listsTest.leftpushBatch(key);
  21. listsTest.leftpop(key);
  22. listsTest.rightPopAndLeftPush(key);
  23. }
  24.  
  25. public void leftpush(String key) {
  26. int size = 10;
  27. for(int i = 0; i < size; i++){
  28. UserInfo info = new UserInfo();
  29. info.setName("Tomy" + i);
  30. info.setAge(20 + i);
  31. info.setBirthday(new Date());
  32. info.setId(UUID.randomUUID().toString());
  33. userTemplate.opsForList().leftPush(key, info);
  34. //userTemplate.opsForList().leftPush(key, pivot, value)
  35. //userTemplate.opsForList().leftPushIfPresent(key, value)
  36. //userTemplate.opsForList().rightPush(key, pivot, value)
  37. //userTemplate.opsForList().rightPushIfPresent(key, value)
  38. }
  39. log.info("insert [" + size + "] User success! " + key + "'s size is:" + userTemplate.opsForList().size(key));
  40. }
  41.  
  42. public void leftpushBatch(String key){
  43. int size = 20;
  44. List<UserInfo> users = new ArrayList<>();
  45. for(int i = 10; i < size; i++){
  46. UserInfo info = new UserInfo();
  47. info.setName("Tomy" + i);
  48. info.setAge(20 + i);
  49. info.setBirthday(new Date());
  50. info.setId(UUID.randomUUID().toString());
  51. users.add(info);
  52. }
  53. userTemplate.opsForList().leftPushAll(key, users.toArray(new UserInfo[users.size()]));
  54. //userTemplate.opsForList().rightPushAll(key, (UserInfo[])users.toArray());
  55. log.info("batchinsert [" + users.size() + "] User success! " + key + "'s size is:" + userTemplate.opsForList().size(key));
  56. }
  57.  
  58. public void leftpop(String key){
  59. UserInfo userInfo = userTemplate.opsForList().leftPop(key, 2, TimeUnit.SECONDS);
  60. //userTemplate.opsForList().leftPop(key);
  61. AtomicInteger ai = new AtomicInteger(0);
  62. while(userInfo != null){
  63. ai.incrementAndGet();
  64. userInfo = userTemplate.opsForList().leftPop(key, 2, TimeUnit.SECONDS);
  65. }
  66. log.info("pop [" + ai.get() + "] Users from " + key);
  67. }
  68.  
  69. public void rightPopAndLeftPush(String srcKey){
  70. String destinationKey = "destinationKey";
  71. log.info("srcKey [" + srcKey + "]'s size : " + userTemplate.opsForList().size(srcKey));
  72. log.info("destKey [" + destinationKey + "]'s size : " + userTemplate.opsForList().size(destinationKey));
  73. UserInfo userInfo = userTemplate.opsForList().rightPopAndLeftPush(srcKey, destinationKey);
  74. while(userInfo != null){
  75. userInfo = userTemplate.opsForList().rightPopAndLeftPush(srcKey, destinationKey, 2, TimeUnit.SECONDS);
  76. }
  77. log.info("After rightPopAndLeftPush destKey [" + destinationKey + "]'s size : " + userTemplate.opsForList().size(destinationKey));
  78. }
  79.  
  80. }

5.Set(集合)

  1. public class SetTest extends RedisCommon {
  2.  
  3. public static void main(String[] args) throws InterruptedException {
  4. log.info("-----------Starting Redis Set testing-----------");
  5. ApplicationContext ctx = SpringApplication.run(SetTest.class, args);
  6. StringRedisTemplate st = ctx.getBean(StringRedisTemplate.class);
  7. String key = "SetKey";
  8. String destKey = "DestKey";
  9. String[] values = new String[]{"value1","value2","value3","value4","value5","value6","value7"};
  10. log.info("SetKey add [" + st.opsForSet().add(key, values ) + "] values ");
  11. log.info("SetKey's member " + st.opsForSet().members(key));
  12. String value5 = "value5";
  13. log.info(value5 + " is member of SetKey's : " + st.opsForSet().isMember(key, value5));
  14. log.info("SetKey's randomMember [" + st.opsForSet().randomMember(key) + "]");
  15. log.info("SetKey's size: " + st.opsForSet().size(key));
  16.  
  17. String[] subValues = new String[]{"value1","value2","value3"};
  18. log.info("SetKey remove " + st.opsForSet().remove(key, subValues) + " members");
  19. log.info("SetKey's size: " + st.opsForSet().size(key));
  20.  
  21. log.info("SetKey move to DestKey: " + st.opsForSet().move(key, value5, destKey));
  22. log.info("SetKey's size: " + st.opsForSet().size(key));
  23. log.info("DestKey size: " + st.opsForSet().size(destKey));
  24.  
  25. String popValue = st.opsForSet().pop(key);
  26. log.info("SetKey move to DestKey: " + st.opsForSet().move(key, popValue, destKey));
  27. log.info("SetKey's size: " + st.opsForSet().size(key));
  28. log.info("DestKey size: " + st.opsForSet().size(destKey));
  29.  
  30. //st.opsForSet().difference(key, destKey);
  31. //st.opsForSet().differenceAndStore(key, otherKeys, destKey);
  32.  
  33. //st.opsForSet().intersect(key, destKey);
  34. //st.opsForSet().intersectAndStore(key, otherKey, destKey);
  35. }
  36.  
  37. }

6.SortedSet(有序集合)

  1. public class ZSetTest extends RedisCommon {
  2.  
  3. public static void main(String[] args) throws InterruptedException {
  4. log.info("-----------Starting Redis ZSet testing-----------");
  5. ApplicationContext ctx = SpringApplication.run(ZSetTest.class, args);
  6. StringRedisTemplate st = ctx.getBean(StringRedisTemplate.class);
  7. String key = "ZSetKey";
  8. Set<TypedTuple<String>> values = new HashSet<>();
  9. for (int i = 0; i < 10; i++) {
  10. TypedTuple<String> tuple = new DefaultTypedTuple<String>("value-"
  11. + i, 12d + i);
  12. values.add(tuple);
  13. }
  14. // log.info("SetKey add [" + st.opsForZSet().add(key, values) + "] values");
  15. //st.opsForZSet().add(key, value, score)
  16. //st.opsForZSet().incrementScore(key, value, delta)
  17. log.info("SetKey has [" + st.opsForZSet().size(key) + "] values");
  18.  
  19. double start = 15d;
  20. double end = 18d;
  21. log.info("SetKey between " + start + " and " + end + " have " + st.opsForZSet().count(key, start, end));
  22.  
  23. long s = 1;
  24. long e = 5;
  25. log.info("SetKey range from " + s + " to " + e + " have " + st.opsForZSet().range(key, s, e));
  26. //st.opsForZSet().rangeByScore(key, min, max, offset, count)
  27. //st.opsForZSet().rangeByScoreWithScores(key, min, max)
  28. //st.opsForZSet().rangeByScoreWithScores(key, min, max, offset, count)
  29. //st.opsForZSet()
  30.  
  31. String member = "value-5";
  32. log.info(member + "'s rank is " + st.opsForZSet().rank(key, member) + " in SetKey.");
  33.  
  34. log.info("Remove " + member + " from SetKey : " + st.opsForZSet().remove(key, member));
  35.  
  36. // st.opsForZSet().removeRange(key, start, end)
  37. // st.opsForZSet().removeRangeByScore(key, min, max)
  38. // st.opsForZSet().reverseRange(key, start, end)
  39. // st.opsForZSet().reverseRangeByScore(key, min, max)
  40. // st.opsForZSet().reverseRangeByScoreWithScores(key, min, max)
  41. // st.opsForZSet().reverseRank(key, o)
  42. // st.opsForZSet().unionAndStore(key, otherKeys, destKey)
  43. // st.opsForZSet().unionAndStore(key, otherKey, destKey)
  44. }
  45.  
  46. }

7.Pub/Sub(发布/订阅)

  1. public class TopicTest extends RedisCommon {
  2. private static String topicName = "Topic:chat";
  3.  
  4. @Bean
  5. RedisMessageListenerContainer container(
  6. RedisConnectionFactory connectionFactory,
  7. MessageListenerAdapter listenerAdapter) {
  8. RedisMessageListenerContainer container = new RedisMessageListenerContainer();
  9. container.setConnectionFactory(connectionFactory);
  10. container.addMessageListener(listenerAdapter, new PatternTopic(topicName));
  11. //container.addMessageListener(listenerAdapter, new ChannelTopic(topicName));
  12. return container;
  13. }
  14.  
  15. @Bean
  16. MessageListenerAdapter listenerAdapter(Receiver receiver) {
  17. return new MessageListenerAdapter(receiver, "receiveMessage");
  18. }
  19.  
  20. @Bean
  21. Receiver receiver(@Value("Receiver-1") String name) {
  22. return new Receiver(name);
  23. }
  24.  
  25. public static void main(String[] args) throws InterruptedException {
  26. log.info("-----------Starting Redis Topic testing-----------");
  27. ApplicationContext ctx = SpringApplication.run(TopicTest.class, args);
  28. StringRedisTemplate template = ctx.getBean(StringRedisTemplate.class);
  29. template.convertAndSend(topicName, "Hello from Redis!");
  30. }
  31.  
  32. static class Receiver {
  33. private String name;
  34.  
  35. @Autowired
  36. public Receiver(String name) {
  37. this.name = name;
  38. }
  39.  
  40. public void receiveMessage(String message) {
  41. log.info(name + " received <" + message + ">");
  42. }
  43. }
  44.  
  45. }

源码请戳这里

Java操作Redis数据的更多相关文章

  1. java 操作redis

    使用Java操作Redis需要jedis-2.1.0.jar,如果需要使用Redis连接池的话,还需commons-pool-1.5.4.jar package com.test; import ja ...

  2. windows下Redis安装及利用java操作Redis

    一.windows下Redis安装 1.Redis下载 下载地址:https://github.com/MicrosoftArchive/redis 打开下载地址后,选择版本 然后选择压缩包 下载 R ...

  3. java操作redis集群配置[可配置密码]和工具类

    java操作redis集群配置[可配置密码]和工具类     <dependency>   <groupId>redis.clients</groupId>   & ...

  4. Linux+Redis实战教程_day02_3、redis数据类型_4、String命令_5、hash命令_6、java操作redis数据库技术

    3. redis数据类型[重点] redis 使用的是键值对保存数据.(map) key:全部都是字符串 value:有五种数据类型 Key名:自定义,key名不要过长,否则影响使用效率 Key名不要 ...

  5. java操作redis学习(一):安装及连接

    文章参考自:http://www.cnblogs.com/edisonfeng/p/3571870.html,在此基础上进行了修改. 一.下载安装Redis redis官网显示暂时不支持Windows ...

  6. Java操作redis【二十】

    1.首先需要将redis的绑定地址为127.0.0.1去掉,同时将redis的保护模式去掉,并且开放6379端口. 如果是保护模式需要输入密码才能连接. (1)去掉绑定地址: (2)去掉保护模式: ( ...

  7. 使用Java操作Redis(一)

    Redis是一款基于key-value的数据库服务器,安装完成后我们可以通过redis-cli使用Redis提供的命令完成各种操作.redis-cli实际上就是一款客户端,和redis-server建 ...

  8. Redis基础知识、命令以及java操作Redis

    1 nosql的概念 sql:操作(关系型)数据库的标准查询语言 关系型数据库(rdbms):以关系(由行和列组成的二维表)模型为核心数据库,有表的储存系统.(mysql.oracle.sqlserv ...

  9. 最全的Java操作Redis的工具类,使用StringRedisTemplate实现,封装了对Redis五种基本类型的各种操作!

    转载自:https://github.com/whvcse/RedisUtil 代码 ProtoStuffSerializerUtil.java import java.io.ByteArrayInp ...

随机推荐

  1. 从入门到自闭之Python序列化

    序列化(背) json :将数据类型转换成字符串(序列化),将字符串装换成原数据类型(反序列),支持dict,list,tuple等,序列后都变成了列表 dumps,loads ------ 用于网络 ...

  2. python_0基础开始_day12

    第十二节 一,生成器 生成器的核心:生成器的本质就是迭代器 迭代器是python自带的 生成器是程序员自己写的一种迭代器 在python中有三种方式来创建生成器: 基于函数编写 推导式方式编写 pyt ...

  3. DockerFile 编译语法详解

    Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile来快速创建自定义的镜像,本小结首先介绍Dockerfile典型的基本结构和它支持的众多指令,并具体讲解通过这些指令来编写定 ...

  4. JS基础_数据类型-Number类型

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. Nginx请求限制配置

    Nginx请求限制配置 请求限制可以通过两种方式来配置,分别是  连接频率限制和请求频率限制 首先我们要知道什么是http请求和连接,浏览器和服务端首先通过三次握手完成连接,然后发起请求,传输请求参数 ...

  6. 常用的商业级和免费开源Web漏洞扫描工具

    Scanv 国内著名的商业级在线漏洞扫描.可以长期关注,经常会有免费活动.SCANV具备自动探测发现无主资产.僵尸资产的功能,并对资产进行全生命周期的管理.主动进行网络主机探测.端口探测扫描,硬件特性 ...

  7. Inception网络模型

    最近在研究inception模型,将v1到v4版本的论文都研读了一下,这里做一下总结. 这里推荐一下这个GitHub,博主将常见的论文都做了翻译,大家可以参考中文来加深理解. 1.Inception ...

  8. Dubbo 04 服务化最佳实现流程

    Dubbo 04 服务化最佳实践 分包 建议将服务接口.服务模型.服务异常等均放在 API 包中,因为服务模型和异常也是 API 的一部分,这样做也符合分包原则:重用发布等价原则(REP),共同重用原 ...

  9. 14Filter&Listener

    1.Filter:过滤器 1.1 概念 生活中的过滤器:净水器,空气净化器,土匪. web中的过滤器:当访问服务器的资源时,过滤器可以将请求拦截下来,完成一些特殊的功能. 过滤器的作用: 一般用于完成 ...

  10. 转(static final 和final的区别)

    学习java的时候常常会被修饰符搞糊涂,这里总结下static final和final的区别. 1.static 强调只有一份,final 说明是一个常量,final定义的基本类型的值是不可改变的,但 ...