导入jar包
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
测试
Jedis jedis = new Jedis("127.0.0.1",6379);
System.out.println(jedis.ping());
事务
Jedis jedis = new Jedis("127.0.0.1", 6379);
Transaction transaction = jedis.multi();
transaction.set("k1","k1");
transaction.set("k2","k2");
transaction.set("k3","k3");
transaction.exec();
主从复制
jedis2.slaveof("127.0.0.1",6379);
线程池
```java
public class MyRedisPool {
private static volatile JedisPool jedisPool = null;
private MyRedisPool() {
}
public static JedisPool getJedisPool() {
if (null == jedisPool) {
synchronized (MyRedisPool.class) {
if (null == jedisPool) {
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(1000);
jedisPoolConfig.setMaxIdle(32);
jedisPoolConfig.setMaxWaitMillis(100*1000);
jedisPool = new JedisPool(jedisPoolConfig, "127.0.0.1", 6379);
}
}
}
return jedisPool;
}
}