本文整理了Java中redis.clients.jedis.Jedis.decr()
方法的一些代码示例,展示了Jedis.decr()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.decr()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:decr
[英]Decrement the number stored at key by one. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" before to perform the decrement operation.
INCR commands are limited to 64 bit signed integers.
Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.
Time complexity: O(1)
[中]将键上存储的数字减少一。如果键不存在或包含错误类型的值,请在执行递减操作之前将键设置为值“0”。
INCR命令限制为64位有符号整数。
注意:这实际上是一个字符串操作,也就是说,在Redis中没有“整数”类型。只需将存储在密钥处的字符串解析为一个以10为基数的64位有符号整数,递增,然后转换回字符串即可。
时间复杂度:O(1)
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.decr(key);
}
}.run(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.decr(key);
}
}.runBinary(key);
代码示例来源:origin: yu199195/hmily
@Override
public Long decr(final String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.decr(key);
}
}
代码示例来源:origin: yu199195/Raincat
@Override
public Long decr(final String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.decr(key);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Long decr(final String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.decr(key);
}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long decr(byte[] key) {
Jedis j = getShard(key);
return j.decr(key);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long decr(String key) {
Jedis j = getShard(key);
return j.decr(key);
}
代码示例来源:origin: yu199195/hmily
@Override
public Long decr(final String key) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.decr(key);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Long decr(final String key) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.decr(key);
}
}
代码示例来源:origin: yu199195/Raincat
@Override
public Long decr(final String key) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.decr(key);
}
}
代码示例来源:origin: shuzheng/zheng
/**
* decr
* @param key
* @return value
*/
public synchronized static Long decr(String key) {
Jedis jedis = getJedis();
if (null == jedis) {
return null;
}
long value = jedis.decr(key);
jedis.close();
return value;
}
代码示例来源:origin: qiurunze123/miaosha
/**
* 减少值
* */
public <T> Long decr(KeyPrefix prefix, String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
//生成真正的key
String realKey = prefix.getPrefix() + key;
return jedis.decr(realKey);
}finally {
returnToPool(jedis);
}
}
代码示例来源:origin: Netflix/conductor
@Override
public Long decr(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.decr(key);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 将 key 中储存的数字值减一。
* 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作。
* 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
* 本操作的值限制在 64 位(bit)有符号数字表示之内。
* 关于递增(increment) / 递减(decrement)操作的更多信息,请参见 INCR 命令。
*/
public Long decr(Object key) {
Jedis jedis = getJedis();
try {
return jedis.decr(keyToBytes(key));
}
finally {close(jedis);}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public Long decr(byte[] key) {
Assert.notNull(key, "Key must not be null!");
try {
if (isPipelined()) {
pipeline(connection.newJedisResult(connection.getRequiredPipeline().decr(key)));
return null;
}
if (isQueueing()) {
transaction(connection.newJedisResult(connection.getRequiredTransaction().decr(key)));
return null;
}
return connection.getJedis().decr(key);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: apache/ignite
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(1, (long)jedis.incr("newKeyIncr"));
Assert.assertEquals(-1, (long)jedis.decr("newKeyDecr"));
Assert.assertEquals(9L, (long)jedis.decr("decrKey1"));
jedis.decr("nonInt");
jedis.decr("outOfRangeDecr1");
jedis.decr("outOfRangeDecr2");
代码示例来源:origin: jwpttcg66/NettyGameServer
/**
* 返回是否成功
* @param key
* @return
*/
public boolean decr(String key){
Jedis jedis = null;
boolean sucess = true;
long result = -1;
try {
jedis = jedisPool.getResource();
jedis.decr(key);
} catch (Exception e) {
sucess = false;
returnBrokenResource(jedis, "decr:"+key, e);
} finally {
if (sucess && jedis != null) {
returnResource(jedis);
}
}
return sucess;
}
代码示例来源:origin: apache/servicemix-bundles
@Override
public Long execute(Jedis connection) {
return connection.decr(key);
}
}.runBinary(key);
代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis
@Override
public Long decr(byte[] key) {
String command = "decr";
return instrumented(command, () -> delegated.decr(key));
}
代码示例来源:origin: com.netflix.conductor/conductor-redis-persistence
@Override
public Long decr(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.decr(key);
} finally {
if (jedis != null)
jedis.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!