本文整理了Java中redis.clients.jedis.Jedis.hset()
方法的一些代码示例,展示了Jedis.hset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.hset()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:hset
[英]Set the specified hash field to the specified value.
If key does not exist, a new key holding a hash is created.
Time complexity: O(1)
[中]将指定的哈希字段设置为指定值。
若密钥不存在,则创建一个包含散列的新密钥。
时间复杂度:O(1)
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.hset(key, field, value);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.hset(key, field, value);
}
}.runBinary(key);
代码示例来源:origin: yu199195/hmily
@Override
public Long hset(final String key, final String item, final String value) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.hset(key, item, value);
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Override
public void put(String key, Object value) {
String jsonValue = gson.toJson(value);
this.jedis.hset(this.cacheName, key, jsonValue);
}
代码示例来源:origin: yu199195/myth
@Override
public Long hset(final String key, final String item, final String value) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.hset(key, item, value);
}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long hset(String key, String field, String value) {
Jedis j = getShard(key);
return j.hset(key, field, value);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long hset(byte[] key, byte[] field, byte[] value) {
Jedis j = getShard(key);
return j.hset(key, field, value);
}
代码示例来源:origin: sohutv/cachecloud
public Long execute(Jedis connection) {
return connection.hset(keyByte, SafeEncoder.encode(field), value);
}
}.runBinary(keyByte);
代码示例来源:origin: yu199195/hmily
@Override
public Long hset(final String key, final String item, final String value) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.hset(key, item, value);
}
}
代码示例来源:origin: caoxinyu/RedisClient
@Override
protected void command() {
jedis.select(db);
jedis.hset(key, field, value);
}
代码示例来源:origin: qiujiayu/AutoLoadCache
@Override
public void hset(byte[] key, byte[] field, byte[] value) {
Jedis jedis = shardedJedis.getShard(key);
jedis.hset(key, field, value);
}
代码示例来源:origin: apache/incubator-dubbo
private void deferExpired() {
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
for (URL url : new HashSet<>(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
}
}
} catch (Throwable t) {
logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
}
}
}
代码示例来源:origin: apache/incubator-dubbo
private void deferExpired() {
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
for (URL url : new HashSet<>(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
}
}
} catch (Throwable t) {
logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doRegister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
boolean success = false;
RpcException exception = null;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
jedis.hset(key, value, expire);
jedis.publish(key, Constants.REGISTER);
success = true;
if (!replicate) {
break; // If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
exception = new RpcException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doRegister(URL url) {
String key = toCategoryPath(url);
String value = url.toFullString();
String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
boolean success = false;
RpcException exception = null;
for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
JedisPool jedisPool = entry.getValue();
try {
try (Jedis jedis = jedisPool.getResource()) {
jedis.hset(key, value, expire);
jedis.publish(key, Constants.REGISTER);
success = true;
if (!replicate) {
break; // If the server side has synchronized data, just write a single machine
}
}
} catch (Throwable t) {
exception = new RpcException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
}
}
if (exception != null) {
if (success) {
logger.warn(exception.getMessage(), exception);
} else {
throw exception;
}
}
}
代码示例来源:origin: code4craft/webmagic
private void setExtrasInItem(Jedis jedis,Request request, Task task)
{
if(request.getExtras() != null)
{
String field = DigestUtils.shaHex(request.getUrl());
String value = JSON.toJSONString(request);
jedis.hset(getItemKey(task), field, value);
}
}
代码示例来源:origin: Netflix/conductor
@Override
public Long hset(String key, String field, String value) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.hset(key, field, value);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: code4craft/webmagic
@Override
protected void pushWhenNoDuplicate(Request request, Task task) {
Jedis jedis = pool.getResource();
try {
jedis.rpush(getQueueKey(task), request.getUrl());
if (checkForAdditionalInfo(request)) {
String field = DigestUtils.shaHex(request.getUrl());
String value = JSON.toJSONString(request);
jedis.hset((ITEM_PREFIX + task.getUUID()), field, value);
}
} finally {
jedis.close();
}
}
代码示例来源:origin: signalapp/Signal-Server
public void add(ClientContact contact) {
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isVoice(), contact.isVideo());
try (Jedis jedis = redisPool.getWriteResource()) {
jedis.hset(DIRECTORY_KEY, contact.getToken(), objectMapper.writeValueAsBytes(tokenValue));
} catch (JsonProcessingException e) {
logger.warn("JSON Serialization", e);
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 将哈希表 key 中的域 field 的值设为 value 。
* 如果 key 不存在,一个新的哈希表被创建并进行 HSET 操作。
* 如果域 field 已经存在于哈希表中,旧值将被覆盖。
*/
public Long hset(Object key, Object field, Object value) {
Jedis jedis = getJedis();
try {
return jedis.hset(keyToBytes(key), fieldToBytes(field), valueToBytes(value));
}
finally {close(jedis);}
}
内容来源于网络,如有侵权,请联系作者删除!