spring-data-redis整合redis集群配置

心已赠人 2022-04-12 03:10 686阅读 0赞

Spring版本:4.3.21.RELEASE
spring-data-redis版本:

  1. <dependency>
  2. <groupId>org.springframework.data</groupId>
  3. <artifactId>spring-data-redis</artifactId>
  4. <version>1.7.2.RELEASE</version>
  5. </dependency>

jedis版本:

  1. <dependency>
  2. <groupId>redis.clients</groupId>
  3. <artifactId>jedis</artifactId>
  4. <version>2.9.0</version>
  5. </dependency>

spring-redis.xml:

  1. <context:annotation-config></context:annotation-config>
  2. <context:component-scan base-package="com.p7.demo.redis" />
  3. <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
  4. <property name="minIdle" value="2" />
  5. <property name="maxIdle" value="10" />
  6. <property name="maxTotal" value="20" />
  7. <property name="maxWaitMillis" value="1000" />
  8. <property name="testOnBorrow" value="true" />
  9. <property name="minEvictableIdleTimeMillis" value="3000" />
  10. </bean>
  11. <bean id="redisClusterConfig"
  12. class="org.springframework.data.redis.connection.RedisClusterConfiguration">
  13. <property name="maxRedirects" value="3"></property>
  14. <property name="clusterNodes">
  15. <set>
  16. <bean class="org.springframework.data.redis.connection.RedisNode">
  17. <constructor-arg name="host" value="192.168.1.11"></constructor-arg>
  18. <constructor-arg name="port" value="6379"></constructor-arg>
  19. </bean>
  20. <bean class="org.springframework.data.redis.connection.RedisNode">
  21. <constructor-arg name="host" value="192.168.1.11"></constructor-arg>
  22. <constructor-arg name="port" value="6380"></constructor-arg>
  23. </bean>
  24. <bean class="org.springframework.data.redis.connection.RedisNode">
  25. <constructor-arg name="host" value="192.168.1.11"></constructor-arg>
  26. <constructor-arg name="port" value="6381"></constructor-arg>
  27. </bean>
  28. </set>
  29. </property>
  30. </bean>
  31. <!-- Redis 连接工厂 -->
  32. <bean id="jeidsConnectionFactory"
  33. class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
  34. <constructor-arg name="clusterConfig" ref="redisClusterConfig" />
  35. <property name="poolConfig" ref="poolConfig" />
  36. <property name="usePool" value="true" />
  37. <property name="timeout" value="5000" />
  38. </bean>
  39. <!--
  40. Redis 客户端
  41. @Resource
  42. private RedisTemplate redisTemplate;
  43. -->
  44. <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
  45. <property name="connectionFactory" ref="jeidsConnectionFactory" />
  46. </bean>
  47. <!--
  48. <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
  49. <property name="connectionFactory" ref="jeidsConnectionFactory" />
  50. </bean>
  51. <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
  52. <property name="connectionFactory" ref="jeidsConnectionFactory" />
  53. <property name="keySerializer">
  54. <bean
  55. class="org.springframework.data.redis.serializer.StringRedisSerializer" />
  56. </property>
  57. <property name="valueSerializer">
  58. <bean
  59. class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
  60. </property>
  61. <property name="hashKeySerializer">
  62. <bean
  63. class="org.springframework.data.redis.serializer.StringRedisSerializer" />
  64. </property>
  65. <property name="hashValueSerializer">
  66. <bean
  67. class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
  68. </property>
  69. </bean>
  70. -->

发表评论

表情:
评论列表 (有 0 条评论,686人围观)

还没有评论,来说两句吧...

相关阅读

    相关 SSM+redis整合

    搭建完redis集群跟java结合起来(redis集群搭建见上一篇博客) 一:不使用框架的情况 1.引入jar(一个jedis jar就够了) ![在这里插入图片描述

    相关 SpringBoot整合redis

    一:缓存的应用场景 1:什么是缓存? 在互联网场景下,尤其 2C 端大流量场景下,需要将一些经常展现和不会频繁变更的数据,存放在存取速率更快的地方。缓存就是一个存储器,在技

    相关 springboot整合redis

    一、redis集群原理 redis集群中的所有节点彼此互联,节点内部采用二进制协议优化传输速度和带宽,每个节点都可以与Java客户端连接。redis集群的数据分配采用哈希