本文整理匯總了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;
}
示例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();
}
示例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;
}
示例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();
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
示例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();
}
}
示例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;
}
}
}
示例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;
}