In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Xiaobian to share with you how to integrate the use of redis spring, I believe most people still do not know how to use, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
1. brief introduction
Redis is based on C language development.
Redis is a key-value storage system. Similar to Memcached, it supports a relatively large number of stored value types, including string, list, set, zset, and hash.
redis is a cache database (one-sided understanding) can do both cache, you can also persist the data to disk!
2.pom.xml introduces related jars (errors have been reported due to jar version problems, please note)
org.apache.commons commons-pool2 2.2 org.springframework.data spring-data-redis 1.7.5.RELEASE redis.clients jedis 2.9.0
3.spring-redis.xml configuration file, configure key bean redisTemplate
The configuration file redis-config.properteis used above
redis.maxIdle=1redis.maxTotal=5redis.maxWaitMillis=30000redis.testOnBorrow=trueredis.hostname=127.0.0.1redis.port=6379
4. Redis has four key interfaces:
private ValueOperations valueOps;
private ListOperations listOps;
private SetOperations setOps;
private ZSetOperations zSetOps;
Data types corresponding to redis: string, hash, list, set, and zset(sorted set)
Specifically, use the following code:
//Add string ValueOperations value = this.redisTemplate.opsForValue();value.set ("hello", "hate");System.out.println (value.get("hello"));//add a hash set HashOperations hash =redisTemplate.opsForHash();hash.put ("Walmart,""fruit, ""apple");hash.put ("Walmart","Beverage", "Red Bull");System.out.println (hash.entries("Walmart"));//add a list set ListOperations list = redisTemplate.opsForList();list.rightPush ("course", "chinese");list.rightPush ("Course", "englise");System.out.println (list.range("lpList", 0, 1));//add a set SetOperations set = redisTemplate.opsForSet();set.add ("lpSet", "lp");set.add ("lpSet", "26");set.add ("lpSet", "178cm");//output set System.out.println (set.members("lpSet"));//add ordered set ZSetOperations zset = redisTemplate.opsForZSet();zset.add ("lpZset", "lp", 0);zset.add("lpZset", "26", 2);zset.add("lpZset", "178cm", 1);//Output ordered set set System.out.println(zset.rangeByScore("lpZset", 0, 2)); Above is "How spring integrates redis use" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.