redis.clients.jedis.Jedis.incrBy()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(263)

本文整理了Java中redis.clients.jedis.Jedis.incrBy()方法的一些代码示例,展示了Jedis.incrBy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.incrBy()方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:incrBy

Jedis.incrBy介绍

[英]INCRBY work just like #incr(String) but instead to increment by 1 the increment is integer.

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)
[中]INCRBY的工作原理与#incr(String)类似,但如果按1递增,则增量为整数。
INCR命令限制为64位有符号整数。
注意:这实际上是一个字符串操作,也就是说,在Redis中没有“整数”类型。只需将存储在密钥处的字符串解析为一个以10为基数的64位有符号整数,递增,然后转换回字符串即可。
时间复杂度:O(1)

代码示例

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.incrBy(key, integer);
 }
}.runBinary(key);

代码示例来源:origin: sohutv/cachecloud

@Override
 public Long execute(Jedis connection) {
  return connection.incrBy(key, integer);
 }
}.run(key);

代码示例来源:origin: sohutv/cachecloud

@Override
public Long incrBy(String key, long integer) {
 Jedis j = getShard(key);
 return j.incrBy(key, integer);
}

代码示例来源:origin: sohutv/cachecloud

@Override
public Long incrBy(byte[] key, long integer) {
 Jedis j = getShard(key);
 return j.incrBy(key, integer);
}

代码示例来源:origin: Netflix/conductor

@Override
public Long incrBy(String key, long integer) {
 Jedis jedis = null;
  try {
   jedis = jedisPool.getResource();
   return jedis.incrBy(key, integer);
  } finally {
   if (jedis != null)
    jedis.close();
  }
}

代码示例来源:origin: jfinal/jfinal

/**
 * 将 key 所储存的值加上增量 increment 。
 * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCRBY 命令。
 * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。
 * 本操作的值限制在 64 位(bit)有符号数字表示之内。
 * 关于递增(increment) / 递减(decrement)操作的更多信息,参见 INCR 命令。 
 */
public Long incrBy(Object key, long longValue) {
  Jedis jedis = getJedis();
  try {
    return jedis.incrBy(keyToBytes(key), longValue);
  }
  finally {close(jedis);}
}

代码示例来源:origin: apache/ignite

public void testIncrDecrBy() throws Exception {
  try (Jedis jedis = pool.getResource()) {
    Assert.assertEquals(2, (long)jedis.incrBy("newKeyIncrBy", 2));
    Assert.assertEquals(-2, (long)jedis.decrBy("newKeyDecrBy", 2));
    Assert.assertEquals(11L, (long)jedis.incrBy("incrDecrKeyBy", 10));
      jedis.incrBy("outOfRangeIncrBy", Long.MAX_VALUE);
      jedis.incrBy("outOfRangeIncBy2", Long.MAX_VALUE);

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Long incrBy(byte[] key, long value) {
  Assert.notNull(key, "Key must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().incrBy(key, value)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().incrBy(key, value)));
      return null;
    }
    return connection.getJedis().incrBy(key, value);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: jwpttcg66/NettyGameServer

public Long incrBy(String key, long value){
  Jedis jedis = null;
  boolean sucess = true;
  long result = -1;
  try {
    jedis = jedisPool.getResource();
    result = jedis.incrBy(key, value);
  } catch (Exception e) {
    sucess = false;
    returnBrokenResource(jedis, "incrBy:"+key, e);
  } finally {
    if (sucess && jedis != null) {
      returnResource(jedis);
    }
  }
  return result;
}

代码示例来源:origin: yrain/smart-cache

@Override
  Long doInJedis(Jedis jedis) {
    return jedis.incrBy(key, value);
  }
});

代码示例来源:origin: apache/servicemix-bundles

@Override
 public Long execute(Jedis connection) {
  return connection.incrBy(key, increment);
 }
}.run(key);

代码示例来源:origin: apache/servicemix-bundles

@Override
 public Long execute(Jedis connection) {
  return connection.incrBy(key, increment);
 }
}.runBinary(key);

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

@Override
protected long incrementStorageSize(final long size) {
  return redisExecutor.execute((RedisCallable<Long>) jedis -> {
    Long incremented = jedis.incrBy(sizeKey, size);
    if (log.isDebugEnabled()) {
      log.debug(String.format("Incremented Redis key %s to %d", sizeKey, incremented));
    }
    return incremented;
  });
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public Long incrBy(String key, long integer) {
 String command = "incrBy";
 return instrumented(command, () -> delegated.incrBy(key, integer));
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public Long incrBy(byte[] key, long integer) {
 String command = "incrBy";
 return instrumented(command, () -> delegated.incrBy(key, integer));
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Long incrBy(final String key, final long increment) {
 Jedis j = getShard(key);
 return j.incrBy(key, increment);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Long incrBy(final byte[] key, final long increment) {
 Jedis j = getShard(key);
 return j.incrBy(key, increment);
}

代码示例来源:origin: pyloque/captain

public long globalVersion() {
  Holder<Long> version = new Holder<Long>();
  this.redis.execute(jedis -> {
    version.set(jedis.incrBy(globalVersionKey, 0));
  });
  return version.value();
}

代码示例来源:origin: pyloque/captain

public long globalVersion() {
  Holder<Long> version = new Holder<Long>();
  redis.execute(jedis -> {
    version.set(jedis.incrBy(globalVersionKey, 0));
  });
  return version.value();
}

代码示例来源:origin: pyloque/captain

public long version(String name) {
  Holder<Long> version = new Holder<Long>();
  this.redis.execute(jedis -> {
    version.set(jedis.incrBy(keyForVersion(name), 0));
  });
  return version.value();
}

相关文章

Jedis类方法