本文整理了Java中redis.clients.jedis.Jedis.incr()
方法的一些代码示例,展示了Jedis.incr()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.incr()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:incr
[英]Increment 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 increment 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)
[中]将键上存储的数字增加1。如果键不存在或包含错误类型的值,请在执行增量操作之前将键设置为值“0”。
INCR命令限制为64位有符号整数。
注意:这实际上是一个字符串操作,也就是说,在Redis中没有“整数”类型。只需将存储在密钥处的字符串解析为一个以10为基数的64位有符号整数,递增,然后转换回字符串即可。
时间复杂度:O(1)
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.incr(key);
}
}.runBinary(key);
代码示例来源:origin: sohutv/cachecloud
@Override
public Long execute(Jedis connection) {
return connection.incr(key);
}
}.run(key);
代码示例来源:origin: yu199195/hmily
@Override
public Long incr(final String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.incr(key);
}
}
代码示例来源:origin: yu199195/Raincat
@Override
public Long incr(final String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.incr(key);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Long incr(final String key) {
try (Jedis jedis = jedisPool.getResource()) {
return jedis.incr(key);
}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long incr(byte[] key) {
Jedis j = getShard(key);
return j.incr(key);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Long incr(String key) {
Jedis j = getShard(key);
return j.incr(key);
}
代码示例来源:origin: yu199195/hmily
@Override
public Long incr(final String key) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.incr(key);
}
}
代码示例来源:origin: yu199195/myth
@Override
public Long incr(final String key) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.incr(key);
}
}
代码示例来源:origin: yu199195/Raincat
@Override
public Long incr(final String key) {
try (Jedis jedis = jedisSentinelPool.getResource()) {
return jedis.incr(key);
}
}
代码示例来源:origin: shuzheng/zheng
/**
* incr
* @param key
* @return value
*/
public synchronized static Long incr(String key) {
Jedis jedis = getJedis();
if (null == jedis) {
return null;
}
long value = jedis.incr(key);
jedis.close();
return value;
}
代码示例来源:origin: qiurunze123/miaosha
/**
* 增加值
* */
public <T> Long incr(KeyPrefix prefix, String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
//生成真正的key
String realKey = prefix.getPrefix() + key;
return jedis.incr(realKey);
}finally {
returnToPool(jedis);
}
}
代码示例来源:origin: Netflix/conductor
@Override
public Long incr(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.incr(key);
} finally {
if (jedis != null)
jedis.close();
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 将 key 中储存的数字值增一。
* 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作。
* 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
* 本操作的值限制在 64 位(bit)有符号数字表示之内。
*/
public Long incr(Object key) {
Jedis jedis = getJedis();
try {
return jedis.incr(keyToBytes(key));
}
finally {close(jedis);}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void simpleTest() {
for (int i = 0; i < 3; i++) {
clients[i].incr("somekey");
assertEquals("Each redis instance is separate", "1", clients[i].get("somekey"));
}
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
void step1() {
assertEquals(1, redisPerClass.getJedis().incr("key").longValue());
assertEquals(1, redisPerTest.getJedis().incr("key").longValue());
assertEquals(1, myRedis.getJedis().incr("key").longValue());
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
void step2() {
assertEquals(2, redisPerClass.getJedis().incr("key").longValue());
assertEquals(1, redisPerTest.getJedis().incr("key").longValue());
assertEquals(1, myRedis.getJedis().incr("key").longValue());
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void simpleTest() {
Jedis jedis = new Jedis(getEnvironment().getServiceHost("redis_1", REDIS_PORT), getEnvironment().getServicePort("redis_1", REDIS_PORT));
jedis.incr("test");
jedis.incr("test");
jedis.incr("test");
assertEquals("A redis instance defined in compose can be used in isolation", "3", jedis.get("test"));
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void secondTest() {
// used in manual checking for cleanup in between tests
Jedis jedis = new Jedis(getEnvironment().getServiceHost("redis_1", REDIS_PORT), getEnvironment().getServicePort("redis_1", REDIS_PORT));
jedis.incr("test");
jedis.incr("test");
jedis.incr("test");
assertEquals("Tests use fresh container instances", "3", jedis.get("test"));
// if these end up using the same container one of the test methods will fail.
// However, @Rule creates a separate DockerComposeContainer instance per test, so this just shouldn't happen
}
代码示例来源:origin: apache/ignite
/**
* Test that threads with datastructures commands wasn't deadlocked when PME happens.
*
* @throws Exception If failed.
*/
@Test
public void testAtomicCommandsTopologyChange() throws Exception {
try (Jedis jedis = pool.getResource()) {
int size = grid(0).cachesx().size();
jedis.incr("key1");
// Expect that datastructures cache was created and init PME.
assertTrue("Topology wasn't changed.", grid(0).cachesx().size() > size);
for (int i = 0; i < 1000; i++)
jedis.get("nonExistKey");
}
}
}
内容来源于网络,如有侵权,请联系作者删除!