Redis多数据库特性
一个Redis最多可连接16个数据库,下标从0-15,默认连接的是下标0 号数据库
Demo代码
import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.Transaction;
public class RedisKeyDemo {
public static Jedis getJedisByPool() { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxTotal(30); jedisPoolConfig.setMaxIdle(10); JedisPool jedisPool = new JedisPool(jedisPoolConfig, "192.168.06.37", 6379); return jedisPool.getResource(); }
public static void keysMethod(){ Jedis jedis = RedisKeyDemo.getJedisByPool(); jedis.keys("*"); jedis.keys("set?"); jedis.del("set1","aw"); jedis.exists("set1"); jedis.rename("oldKeyName","newKeyName"); jedis.expire("set1",10); jedis.ttl("set1"); jedis.type("set1");
}
public static void dataBase(){ Jedis jedis = RedisKeyDemo.getJedisByPool(); jedis.select(1); jedis.move("hello",1);
jedis.set("sw","1"); Transaction multi = jedis.multi();
jedis.incr("sw");
multi.exec();
jedis.set("a1","jack"); Transaction multi1 = jedis.multi(); jedis.set("a1","tom");
multi.discard(); }
|