In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the function and usage of Spring Data Redis". In the daily operation, I believe many people have doubts about the function and usage of Spring Data Redis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the function and usage of Spring Data Redis". Next, please follow the editor to study!
SpringDataRedis is a part of the Spring family, which provides access to redis services through simple configuration in Spring applications, highly encapsulates the underlying development package of redis, RedisTemplate provides various operations of redis, exception handling and serialization, supports distributed subscription, and implements spring3.1cache.
The functions provided by SpringDataRedis:
1. Automatic management of connection pool, providing a highly encapsulated RedisTemplate class
2. A large number of API in Jedis client are classified and encapsulated, and the same type of operation is encapsulated as operation interface.
ValueOperations: simple Kmurv operation
SetOperations:set type data operation
ZSetOperations:zset type data operation
HashOperations: data manipulation for map types
ListOperations: data manipulation for list types
Getting started case:
1. Import dependency
Org.springframework.boot spring-boot-starter-data-redis org.springframework.boot spring-boot-starter-test
2. Create a startup class
@ SpringBootApplicationpublic class RedisApplication {public static void main (String [] args) {SpringApplication.run (RedisApplication.class);}}
3. Operation value type
@ RunWith (SpringRunner.class) @ SpringBootTestpublic class RedisTests {@ Autowired private RedisTemplate template; @ Testpublic void setValue () {template.boundValueOps ("name") .set ("lianbang.wu");} @ Testpublic void getValue () {String str = (String) template.boundValueOps ("name"). Get (); System.out.println (str);} @ Testpublic void deleteValue () {template.delete ("name") }}
4. Operation set type
@ Testpublic void setValue () {template.boundSetOps ("nameset"). Add ("Reader 1"); template.boundSetOps ("nameset"). Add ("Reader 2"); template.boundSetOps ("nameset"). Add ("Reader 3");} @ Testpublic void getValue () {Set members = template.boundSetOps ("nameset"). Members (); System.out.println (members) } @ Testpublic void deleteValue () {template.boundSetOps ("nameset") .remove ("Reader 1");} @ Testpublic void deleteAll () {template.delete ("nameset");}
5. Operate List
@ Test public void testSetValue () {template.boundListOps ("namelist1"). RightPush ("Reader 1"); template.boundListOps ("namelist1"). LeftPush ("Reader 2");} @ Test public void testGetValue () {List namelist1 = template.boundListOps ("namelist1"). Range (0,10); System.out.println (namelist1);} @ Test public void testSearechIndex () {Object namelist1 = template.boundListOps ("namelist1"). Index (1); System.out.println (namelist1) } @ Test public void testRemoveByIndex () {template.boundListOps ("namelist1") .remove (1, "Reader 1");}
6. Manipulate Hash type
@ Testpublic void testSetValue () {template.boundHashOps ("namehash"). Put ("a", "Reader 1"); template.boundHashOps ("namehash"). Put ("b", "Reader 2");} @ Testpublic void testGetKeys () {Set s = template.boundHashOps ("namehash"). Keys (); System.out.println (s);} @ Testpublic void testGetValue () {List values = template.boundHashOps ("namehash"). Values (); System.out.println (values) } @ Testpublic void testGetValueByKey () {Object o = template.boundHashOps ("namehash"). Get ("a"); System.out.println (o);} @ Testpublic void testRemoveValueByKey () {template.boundHashOps ("namehash"). Delete ("b"); at this point, the study on "the function and usage of Spring Data Redis" is over. I hope to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.