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

The following examples show how to use redis.clients.jedis.Jedis#hmget() . 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: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 通过key 和 fields 获取指定的value 如果没有对应的value则返回null
 * </p>
 *
 * @param key
 * @param fields
 *            可以使 一个String 也可以是 String数组
 * @return
 */
public List<String> hmget(String key, int indexdb, String... fields) {
    Jedis jedis = null;
    List<String> res = null;
    try {
        jedis = jedisPool.getResource();
        jedis.select(indexdb);
        res = jedis.hmget(key, fields);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 2
Source File: RedisClient.java    From apollo with GNU General Public License v2.0 6 votes vote down vote up
public List<Object> hmGet(String key, String... fields) throws Exception {
    Jedis jedis = null;
    try {
        jedis = this.jedisPool.getResource();
        List<byte[]> hmget = jedis.hmget(SafeEncoder.encode(key), encodeArray(fields));
        logger.info("hmGet key:" + key + ", fields:" + Arrays.toString(fields));
        if (CollectionUtils.isEmpty(hmget)) {
            return new ArrayList<Object>(1);
        } else {
            List<Object> ret = new ArrayList<Object>(hmget.size());
            for (byte[] bb : hmget) {
                ret.add(deserialize(bb));
            }
            return ret;
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        this.jedisPool.returnBrokenResource(jedis);
        throw e;
    } finally {
        if (jedis != null) {
            this.jedisPool.returnResource(jedis);
        }
    }
}
 
Example 3
Source File: RedisClient.java    From apollo with GNU General Public License v2.0 6 votes vote down vote up
public List<String> hmGetByStringSerializer(String key, String... fields) throws Exception {
    Jedis jedis = null;
    try {
        jedis = this.jedisPool.getResource();
        List<String> hmget = jedis.hmget(key, fields);
        logger.info("hmGet key:" + key + ", fields:" + Arrays.toString(fields));
        if (CollectionUtils.isEmpty(hmget)) {
            return new ArrayList<String>(1);
        } else {
            return hmget;
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        this.jedisPool.returnBrokenResource(jedis);
        throw e;
    } finally {
        if (jedis != null) {
            this.jedisPool.returnResource(jedis);
        }
    }
}
 
Example 4
Source File: JedisUtil.java    From Project with Apache License 2.0 5 votes vote down vote up
/**
 * 根据多个key,获取对应的value,返回List,如果指定的key不存在,List对应位置为null
 * 
 * @param  key
 * @param  fieids 存储位置
 * @return List<String>
 */
public List<String> hmget(String key, String... fieids) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	List<String> list = sjedis.hmget(key, fieids);
	sjedis.close();
	return list;
}
 
Example 5
Source File: JedisUtil.java    From Project with Apache License 2.0 5 votes vote down vote up
public List<byte[]> hmget(byte[] key, byte[]... fieids) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	List<byte[]> list = sjedis.hmget(key, fieids);
	sjedis.close();
	return list;
}
 
Example 6
Source File: RedisClient.java    From Mykit with Apache License 2.0 5 votes vote down vote up
public List<String> hmget(String key, String... fields) {
	Jedis client = jedisPool.getResource();
	try {
		return client.hmget(key, fields);
	} finally {
		// 向连接池“归还”资源
		jedisPool.returnResourceObject(client);
	}
}
 
Example 7
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> hmget(String key, String... fields) {
    Jedis jedis = null;
    List<String> res = null;
    try {
        jedis = pool.getResource();
        res = jedis.hmget(key, fields);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 8
Source File: JedisTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test(expected = JedisConnectionException.class)
public void timeoutConnection() throws Exception {
  jedis = new Jedis("localhost", 6379, 15000);
  jedis.auth("foobared");
  jedis.configSet("timeout", "1");
  Thread.sleep(2000);
  jedis.hmget("foobar", "foo");
}
 
Example 9
Source File: JedisTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test(expected = JedisConnectionException.class)
public void timeoutConnectionWithURI() throws Exception {
  jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"), 15000);
  jedis.configSet("timeout", "1");
  Thread.sleep(2000);
  jedis.hmget("foobar", "foo");
}
 
Example 10
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 5 votes vote down vote up
public List<byte[]> hmget(byte[] key, byte[]... fieids) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	List<byte[]> list = sjedis.hmget(key, fieids);
	returnJedis(sjedis);
	return list;
}
 
Example 11
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private List<String> hmget0(Jedis j, String key, String... fields) {
	return j.hmget(key, fields);
}
 
Example 12
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 根据多个key,获取对应的value,返回List,如果指定的key不存在,List对应位置为null
 * 
 * @param String
 *            key
 * @param String
 *            ... fieids 存储位置
 * @return List<String>
 * */
public List<String> hmget(String key, String... fieids) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	List<String> list = sjedis.hmget(key, fieids);
	returnJedis(sjedis);
	return list;
}