1、测试Redis list数据结构
@Test public void testRedisList(){ JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(10); config.setMaxTotal(100); JedisPool jedisPool = new JedisPool(config,"localhost",6379); Jedis jedis = null; try{ jedis = jedisPool.getResource(); jedis.lpush("name","zhoujie"); jedis.lpush("name","30"); jedis.lpush("name","9500.00"); jedis.lpush("name","40000.00"); List<String> list = jedis.lrange("name",0,-1); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } }catch ( Exception e ){ e.printStackTrace(); }finally { jedisPool.close(); jedis.close(); } }
2、测试redis中所有key的的获取
/** * 获得redis中所有的key */ @Test public void testRedisKeys(){ JedisPoolConfig config = new JedisPoolConfig(); config.setMaxIdle(10); config.setMaxTotal(100); JedisPool jedisPool = new JedisPool(config,"localhost",6379); Jedis jedis = null; try{ jedis = jedisPool.getResource(); jedis.lpush("name","zhoujie"); jedis.lpush("name1","30"); jedis.lpush("name2","9500.00"); jedis.lpush("name3","40000.00"); //获得所有的keys Set<String> keys = ; Iterator<String> it = ; while (it.hasNext()){ String key = it.next(); System.out.println(key); } }catch ( Exception e ){ e.printStackTrace(); }finally { jedisPool.close(); jedis.close(); } }