-
- <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxTotal" value="100" />
- <property name="maxIdle" value="20" />
- <property name="minIdle" value="10" />
- <property name="blockWhenExhausted" value="true"></property>
- <property name="maxWaitMillis" value="3000" />
- <property name="testOnBorrow" value="false" />
- <property name="testOnReturn" value="false" />
- <property name="testWhileIdle" value="true" />
- <property name="minEvictableIdleTimeMillis" value="60000" />
- <property name="timeBetweenEvictionRunsMillis" value="30000" />
- <property name="numTestsPerEvictionRun" value="-1" />
- </bean>
-
-
- <bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">
- <constructor-arg index="0">
- <set>
- <bean class="redis.clients.jedis.HostAndPort">
- <constructor-arg index="0" value="192.168.1.111" />
- <constructor-arg index="1" value="7111" type="int" />
- </bean>
- <bean class="redis.clients.jedis.HostAndPort">
- <constructor-arg index="0" value="192.168.1.112" />
- <constructor-arg index="1" value="7112" type="int" />
- </bean>
- <bean class="redis.clients.jedis.HostAndPort">
- <constructor-arg index="0" value="192.168.1.113" />
- <constructor-arg index="1" value="7113" type="int" />
- </bean>
- <bean class="redis.clients.jedis.HostAndPort">
- <constructor-arg index="0" value="192.168.1.114" />
- <constructor-arg index="1" value="7114" type="int" />
- </bean>
- <bean class="redis.clients.jedis.HostAndPort">
- <constructor-arg index="0" value="192.168.1.115" />
- <constructor-arg index="1" value="7115" type="int" />
- </bean>
- <bean class="redis.clients.jedis.HostAndPort">
- <constructor-arg index="0" value="192.168.1.116" />
- <constructor-arg index="1" value="7116" type="int" />
- </bean>
- </set>
- </constructor-arg>
- <constructor-arg index="1" value="2000" type="int"></constructor-arg>
- <constructor-arg index="2" value="100" type="int"></constructor-arg>
- <constructor-arg index="3" ref="jedisPoolConfig"></constructor-arg>
- </bean>
package lr.test.redis;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import redis.clients.jedis.JedisCluster;
public class RedisClusterSpringTest {
private static final Log log = LogFactory.getLog(RedisClusterSpringTest.class);
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring-context.xml");
context.start();
JedisCluster jedisCluster = (JedisCluster) context.getBean("jedisCluster");
// JedisCluster jedisCluster = SpringContextHolder.getBean(JedisCluster.class);
int num = 1000;
String key = "yingjun";
String value = "";
for (int i=1; i <= num; i++){
// 存数据
//jedisCluster.set(key+i, "yingjun"+i);
//jedisCluster.setex(key+i, 60, "yingjun"+i);
// 取数据
value = jedisCluster.get(key+i);
log.info(key+i + "=" + value);
// 删除数据
//jedisCluster.del(key+i);
//value = jedisCluster.get(key+i);
//log.info(key+i + "=" + value);
}
context.stop();
} catch (Exception e) {
log.error("==>RedisSpringTest context start error:", e);
System.exit(0);
} finally {
log.info("===>System.exit");
System.exit(0);
}
}
}