Java Code Examples for redis.clients.jedis.Jedis#mget()

The following examples show how to use redis.clients.jedis.Jedis#mget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShiroSessionDao.java    From Spring-Shiro-Spark with Apache License 2.0 6 votes vote down vote up
/**
 * 获取当前所有活跃用户
 */
@Override
public Collection<Session> getActiveSessions(){
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        Set<String> keys = jedis.keys(prefix + "*");
        if(CollectionUtils.isEmpty(keys)){
            return null;
        }
        List<String> values = jedis.mget(keys.toArray(new String[keys.size()]));
        return SerializeUtils.deserializeFromStrings(values);
    } catch (Exception e){
        logger.warn("统计Session信息失败", e);
    } finally {
        jedis.close();
    }
    return null;
}
 
Example 2
Source File: JedisApiTest.java    From easyooo-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 最简单的调用方式,
 * 本地1秒钟可设置10000 - 12000次
 */
@Test
@Ignore
public void testNormalApi(){
	List<String> keys = new ArrayList<String>();
	Jedis jedis = new Jedis("localhost");
	long start = System.currentTimeMillis();
	for(int i = 0; i< COUNTER; i++){
		keys.add("n" + i);
		String result = jedis.set("n" + i, "n" + i);
	}
	long end = System.currentTimeMillis();
	logger.info("SET: " + ((end - start) / 1000.0) + " seconds");
	
	start = System.currentTimeMillis();
	List<String> values = jedis.mget(keys.toArray(new String[]{}));
	end = System.currentTimeMillis();
	
	logger.info("MGet: " + ((end - start) / 1000.0) + " seconds");
	jedis.close();
}
 
Example 3
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过批量的key获取批量的value
 * </p>
 *
 * @param keys
 *            string数组 也可以是一个key
 * @return 成功返回value的集合, 失败返回null的集合 ,异常返回空
 */
public List<String> mget(String... keys) {
    Jedis jedis = null;
    List<String> values = null;
    try {
        jedis = jedisPool.getResource();
        values = jedis.mget(keys);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return values;
}
 
Example 4
Source File: JedisUtil.java    From Project with Apache License 2.0 5 votes vote down vote up
/**
 * 批量获取记录,如果指定的key不存在返回List的对应位置将是null
 * 
 * @param  keys
 * @return List<String> 值得集合
 */
public List<String> mget(String... keys) {
	Jedis jedis = getJedis();
	List<String> str = jedis.mget(keys);
	jedis.close();
	return str;
}
 
Example 5
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> mget(String... keys) {
    Jedis jedis = null;
    List<String> values = null;
    try {
        jedis = pool.getResource();
        values = jedis.mget(keys);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return values;
}
 
Example 6
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private List<String> mget0(Jedis j, String... keys) {
	return j.mget(keys);
}
 
Example 7
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 批量获取记录,如果指定的key不存在返回List的对应位置将是null
 * 
 * @param String
 *            keys
 * @return List<String> 值得集合
 * */
public List<String> mget(String... keys) {
	Jedis jedis = getJedis();
	List<String> str = jedis.mget(keys);
	returnJedis(jedis);
	return str;
}