package com.ldr.bean;

import java.lang.reflect.Field;

import redis.clients.jedis.JedisShardInfo;

public class MyJedisInfo {

    String host;
int port;
int db; public JedisShardInfo newInstance() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
JedisShardInfo jedisShardInfo=new JedisShardInfo(host,port) ;
Class<? extends JedisShardInfo> clz = jedisShardInfo.getClass();
Field declaredField = clz.getDeclaredField("db");
declaredField.setAccessible(true);
declaredField.set(jedisShardInfo, db);
return jedisShardInfo;
} public String getHost() {
return host;
} public void setHost(String host) {
this.host = host;
} public int getDb() {
return db;
} public void setDb(int db) {
this.db = db;
}
public int getPort() {
return port;
} public void setPort(int port) {
this.port = port;
}
}

spring中的application.xml中配置如下

    <!-- spring集成redis -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal">
<value>${redis.maxTotal}</value>
</property>
<property name="maxIdle">
<value>${redis.maxIdle}</value>
</property>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
</bean> <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool" scope="singleton">
<constructor-arg index="0" ref="jedisPoolConfig" />
<constructor-arg index="1">
<list>
<!-- <bean class="redis.clients.jedis.JedisShardInfo">
<constructor-arg name="host" value="${redis.host}" />
<constructor-arg name="port" value="${redis.port}" />
</bean> --> <ref bean="jedisShardInfo"/><!-- 生产环境请换成上述 -->
</list>
</constructor-arg>
</bean> <!-- 以下配置上生产请注释掉 begin-->
<bean id="jedisFactory" class="com.ldr.bean.MyJedisInfo">
<property name="host" value="${redis.host}"></property>
<property name="port" value="${redis.port}"></property>
<property name="db" value="${redis.db}"></property>
</bean> <bean id="jedisShardInfo" class="redis.clients.jedis.JedisShardInfo"
factory-bean="jedisFactory" factory-method="newInstance" >
</bean>
<!-- 以上配置上生产请注释掉 end -->

最新文章

  1. 杂项之图像处理pillow
  2. C#中的继承
  3. 右下角浮窗&amp;动画效果
  4. webdriver中PDF控件无法显示的问题(IE兼容性)
  5. 对C#对象的Shallow、Deep Cloning认识【转】
  6. MIUI选项框开关样式模拟
  7. ActionBar官方教程(5)ActionBar的分裂模式(底部tab样式),隐藏标题,隐藏图标
  8. 愉快的开始 - 零基础入门学习Python000
  9. 【HDU 4451 Dressing】水题,组合数
  10. ext4 delalloc相关
  11. JavaScript高级程序设计:第九章
  12. Java程序设计-表达式运算(个人博客)
  13. 将studio项目 转换为eclipse项目
  14. expect--自动批量分发公钥脚本
  15. jenkins(3): jenkins执行shell命令
  16. GlusterFs卷的简单操作
  17. 举例说明Unicode 和UTF-8之间的转换
  18. 深度学习课程笔记(十六)Recursive Neural Network
  19. 485. Max Consecutive Ones最大连续1的个数
  20. 【Java】JABX实现对象与XML互转

热门文章

  1. Dubbo服务的搭建
  2. dedeCMS数据库字段详细介绍
  3. shell脚本,alias别名命令用法。
  4. http post get 同步异步
  5. UIViewAnimationOptions
  6. (47)zabbix报警媒介:Ez Texting
  7. python 中requests 模块用py2exe生成exe后SSL certificate exception的问题
  8. jQuery实现Ajax
  9. windows python MySQLdb 安装配置
  10. C++代码学习之一:组合模式例子