{"id":62954,"date":"2026-01-21T00:41:36","date_gmt":"2026-01-20T16:41:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/62954.html"},"modified":"2026-01-21T00:41:36","modified_gmt":"2026-01-20T16:41:36","slug":"springdataredis%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/62954.html","title":{"rendered":"SpringDataRedis\u5feb\u901f\u5165\u95e8"},"content":{"rendered":"<h3>\u4e00\u3001\u524d\u8a00&#xff1a;\u4e3a\u4ec0\u4e48\u7528 Spring Data Redis&#xff1f;<\/h3>\n<p>\u4f60\u662f\u5426\u8fd8\u5728\u624b\u52a8\u7ba1\u7406 Jedis \u8fde\u63a5\u6c60&#xff1f; \u662f\u5426\u4e3a\u6bcf\u4e2a Redis \u64cd\u4f5c\u5199\u91cd\u590d\u7684\u00a0try-finally\u00a0\u4ee3\u7801&#xff1f; \u662f\u5426\u5e0c\u671b\u50cf\u64cd\u4f5c\u6570\u636e\u5e93\u4e00\u6837&#xff0c;\u7528\u58f0\u660e\u5f0f\u65b9\u5f0f\u64cd\u4f5c Redis&#xff1f;<\/p>\n<p>Spring Data Redis\u00a0\u6b63\u662f\u4e3a\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f&#xff01;<\/p>\n<p>\u4f5c\u4e3a Spring \u5b98\u65b9\u63d0\u4f9b\u7684 Redis \u96c6\u6210\u6a21\u5757&#xff0c;\u5b83&#xff1a; \u2705 \u81ea\u52a8\u7ba1\u7406\u8fde\u63a5&#xff08;\u9ed8\u8ba4\u4f7f\u7528\u9ad8\u6027\u80fd Lettuce \u5ba2\u6237\u7aef&#xff09; \u2705 \u63d0\u4f9b\u00a0RedisTemplate\u00a0\u548c\u00a0StringRedisTemplate\u00a0\u7b80\u5316\u64cd\u4f5c \u2705 \u652f\u6301\u5e8f\u5217\u5316\u5b9a\u5236\u3001\u4e8b\u52a1\u3001\u7ba1\u9053\u7b49\u9ad8\u7ea7\u7279\u6027 \u2705 \u65e0\u7f1d\u96c6\u6210 Spring Cache&#xff0c;\u4e00\u884c\u6ce8\u89e3\u5b9e\u73b0\u7f13\u5b58<\/p>\n<p>\u672c\u6587\u5c06\u5e26\u4f60\u4ece\u96f6\u642d\u5efa\u9879\u76ee&#xff0c;\u638c\u63e1\u6838\u5fc3 API&#xff0c;\u5e76\u5199\u51fa\u4f18\u96c5\u7684 Redis \u4ee3\u7801&#xff01;<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u73af\u5883\u51c6\u5907<\/h3>\n<h4>1. \u521b\u5efa Spring Boot \u9879\u76ee&#xff08;2.7&#043; \u6216 3.x&#xff09;<\/h4>\n<p>\u901a\u8fc7\u00a0start.spring.io\u00a0\u6dfb\u52a0\u4f9d\u8d56&#xff1a;<\/p>\n<ul>\n<li>Spring Web<\/li>\n<li>Spring Data Redis (Access&#043;Driver)<\/li>\n<\/ul>\n<p>\u6216\u624b\u52a8\u6dfb\u52a0 Maven \u4f9d\u8d56&#xff1a;<\/p>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;spring-boot-starter-data-redis&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p>&lt;!&#8211; \u82e5\u4f7f\u7528 Spring Boot 3.x&#xff0c;\u65e0\u9700\u989d\u5916\u5f15\u5165 Lettuce &#8211;&gt; <\/p>\n<p>&#x1f4cc;\u00a0\u6ce8\u610f&#xff1a;Spring Boot 2.x \u9ed8\u8ba4\u4f7f\u7528\u00a0Lettuce&#xff08;\u975e\u963b\u585e\u3001\u7ebf\u7a0b\u5b89\u5168&#xff09;&#xff0c;\u4e0d\u518d\u63a8\u8350 Jedis\u3002<\/p>\n<h4>2. \u542f\u52a8\u672c\u5730 Redis<\/h4>\n<p># \u4f7f\u7528 Docker \u5feb\u901f\u542f\u52a8<br \/>\ndocker run -d &#8211;name redis -p 6379:6379 redis:7.0 <\/p>\n<hr \/>\n<h3>\u4e09\u3001\u57fa\u7840\u914d\u7f6e&#xff1a;application.yml<\/h3>\n<p>spring:<br \/>\n  redis:<br \/>\n    host: localhost<br \/>\n    port: 6379<br \/>\n    password: &#034;&#034;          # \u65e0\u5bc6\u7801\u7559\u7a7a<br \/>\n    database: 0<br \/>\n    timeout: 2000ms       # \u8fde\u63a5\u8d85\u65f6<br \/>\n    lettuce:<br \/>\n      pool:<br \/>\n        max-active: 20    # \u6700\u5927\u8fde\u63a5\u6570<br \/>\n        max-idle: 10      # \u6700\u5927\u7a7a\u95f2\u8fde\u63a5<br \/>\n        min-idle: 2       # \u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5<br \/>\n        max-wait: 2000ms  # \u83b7\u53d6\u8fde\u63a5\u6700\u5927\u7b49\u5f85\u65f6\u95f4 <\/p>\n<p>\u2705 Spring Boot \u4f1a\u81ea\u52a8\u914d\u7f6e\u00a0RedisConnectionFactory\u00a0\u548c\u00a0RedisTemplate&#xff0c;\u65e0\u9700\u624b\u52a8\u521b\u5efa\u8fde\u63a5\u6c60&#xff01;<\/p>\n<hr \/>\n<h3>\u56db\u3001\u6838\u5fc3\u64cd\u4f5c&#xff1a;RedisTemplate vs StringRedisTemplate<\/h3>\n<p>Spring Data Redis \u63d0\u4f9b\u4e24\u4e2a\u6838\u5fc3\u6a21\u677f\u7c7b&#xff1a;<\/p>\n<table>\n<tr>\u6a21\u677f\u7c7bKey\/Value \u7c7b\u578b\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>RedisTemplate&lt;K, V&gt;<\/td>\n<td>\u6cdb\u578b&#xff08;Object&#xff09;<\/td>\n<td>\u5b58\u50a8 Java \u5bf9\u8c61&#xff08;\u9700\u5e8f\u5217\u5316&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>StringRedisTemplate<\/td>\n<td>String \/ String<\/td>\n<td>\u7eaf\u5b57\u7b26\u4e32\u64cd\u4f5c&#xff08;\u5982\u9a8c\u8bc1\u7801\u3001\u8ba1\u6570\u5668&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>1. \u4f7f\u7528 StringRedisTemplate&#xff08;\u63a8\u8350\u521d\u5b66\u8005&#xff09;<\/h4>\n<p>&#064;RestController<br \/>\npublic class RedisController {<\/p>\n<p>    &#064;Autowired<br \/>\n    private StringRedisTemplate stringRedisTemplate;<\/p>\n<p>    &#064;GetMapping(&#034;\/set&#034;)<br \/>\n    public String set(&#064;RequestParam String key, &#064;RequestParam String value) {<br \/>\n        stringRedisTemplate.opsForValue().set(key, value, 10, TimeUnit.MINUTES);<br \/>\n        return &#034;OK&#034;;<br \/>\n    }<\/p>\n<p>    &#064;GetMapping(&#034;\/get&#034;)<br \/>\n    public String get(&#064;RequestParam String key) {<br \/>\n        return stringRedisTemplate.opsForValue().get(key);<br \/>\n    }<\/p>\n<p>    \/\/ Hash \u64cd\u4f5c<br \/>\n    &#064;PostMapping(&#034;\/user&#034;)<br \/>\n    public void saveUser(&#064;RequestParam String userId,<br \/>\n                         &#064;RequestParam String name,<br \/>\n                         &#064;RequestParam Integer age) {<br \/>\n        stringRedisTemplate.opsForHash().put(&#034;user:&#034; &#043; userId, &#034;name&#034;, name);<br \/>\n        stringRedisTemplate.opsForHash().put(&#034;user:&#034; &#043; userId, &#034;age&#034;, age.toString());<br \/>\n    }<\/p>\n<p>    \/\/ List \u64cd\u4f5c<br \/>\n    &#064;PostMapping(&#034;\/task&#034;)<br \/>\n    public void addTask(&#064;RequestParam String task) {<br \/>\n        stringRedisTemplate.opsForList().leftPush(&#034;tasks&#034;, task);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u2705\u00a0\u4f18\u70b9&#xff1a;API \u6e05\u6670&#xff0c;opsForXxx()\u00a0\u5bf9\u5e94 Redis \u6570\u636e\u7c7b\u578b<\/p>\n<h4>2. \u4f7f\u7528 RedisTemplate \u5b58\u50a8 Java \u5bf9\u8c61<\/h4>\n<h5>\u6b65\u9aa4 1&#xff1a;\u5b9a\u4e49\u5b9e\u4f53\u7c7b<\/h5>\n<p>public class User implements Serializable {<br \/>\n    private String id;<br \/>\n    private String name;<br \/>\n    private int age;<br \/>\n    \/\/ getter\/setter&#8230;<br \/>\n} <\/p>\n<h5>\u6b65\u9aa4 2&#xff1a;\u914d\u7f6e\u5e8f\u5217\u5316\u65b9\u5f0f&#xff08;\u907f\u514d\u4e71\u7801&#xff09;<\/h5>\n<p>&#064;Configuration<br \/>\npublic class RedisConfig {<\/p>\n<p>    &#064;Bean<br \/>\n    public RedisTemplate&lt;String, Object&gt; redisTemplate(RedisConnectionFactory factory) {<br \/>\n        RedisTemplate&lt;String, Object&gt; template &#061; new RedisTemplate&lt;&gt;();<br \/>\n        template.setConnectionFactory(factory);<\/p>\n<p>        \/\/ \u4f7f\u7528 Jackson \u5e8f\u5217\u5316\u5bf9\u8c61&#xff08;\u53ef\u8bfb\u6027\u5f3a&#xff09;<br \/>\n        Jackson2JsonRedisSerializer&lt;Object&gt; serializer &#061;<br \/>\n            new Jackson2JsonRedisSerializer&lt;&gt;(Object.class);<\/p>\n<p>        ObjectMapper mapper &#061; new ObjectMapper();<br \/>\n        mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);<br \/>\n        mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator(),<br \/>\n                                     ObjectMapper.DefaultTyping.NON_FINAL);<br \/>\n        serializer.setObjectMapper(mapper);<\/p>\n<p>        \/\/ \u8bbe\u7f6e key \u548c value \u7684\u5e8f\u5217\u5316\u65b9\u5f0f<br \/>\n        template.setKeySerializer(new StringRedisSerializer());<br \/>\n        template.setValueSerializer(serializer);<br \/>\n        template.setHashKeySerializer(new StringRedisSerializer());<br \/>\n        template.setHashValueSerializer(serializer);<br \/>\n        template.afterPropertiesSet();<br \/>\n        return template;<br \/>\n    }<br \/>\n} <\/p>\n<h5>\u6b65\u9aa4 3&#xff1a;\u64cd\u4f5c\u5bf9\u8c61<\/h5>\n<p>&#064;Autowired<br \/>\nprivate RedisTemplate&lt;String, Object&gt; redisTemplate;<\/p>\n<p>public void saveUser(User user) {<br \/>\n    redisTemplate.opsForValue().set(&#034;user:&#034; &#043; user.getId(), user, 1, TimeUnit.HOURS);<br \/>\n}<\/p>\n<p>public User getUser(String id) {<br \/>\n    return (User) redisTemplate.opsForValue().get(&#034;user:&#034; &#043; id);<br \/>\n} <\/p>\n<p>&#x1f4a1;\u00a0\u63d0\u793a&#xff1a;\u82e5\u4e0d\u914d\u7f6e\u5e8f\u5217\u5316&#xff0c;\u9ed8\u8ba4\u4f7f\u7528 JDK \u5e8f\u5217\u5316&#xff0c;\u4f1a\u5bfc\u81f4 Redis \u4e2d\u51fa\u73b0\u4e0d\u53ef\u8bfb\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u5e38\u7528\u64cd\u4f5c\u901f\u67e5\u8868<\/h3>\n<table>\n<tr>\u64cd\u4f5c\u4ee3\u7801\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>String<\/td>\n<td>opsForValue().set(&#034;k&#034;, &#034;v&#034;)<\/td>\n<\/tr>\n<tr>\n<td>Hash<\/td>\n<td>opsForHash().put(&#034;user:1&#034;, &#034;name&#034;, &#034;\u5f20\u4e09&#034;)<\/td>\n<\/tr>\n<tr>\n<td>List<\/td>\n<td>opsForList().rightPush(&#034;queue&#034;, &#034;item&#034;)<\/td>\n<\/tr>\n<tr>\n<td>Set<\/td>\n<td>opsForSet().add(&#034;tags&#034;, &#034;java&#034;, &#034;redis&#034;)<\/td>\n<\/tr>\n<tr>\n<td>ZSet<\/td>\n<td>opsForZSet().add(&#034;rank&#034;, &#034;playerA&#034;, 95.5)<\/td>\n<\/tr>\n<tr>\n<td>\u8fc7\u671f\u65f6\u95f4<\/td>\n<td>expire(&#034;key&#034;, 60, TimeUnit.SECONDS)<\/td>\n<\/tr>\n<tr>\n<td>\u6279\u91cf\u64cd\u4f5c<\/td>\n<td>opsForValue().multiSet(map)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u516d\u3001\u8fdb\u9636&#xff1a;\u7ed3\u5408 Spring Cache \u5b9e\u73b0\u58f0\u660e\u5f0f\u7f13\u5b58<\/h3>\n<p>\u53ea\u9700\u4e09\u6b65&#xff0c;\u65b9\u6cd5\u7ed3\u679c\u81ea\u52a8\u7f13\u5b58&#xff01;<\/p>\n<h4>1. \u542f\u7528\u7f13\u5b58<\/h4>\n<p>&#064;SpringBootApplication<br \/>\n&#064;EnableCaching \/\/ \u2190 \u5173\u952e\u6ce8\u89e3<br \/>\npublic class Application {<br \/>\n    public static void main(String[] args) {<br \/>\n        SpringApplication.run(Application.class, args);<br \/>\n    }<br \/>\n} <\/p>\n<h4>2. \u5728 Service \u65b9\u6cd5\u4e0a\u52a0\u6ce8\u89e3<\/h4>\n<p>&#064;Service<br \/>\npublic class UserService {<\/p>\n<p>    &#064;Cacheable(value &#061; &#034;users&#034;, key &#061; &#034;#id&#034;)<br \/>\n    public User getUserById(String id) {<br \/>\n        System.out.println(&#034;\u67e5\u8be2\u6570\u636e\u5e93&#8230;&#034;); \/\/ \u4ec5\u9996\u6b21\u6253\u5370<br \/>\n        return userMapper.selectById(id);<br \/>\n    }<\/p>\n<p>    &#064;CacheEvict(value &#061; &#034;users&#034;, key &#061; &#034;#id&#034;)<br \/>\n    public void updateUser(User user) {<br \/>\n        userMapper.update(user);<br \/>\n    }<br \/>\n} <\/p>\n<p>\u2705\u00a0\u6548\u679c&#xff1a;<\/p>\n<ul>\n<li>\u7b2c\u4e00\u6b21\u8c03\u7528\u00a0getUserById(&#034;1001&#034;)\u00a0\u2192 \u67e5\u8be2 DB \u5e76\u7f13\u5b58<\/li>\n<li>\u540e\u7eed\u8c03\u7528 \u2192 \u76f4\u63a5\u8fd4\u56de\u7f13\u5b58&#xff0c;\u4e0d\u6267\u884c\u65b9\u6cd5\u4f53<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u4e0e\u907f\u5751\u6307\u5357<\/h3>\n<h4>\u274c \u5751 1&#xff1a;Redis \u4e2d\u51fa\u73b0\u00a0\\\\xac\\\\xed\\\\x00\\\\x05\u00a0\u4e71\u7801<\/h4>\n<p>\u539f\u56e0&#xff1a;\u4f7f\u7528\u4e86\u9ed8\u8ba4\u7684 JDK \u5e8f\u5217\u5316 \u89e3\u51b3&#xff1a;\u914d\u7f6e\u00a0StringRedisSerializer\u00a0\u6216\u00a0Jackson2JsonRedisSerializer<\/p>\n<h4>\u274c \u5751 2&#xff1a;\u7f13\u5b58\u7a7f\u900f&#xff08;\u5927\u91cf\u67e5\u4e0d\u5b58\u5728\u7684 key&#xff09;<\/h4>\n<p>\u65b9\u6848&#xff1a;\u5bf9 null \u7ed3\u679c\u4e5f\u7f13\u5b58&#xff08;\u77ed TTL&#xff09;&#xff0c;\u6216\u4f7f\u7528\u5e03\u9686\u8fc7\u6ee4\u5668<\/p>\n<h4>\u274c \u5751 3&#xff1a;\u7f13\u5b58\u96ea\u5d29&#xff08;\u5927\u91cf key \u540c\u65f6\u8fc7\u671f&#xff09;<\/h4>\n<p>\u65b9\u6848&#xff1a;\u8bbe\u7f6e\u968f\u673a\u8fc7\u671f\u65f6\u95f4&#xff0c;\u5982\u00a0600 &#043; random(60)<\/p>\n<hr \/>\n<h3>\u516b\u3001Jedis vs Lettuce vs Spring Data Redis<\/h3>\n<table>\n<tr>\u65b9\u6848\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u539f\u751f Jedis<\/td>\n<td>\u5b66\u4e60 Redis \u534f\u8bae\u3001\u6781\u7b80\u9879\u76ee<\/td>\n<\/tr>\n<tr>\n<td>JedisPool<\/td>\n<td>\u9700\u8981\u7cbe\u7ec6\u63a7\u5236\u8fde\u63a5\u6c60\u7684\u4e2d\u5c0f\u9879\u76ee<\/td>\n<\/tr>\n<tr>\n<td>Spring Data Redis (Lettuce)<\/td>\n<td>\u2705\u00a0\u4e3b\u6d41\u9009\u62e9&#xff1a;Spring Boot \u9879\u76ee\u3001\u9ad8\u5e76\u53d1\u3001\u54cd\u5e94\u5f0f\u652f\u6301<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f4cc;\u00a0\u5efa\u8bae&#xff1a;\u65b0\u9879\u76ee\u76f4\u63a5\u4f7f\u7528\u00a0Spring Data Redis &#043; Lettuce<\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u7ed3\u8bed<\/h3>\n<p>\u611f\u8c22\u60a8\u7684\u9605\u8bfb&#xff01;\u5982\u679c\u4f60\u6709\u4efb\u4f55\u7591\u95ee\u6216\u60f3\u8981\u5206\u4eab\u7684\u7ecf\u9a8c&#xff0c;\u8bf7\u5728\u8bc4\u8bba\u533a\u7559\u8a00\u4ea4\u6d41&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u524d\u8a00&#xff1a;\u4e3a\u4ec0\u4e48\u7528 Spring Data Redis&#xff1f;<br \/>\n\u4f60\u662f\u5426\u8fd8\u5728\u624b\u52a8\u7ba1\u7406 Jedis \u8fde\u63a5\u6c60&#xff1f; \u662f\u5426\u4e3a\u6bcf\u4e2a Redis \u64cd\u4f5c\u5199\u91cd\u590d\u7684\u00a0try-finally\u00a0\u4ee3\u7801&#xff1f; \u662f\u5426\u5e0c\u671b\u50cf\u64cd\u4f5c\u6570\u636e\u5e93\u4e00\u6837&#xff0c;\u7528\u58f0\u660e\u5f0f\u65b9\u5f0f\u64cd\u4f5c Redis&#xff1f;<br \/>\nSpring Data Redis\u00a0\u6b63\u662f\u4e3a\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f&#xff01;<br \/>\n\u4f5c\u4e3a Spring \u5b98\u65b9\u63d0\u4f9b\u7684 Redis \u96c6\u6210\u6a21\u5757&#xff0c;\u5b83&#xff1a;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[105,398],"topic":[],"class_list":["post-62954","post","type-post","status-publish","format-standard","hentry","category-server","tag-redis","tag-398"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SpringDataRedis\u5feb\u901f\u5165\u95e8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/62954.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SpringDataRedis\u5feb\u901f\u5165\u95e8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u524d\u8a00&#xff1a;\u4e3a\u4ec0\u4e48\u7528 Spring Data Redis&#xff1f; \u4f60\u662f\u5426\u8fd8\u5728\u624b\u52a8\u7ba1\u7406 Jedis \u8fde\u63a5\u6c60&#xff1f; \u662f\u5426\u4e3a\u6bcf\u4e2a Redis \u64cd\u4f5c\u5199\u91cd\u590d\u7684\u00a0try-finally\u00a0\u4ee3\u7801&#xff1f; \u662f\u5426\u5e0c\u671b\u50cf\u64cd\u4f5c\u6570\u636e\u5e93\u4e00\u6837&#xff0c;\u7528\u58f0\u660e\u5f0f\u65b9\u5f0f\u64cd\u4f5c Redis&#xff1f; Spring Data Redis\u00a0\u6b63\u662f\u4e3a\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f&#xff01; \u4f5c\u4e3a Spring \u5b98\u65b9\u63d0\u4f9b\u7684 Redis \u96c6\u6210\u6a21\u5757&#xff0c;\u5b83&#xff1a;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/62954.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-20T16:41:36+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62954.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/62954.html\",\"name\":\"SpringDataRedis\u5feb\u901f\u5165\u95e8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-20T16:41:36+00:00\",\"dateModified\":\"2026-01-20T16:41:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/62954.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/62954.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62954.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SpringDataRedis\u5feb\u901f\u5165\u95e8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SpringDataRedis\u5feb\u901f\u5165\u95e8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/62954.html","og_locale":"zh_CN","og_type":"article","og_title":"SpringDataRedis\u5feb\u901f\u5165\u95e8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001\u524d\u8a00&#xff1a;\u4e3a\u4ec0\u4e48\u7528 Spring Data Redis&#xff1f; \u4f60\u662f\u5426\u8fd8\u5728\u624b\u52a8\u7ba1\u7406 Jedis \u8fde\u63a5\u6c60&#xff1f; \u662f\u5426\u4e3a\u6bcf\u4e2a Redis \u64cd\u4f5c\u5199\u91cd\u590d\u7684\u00a0try-finally\u00a0\u4ee3\u7801&#xff1f; \u662f\u5426\u5e0c\u671b\u50cf\u64cd\u4f5c\u6570\u636e\u5e93\u4e00\u6837&#xff0c;\u7528\u58f0\u660e\u5f0f\u65b9\u5f0f\u64cd\u4f5c Redis&#xff1f; Spring Data Redis\u00a0\u6b63\u662f\u4e3a\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u800c\u751f&#xff01; \u4f5c\u4e3a Spring \u5b98\u65b9\u63d0\u4f9b\u7684 Redis \u96c6\u6210\u6a21\u5757&#xff0c;\u5b83&#xff1a;","og_url":"https:\/\/www.wsisp.com\/helps\/62954.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-20T16:41:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/62954.html","url":"https:\/\/www.wsisp.com\/helps\/62954.html","name":"SpringDataRedis\u5feb\u901f\u5165\u95e8 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-20T16:41:36+00:00","dateModified":"2026-01-20T16:41:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/62954.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/62954.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/62954.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"SpringDataRedis\u5feb\u901f\u5165\u95e8"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=62954"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62954\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=62954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=62954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=62954"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=62954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}