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

The following examples show how to use redis.clients.jedis.Jedis#hset() . 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: JedisScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addFirst(String queueID, ResourceItem e) {
    Jedis jedis = null;
    if (!lockQueue(queueID)) {
        return false;
    }
    try {
        remove(queueID, e.getKey());
        jedis = jedisPool.getResource();
        jedis.lpush(makePoolQueueKey(queueID), e.getKey());
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
    return true;
}
 
Example 2
Source File: JedisCacheManager.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
@Override
public V put(K key, V value) throws CacheException {
	if (key == null){
		return null;
	}
	
	Jedis jedis = null;
	try {
		jedis = JedisUtils.getResource();
		jedis.hset(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key), JedisUtils.toBytes(value));
		logger.debug("put {} {} = {}", cacheKeyName, key, value);
	} catch (Exception e) {
		logger.error("put {} {}", cacheKeyName, key, e);
	} finally {
		JedisUtils.returnResource(jedis);
	}
	return value;
}
 
Example 3
Source File: JedisCacheManager.java    From easyweb with Apache License 2.0 6 votes vote down vote up
@Override
public V put(K key, V value) throws CacheException {
	if (key == null){
		return null;
	}
	
	Jedis jedis = null;
	try {
		jedis = JedisUtils.getResource();
		jedis.hset(JedisUtils.getBytesKey(cacheKeyName), JedisUtils.getBytesKey(key), JedisUtils.toBytes(value));
		logger.debug("put {} {} = {}", cacheKeyName, key, value);
	} catch (Exception e) {
		logger.error("put {} {}", cacheKeyName, key, e);
	} finally {
		JedisUtils.returnResource(jedis);
	}
	return value;
}
 
Example 4
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addFirst(String queueID, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        remove(queueID, e.getKey());
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
        String sliceID = jedis.lpop(makeSliceQueueKey(queueID));
        if (isNil(sliceID)) {
            sliceID = "1";
        }
        jedis.lpush(makeSliceQueueKey(queueID), sliceID);
        jedis.lpush(makePoolQueueKey(queueID, sliceID), e.getKey());
    } finally {
        unLockQueue(queueID);
    }
    return true;
}
 
Example 5
Source File: WispKvStoreCodisKvImpl.java    From wisp with Apache License 2.0 6 votes vote down vote up
/**
 * @param tableId
 * @param key
 * @param value
 *
 * @throws WispProcessorException
 */
@Override
public void put(String tableId, String key, String value) throws WispProcessorException {

    Jedis jedis = null;
    try {

        jedis = jedisPool.getResource();

        String hKey = redisPrefix + tableId;
        jedis.hset(hKey, key, value);

    } catch (Exception e) {

        throw new WispProcessorException(e);
    } finally {

        if (jedis != null) {
            jedis.close();
        }
    }

}
 
Example 6
Source File: RedisLockCoordinator.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
private void checkActiveNode(){
	Jedis redisClient = getRedisClient();
	try {
		long currentTime = System.currentTimeMillis();
		Map<String, String> map = redisClient.hgetAll(REDIS_LOCK_ACTIVE_NODES_KEY);
		Iterator<Entry<String, String>> iterator = map.entrySet().iterator();
		while(iterator.hasNext()){
			Entry<String, String> entry = iterator.next();
			if(currentTime - Long.parseLong(entry.getValue()) > HEALTH_CHECK_PERIOD){
				redisClient.hdel(REDIS_LOCK_ACTIVE_NODES_KEY, entry.getKey());
			}else{
				redisClient.hset(REDIS_LOCK_ACTIVE_NODES_KEY, entry.getKey(), String.valueOf(currentTime));
			}
		}
		if(!map.containsKey(EVENT_NODE_ID)){
			redisClient.hset(REDIS_LOCK_ACTIVE_NODES_KEY, EVENT_NODE_ID, String.valueOf(currentTime));
		}
	} finally {
		release(redisClient);
	}
}
 
Example 7
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addLast(String queueID, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        remove(queueID, e.getKey());
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
        String sliceID = jedis.rpop(makeSliceQueueKey(queueID));
        if (isNil(sliceID)) {
            sliceID = "1";
        }
        jedis.rpush(makeSliceQueueKey(queueID), sliceID);
        jedis.rpush(makePoolQueueKey(queueID, sliceID), e.getKey());
    } finally {
        unLockQueue(queueID);
    }
    return true;
}
 
Example 8
Source File: RedisCacheProvider.java    From xiaoyaoji with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void put(String token, String key, Object data, int expires) {
    synchronized (this) {
        Jedis jedis = null;
        try {
            String json = JSON.toJSONString(data);
            jedis = pool.getResource();
            jedis.hset(token, key, json);
            jedis.expire(token, expires);
        } finally {
            if (jedis != null)
                jedis.close();
        }
    }
}
 
Example 9
Source File: JedisUtil.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 设置map
 *
 * @param key
 * @param field
 * @param value
 */
public static void hset(String key, Object field, Object value) {
    Jedis jedis = null;
    try {
        jedis = getResource();
        jedis.hset(getBytesKey(key), getBytesKey(field), getBytesKey(value));
    } finally {
        close(jedis);
    }
}
 
Example 10
Source File: RedisRegistry.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                for (URL url : new HashSet<URL>(getRegistered())) {
                    if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                        String key = toCategoryPath(url);
                        if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) {
                            jedis.publish(key, Constants.REGISTER);
                        }
                    }
                }
                if (admin) {
                    clean(jedis);
                }
                if (!replicate) {
                    break;//  If the server side has synchronized data, just write a single machine
                }
            } finally {
                jedis.close();
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
Example 11
Source File: JedisClientPool.java    From express-ssm with Apache License 2.0 5 votes vote down vote up
@Override
public Long hset(String key, String field, String value) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.hset(key, field, value);
    jedis.close();
    return result;
}
 
Example 12
Source File: JedisClientPool.java    From blog-sample with Apache License 2.0 5 votes vote down vote up
@Override
public Long hset(String key, String field, String value) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.hset(key, field, value);
    jedis.close();
    return result;
}
 
Example 13
Source File: RedisClient.java    From star-zone with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key给field设置指定的值,如果key不存在,则先创建
 * </p>
 * 
 * @param key
 * @param field
 *            字段
 * @param value
 * @return 如果存在返回0 异常返回null
 */
public Long hset(String key, String field, String value) {
	Jedis jedis = null;
	Long res = null;
	try {
		jedis = jedisPool.getResource();
		res = jedis.hset(key, field, value);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		closeJedis(jedis);
	}
	return res;
}
 
Example 14
Source File: JedisForbiddenQueueStore.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@Override
public void add(String queueID, ResourceItem resourceItem) {
    if (!lockQueue(queueID)) {
        throw new RuntimeException("failed to acquire redis lock");
    }
    Jedis jedis = jedisPool.getResource();
    try {
        jedis.hset(makeDataKey(queueID), resourceItem.getKey(), JSONObject.toJSONString(resourceItem));
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 15
Source File: RedisManager.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
public Long hset(String key,String filed,String value){
    Long length=null;
    Jedis jedis = pool.getResource();
    try {
        length=jedis.hset(key, filed,value);
    } finally {
        pool.returnResource(jedis);
    }
    return length;
}
 
Example 16
Source File: ShardedJedisCacheManager.java    From AutoLoadCache with Apache License 2.0 4 votes vote down vote up
@Override
public void hset(byte[] key, byte[] field, byte[] value) {
    Jedis jedis = shardedJedis.getShard(key);
    jedis.hset(key, field, value);
}
 
Example 17
Source File: JedisUtil.java    From Project with Apache License 2.0 4 votes vote down vote up
public long hset(String key, String fieid, byte[] value) {
	Jedis jedis = getJedis();
	long s = jedis.hset(key.getBytes(), fieid.getBytes(), value);
	jedis.close();
	return s;
}
 
Example 18
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 添加一个对应关系
 * 
 * @param  key
 * @param  fieid
 * @param  value
 * @return 状态码 1成功,0失败,fieid已存在将更新,也返回0
 **/
public long hset(String key, String fieid, String value) {
	Jedis jedis = getJedis();
	long s = jedis.hset(key, fieid, value);
	jedis.close();
	return s;
}
 
Example 19
Source File: RedisClient.java    From springboot-learn with MIT License 2 votes vote down vote up
/**
 * 哈希 添加
 *
 * @param key
 * @param hashKey
 * @param value
 */
public void hmSet(String key, String hashKey, String value) {
    Jedis jedis = jedisPool.getResource();
    jedis.hset(key, hashKey, value);
}
 
Example 20
Source File: RedisHashBackedPropertySupport.java    From tomcat8-redis-sessions with The Unlicense 2 votes vote down vote up
/**
 * Stores the property into Redis.
 *
 * @param jedis The client; never {@code null}
 * @param value The value to store; never {@code null}
 */
@Override
protected void doStore(Jedis jedis, String value) throws Exception {
  jedis.hset(redisKey, hashKey, value);
}