當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.hset方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.hset方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.hset方法的具體用法?Java Jedis.hset怎麽用?Java Jedis.hset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.hset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addFirst

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@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;
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:21,代碼來源:JedisSegmentQueueStore.java

示例2: foo

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private static void foo() {

        System.out.println("TEST Jedis ======================================================");
        Jedis jedis = new Jedis(ip, port);
        jedis.set("foo", "bar");

        jedis.get("foo");

        jedis.lpush("lll", "a");
        jedis.lpush("lll", "b");
        jedis.lpush("lll", "c");
        jedis.lpop("lll");
        jedis.lpop("lll");
        jedis.lpop("lll");

        jedis.hset("mmm", "abc", "123");
        jedis.hset("mmm", "def", "456");
        jedis.hgetAll("mmm");

        jedis.close();
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:22,代碼來源:DoTestJedisHookProxy.java

示例3: put

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@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;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:19,代碼來源:JedisCacheManager.java

示例4: push

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public void push(Request request, ISpider spider) {
       Jedis jedis = pool.getResource();
       if (Const.HttpMethod.POST == request.getMethod()
			|| !isDuplicate(request, spider)) {
		log.debug("push to queue {}", request.getUrl());
		 try {
	            jedis.rpush(getQueueKey(spider), request.getUrl());
	            String field = DigestUtils.md5Hex(request.getUrl());
	            byte[] data=SerializationUtils.serialize(request);
	            jedis.hset((ITEM_PREFIX + spider.getName()).getBytes(), field.getBytes(), data);
			} finally {
	            jedis.close();
	        }
	}
   }
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:17,代碼來源:RedisScheduler.java

示例5: hsetString

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void hsetString(String key, String field, String value, int seconds) {
	Jedis jedis = null;
	boolean success = true;
	try {
		jedis = jedisPool.getResource();
		if (jedis == null) {
			success = false;
			return;
		}
		jedis.hset(key, field, value);
		if (seconds >= 0) {
			jedis.expire(key, seconds);
		}
	} catch (Exception e) {
		success = false;
		releaseBrokenReidsSource(jedis, key, "hsetString", e, true);
	} finally {
		releaseReidsSource(success, jedis);
	}
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,代碼來源:RedisService.java

示例6: setRedisData

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 向redis中存入數據
 *
 * @param key    鍵值
 * @param object 數據
 * @return boolean
 */
public <T> boolean setRedisData(String key, String fieldName, T object, int seconds) {
    Jedis jedis = null;
    try {
        jedis = getConnect();
        jedis.hset(key.getBytes(), fieldName.getBytes(), ConvertUtil.serialize(object));
        if (seconds > 0)
            jedis.expire(key.getBytes(), seconds);
    } catch (Exception e) {
        logger.error("redis setRedisData data failed!", e);
        return false;
    } finally {
        close(jedis);
    }
    return true;
}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:23,代碼來源:RedisUtil.java

示例7: addLast

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public boolean addLast(String queueID, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    remove(queueID, e.getKey());
    Jedis jedis = jedisPool.getResource();
    try {
        jedis.rpush(makePoolQueueKey(queueID), e.getKey());
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
    return true;
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:17,代碼來源:JedisQueueStore.java

示例8: hset

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Void hset(String cacheKey, String fieldKey, String value) {
  Jedis jedis = null;
  try {
    jedis = redisProvider.get();
    jedis.hset(cacheKey, fieldKey, value);
  } catch (Exception e) {
    logger.error("{}", kvp("op", "hset",
        "key", cacheKey,
        "field", fieldKey,
        "data", "[" + value + "]",
        "err", "[" + e.getMessage() + "]"), e);
  } finally {
    redisProvider.closeSafely(jedis);
  }
  return null;
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:17,代碼來源:RedisCache.java

示例9: setVByMap

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 
 * @param mapkey map
 * @param key	 map裏的key
 * @param value   map裏的value
 */
public  void setVByMap(String mapkey,String key ,Object value) throws Exception {
	Jedis jds = null;
	try {
		jds = getJedis();
		jds.select(0);
		byte[] svalue = SerializeUtil.serialize(value);
		jds.hset(mapkey.getBytes(), key.getBytes(),svalue);
       } catch (Exception e) {
       	throw e;
       } finally {
       	if(jds != null)
		{
			jds.close();
		}
       }
	
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:24,代碼來源:RedisManager.java

示例10: hset

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void hset(String mapName, String key, String value) {
	Jedis jedis = null;
	try {
		jedis = get();
		if (jedis == null)
			return;
		jedis.hset(mapName, key, value);
		pool.returnResource(jedis);
	} catch (Exception e) {
		pool.returnBrokenResource(jedis);
	}
}
 
開發者ID:x7-framework,項目名稱:x7,代碼行數:13,代碼來源:JedisConnector_Persistence.java

示例11: hset

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@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;
}
 
開發者ID:mmdsyl,項目名稱:BLOG-Microservice,代碼行數:8,代碼來源:JedisClientPool.java

示例12: deferExpired

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private void deferExpired() {
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        boolean isBroken = false;
        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;//  如果服務器端已同步數據,隻需寫入單台機器
                }
            } catch (JedisConnectionException e){
                isBroken = true;
            } finally {
                if(isBroken){
                    jedisPool.returnBrokenResource(jedis);
                } else {
                    jedisPool.returnResource(jedis);
                }
            }
        } catch (Throwable t) {
            logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
        }
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:36,代碼來源:RedisRegistry.java

示例13: pushWhenNoDuplicate

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
protected void pushWhenNoDuplicate(Request request) {

    Jedis jedis = pool.getResource();
    try {
        jedis.rpush(getQueueKey(request.getSpiderName()), request.getUrl());
        String field = DigestUtils.shaHex(request.getUrl());
        String value = JSON.toJSONString(request);
        jedis.hset((ITEM_PREFIX + request.getUrl()), field, value);
    } finally {
        jedis.close();
    }

}
 
開發者ID:fengzhizi715,項目名稱:NetDiscovery,代碼行數:15,代碼來源:RedisQueue.java

示例14: doRegister

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public void doRegister(NURL nurl) {
    String key = toCategoryPath(nurl);
    String value = nurl.toFullString();
    String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
    boolean success = false;
    MregException exception = null;
    for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
        JedisPool jedisPool = entry.getValue();
        try {
            Jedis jedis = jedisPool.getResource();
            try {
                jedis.hset(key, value, expire);
                jedis.publish(key, Consts.REGISTER);
                success = true;
                if (! replicate) {
                    break; //  如果服務器端已同步數據,隻需寫入單台機器
                }
            } catch (JedisConnectionException e){
            	logger.error("Jedis Connection Exception", e);
            } finally {
            	if(jedis != null){
                	jedis.close();
                }
            }
        } catch (Throwable t) {
            exception = new MregException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + nurl + ", cause: " + t.getMessage(), t);
        }
    }
    if (exception != null) {
        if (success) {
            logger.warn(exception.getMessage(), exception);
        } else {
            throw exception;
        }
    }
}
 
開發者ID:yu120,項目名稱:coon,代碼行數:38,代碼來源:RedisMreg.java

示例15: registerServer

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private void registerServer()
{
    if (serverRegistered)
        return;

    log("Trying to register server to the proxy");
    //now done by hydro
    try
    {
        String bungeename = getServerName();

        Jedis rb_jedis = databaseConnector.getBungeeResource();
        rb_jedis.hset("servers", bungeename, this.getServer().getIp() + ":" + this.getServer().getPort());
        rb_jedis.close();


        api.getPubSub().send("servers", "heartbeat " + bungeename + " " + this.getServer().getIp() + " " + this.getServer().getPort());

        getExecutor().scheduleAtFixedRate(() -> {
            try {
                Jedis jedis = databaseConnector.getBungeeResource();
                jedis.hset("servers", bungeename, getServer().getIp() + ":" + getServer().getPort());
                jedis.close();

                api.getPubSub().send("servers", "heartbeat " + getServerName() + " " + getServer().getIp() + " " + getServer().getPort());
            }catch (Exception e)
            {
                e.printStackTrace();
            }
        }, 30, 20, TimeUnit.SECONDS);
    } catch (Exception ignore)
    {
        ignore.printStackTrace();
        return;
    }

    serverRegistered = true;
}
 
開發者ID:SamaGames,項目名稱:SamaGamesCore,代碼行數:39,代碼來源:APIPlugin.java


注:本文中的redis.clients.jedis.Jedis.hset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。