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

The following examples show how to use redis.clients.jedis.Jedis#hget() . 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: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem get(String queueID, String key) {
    if (!lockQueue(queueID)) {
        return null;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        String dataJson = jedis.hget(makeDataKey(queueID), key);
        if (isNil(dataJson)) {
            return null;
        }
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        unLockQueue(queueID);
    }
}
 
Example 2
Source File: JedisForbiddenQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem remove(String queueID, String key) {
    if (!lockQueue(queueID)) {
        throw new RuntimeException("failed to acquire redis lock");
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String data = jedis.hget(makeDataKey(queueID), key);
        if (StringUtils.isBlank(data)) {
            return null;
        }
        jedis.hdel(makeDataKey(queueID), key);
        return JSONObject.toJavaObject(JSONObject.parseObject(data), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 3
Source File: JedisBlockingQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem poll(String queueID) {
    Jedis jedis = jedisPool.getResource();
    try {
        Set<String> zrange = jedis.zrange(makePoolQueueKey(queueID), 0, 1);
        if (zrange.size() == 0) {
            return null;
        }
        String key = zrange.iterator().next();
        String data = jedis.hget(makeDataKey(queueID), key);
        if (StringUtils.isBlank(data)) {
            VSCrawlerMonitor.recordOne(queueID + "_find_meta_data_failed");
            return null;
        }
        return JSONObject.toJavaObject(JSON.parseObject(data), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
    }
}
 
Example 4
Source File: InfoDaoImpl.java    From dynamic-show with Apache License 2.0 6 votes vote down vote up
@Override
public List<Map<String, String>> getPV(String dateStr) {
    Jedis jedis = JedisUtil.getJedis();
    List<Map<String, String>> pvData = new ArrayList<>();
    String pvKey = null;
    String result = null;
    Map<String, String> map = null;
    for(String province : ProvinceUtil.provinceMap.keySet()) {
        pvKey = province + "_pv";
        result = jedis.hget(pvKey, dateStr);
        if(result == null) {
            result = "0";
        }
        map = new HashMap<>();
        map.put("name", ProvinceUtil.provinceMap.get(province));
        map.put("value", result);
        pvData.add(map);
    }

    // 释放jedis资源
    JedisUtil.returnJedis(jedis);

    return pvData;
}
 
Example 5
Source File: JedisScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem pop(String queueID) {
    if (!lockQueue(queueID)) {
        return null;
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String firstResourceKey = jedis.lpop(makePoolQueueKey(queueID));
        if (isNil(firstResourceKey)) {
            return null;
        }
        String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey);
        if (isNil(dataJson)) {
            throw new IllegalStateException("this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey);
        }
        jedis.hdel(makeDataKey(queueID), firstResourceKey);
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 6
Source File: PasswordDB.java    From VileBot with MIT License 6 votes vote down vote up
/**
 * Checks the validity of a password for a user
 * 
 * @param username user to check the password of
 * @param password the password to check
 * @return true iff the given password is valid
 */
public static boolean isValidPassword( String username, String password )
{
    String storedHash;

    Jedis jedis = pool.getResource();
    try
    {
        storedHash = jedis.hget( keyOfPassHash, username );
    }
    finally
    {
        pool.returnResource( jedis );
    }

    String hash = hash( password, getSalt( username ) );

    return hash.equals( storedHash );
}
 
Example 7
Source File: JedisScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem get(String queueID, String key) {
    if (!lockQueue(queueID)) {
        return null;
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String dataJson = jedis.hget(makeDataKey(queueID), key);
        if (isNil(dataJson)) {
            return null;
        }
        return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 8
Source File: WispKvStoreCodisKvImpl.java    From wisp with Apache License 2.0 6 votes vote down vote up
/**
 * @param tableId
 * @param key
 *
 * @return
 *
 * @throws WispProcessorException
 */
@Override
public String get(String tableId, String key) throws WispProcessorException {

    Jedis jedis = null;
    try {

        LOGGER.debug("jedis get: {} {}", tableId, key);

        jedis = jedisPool.getResource();

        String hKey = redisPrefix + tableId;
        return jedis.hget(hKey, key);

    } catch (Exception e) {

        throw new WispProcessorException(e);
    } finally {

        if (jedis != null) {
            jedis.close();
        }
    }
}
 
Example 9
Source File: JedisBlockingQueueStore.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@Override
public ResourceItem get(String queueID, String key) {
    Jedis jedis = jedisPool.getResource();
    try {
        String data = jedis.hget(makeDataKey(queueID), key);
        if (StringUtils.isBlank(data)) {
            VSCrawlerMonitor.recordOne(queueID + "_find_meta_data_failed");
            return null;
        }
        return JSONObject.toJavaObject(JSON.parseObject(data), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
    }
}
 
Example 10
Source File: JedisClientPool.java    From blog-sample with Apache License 2.0 5 votes vote down vote up
@Override
public String hget(String key, String field) {
    Jedis jedis = jedisPool.getResource();
    String result = jedis.hget(key, field);
    jedis.close();
    return result;
}
 
Example 11
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 5 votes vote down vote up
public byte[] hget(byte[] key, byte[] fieid) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	byte[] s = sjedis.hget(key, fieid);
	returnJedis(sjedis);
	return s;
}
 
Example 12
Source File: RedisClient.java    From star-zone with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key 和 field 获取指定的 value
 * </p>
 * 
 * @param key
 * @param field
 * @return 没有返回null
 */
public String hget(String key, String field) {
	Jedis jedis = null;
	String res = null;
	try {
		jedis = jedisPool.getResource();
		res = jedis.hget(key, field);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		closeJedis(jedis);
	}
	return res;
}
 
Example 13
Source File: RedisClient.java    From Mykit with Apache License 2.0 5 votes vote down vote up
public <T> T hgetObject(String key, String field, Class<T> cls) {
	Jedis client = jedisPool.getResource();
	try {
		String value = client.hget(key, field);
		return (T) JsonUtils.jsonToBean(value, cls);
	} finally {
		// 向连接池“归还”资源
		jedisPool.returnResourceObject(client);
	}

}
 
Example 14
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key 和 field 获取指定的 value
 * </p>
 *
 * @param key
 * @param field
 * @return 没有返回null
 */
public String hget(String key, String field) {
    Jedis jedis = null;
    String res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.hget(key, field);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 15
Source File: JedisClientPool.java    From BigDataPlatform with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String hget(String key, String field) {
	Jedis jedis = jedisPool.getResource();
	String result = jedis.hget(key, field);
	jedis.close();
	return result;
}
 
Example 16
Source File: RedisPriorityScheduler.java    From webmagic with Apache License 2.0 5 votes vote down vote up
private Request getExtrasInItem(Jedis jedis, String url, Task task)
{
    String key      = getItemKey(task);
    String field    = DigestUtils.shaHex(url);
    byte[] bytes    = jedis.hget(key.getBytes(), field.getBytes());
    if(bytes != null)
        return JSON.parseObject(new String(bytes), Request.class);
    return new Request(url);
}
 
Example 17
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean update(String queueID, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        String dataJson = jedis.hget(makeDataKey(queueID), e.getKey());
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
        return !isNil(dataJson);
    } finally {
        unLockQueue(queueID);
    }
}
 
Example 18
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private String hget0(Jedis j, String key, String field) {
	return j.hget(key, field);
}
 
Example 19
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 返回hash中指定存储位置的值
 * 
 * @param key
 * @param  fieid 存储的名字
 * @return 存储对应的值
 */
public String hget(String key, String fieid) {
	Jedis sjedis = getJedis();
	String s = sjedis.hget(key, fieid);
	sjedis.close();
	return s;
}
 
Example 20
Source File: RedisClient.java    From springboot-learn with MIT License 2 votes vote down vote up
/**
 * 哈希获取数据
 *
 * @param key
 * @param hashKey
 * @return
 */
public Object hmGet(String key, String hashKey) {
    Jedis jedis = jedisPool.getResource();
    return jedis.hget(key, hashKey);
}