Java Code Examples for redis.clients.jedis.Jedis#incrBy()
The following examples show how to use
redis.clients.jedis.Jedis#incrBy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisUtil.java From scaffold-cloud with MIT License | 6 votes |
/** * 递增数字 * * @param key 键 * @param by 步长 * @return */ public static long incr(String key, long by) { long result = 0; Jedis jedis = null; try { jedis = getResource(); if (by > 0) { result = jedis.incrBy(key, by); } else { result = jedis.incr(key); } } catch (Exception e) { logger.warn("incr key={}, by={}", key, by, e); } finally { close(jedis); } return result; }
Example 2
Source File: RedisContainer.java From bahir-flink with Apache License 2.0 | 6 votes |
@Override public void incrByEx(String key, Long value, Integer ttl) { Jedis jedis = null; try { jedis = getInstance(); jedis.incrBy(key, value); if (ttl != null) { jedis.expire(key, ttl); } } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Cannot send Redis with incrby command with increment {} with ttl {} error message {}", key, value, ttl, e.getMessage()); } throw e; } finally { releaseInstance(jedis); } }
Example 3
Source File: RedisContainer.java From bahir-flink with Apache License 2.0 | 6 votes |
@Override public void incrBy(String key, Long value) { Jedis jedis = null; try { jedis = getInstance(); jedis.incrBy(key, value); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error("Cannot send Redis with incrby command with increment {} error message {}", key, value, e.getMessage()); } throw e; } finally { releaseInstance(jedis); } }
Example 4
Source File: RedisClient.java From apollo with GNU General Public License v2.0 | 6 votes |
public Long incrBy(final String key, final long integer) throws Exception { Long data = null; Jedis jedis = null; try { jedis = this.jedisPool.getResource(); // long begin = System.currentTimeMillis(); data = jedis.incrBy(key, integer); // long end = System.currentTimeMillis(); // LOG.info("getValueFromCache spends: " + (end - begin) + " millionseconds."); } catch (Exception e) { // do jedis.quit() and jedis.disconnect() this.jedisPool.returnBrokenResource(jedis); throw e; } finally { if (jedis != null) { this.jedisPool.returnResource(jedis); } } return data; }
Example 5
Source File: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
/** * <p> * 通过key给指定的value加值,如果key不存在,则这是value为该值 * </p> * * @param key * @param integer * @return */ public Long incrBy(String key, Long integer) { Jedis jedis = null; Long res = null; try { jedis = jedisPool.getResource(); res = jedis.incrBy(key, integer); } catch (Exception e) { log.error(e.getMessage()); } finally { returnResource(jedisPool, jedis); } return res; }
Example 6
Source File: RedisServiceImpl.java From ace-cache with Apache License 2.0 | 5 votes |
@Override public Long incrBy(String key, Long integer) { Jedis jedis = null; Long res = null; try { jedis = pool.getResource(); res = jedis.incrBy(key, integer); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { returnResource(pool, jedis); } return res; }
Example 7
Source File: TestJedis.java From khan-session with GNU Lesser General Public License v2.1 | 5 votes |
public static void testSequential() throws InterruptedException { final Jedis jedis = new Jedis("127.0.0.1", 6379); jedis.set("abc", Long.toString(0)); for (int i = 0; i < 500; i++) { jedis.incrBy("abc", i); } System.out.println("Done: " + jedis.get("abc")); }
Example 8
Source File: DefaultRedis.java From craft-atom with MIT License | 4 votes |
private Long incrby0(Jedis j, String key, long increment) { return j.incrBy(key, increment); }
Example 9
Source File: JedisUtil.java From Project with Apache License 2.0 | 3 votes |
/** * <b>可以作为获取唯一id的方法</b><br/> * 将key对应的value加上指定的值,只有value可以转为数字时该方法才可用 * * @param key * @param number 要减去的值 * @return long 相加后的值 */ public long incrBy(String key, long number) { Jedis jedis = getJedis(); long len = jedis.incrBy(key, number); jedis.close(); return len; }
Example 10
Source File: JedisUtil.java From BigData with GNU General Public License v3.0 | 3 votes |
/** * <b>可以作为获取唯一id的方法</b><br/> * 将key对应的value加上指定的值,只有value可以转为数字时该方法才可用 * * @param String * key * @param long number 要减去的值 * @return long 相加后的值 * */ public long incrBy(String key, long number) { Jedis jedis = getJedis(); long len = jedis.incrBy(key, number); returnJedis(jedis); return len; }
Example 11
Source File: ObjectCacheOperate.java From xian with Apache License 2.0 | 2 votes |
/** * @param jedis the jedis connection. * @param key the key * @param increment the increment * @return according to jedis javadoc, the new value after increment is returned. */ public static long incrBy(Jedis jedis, String key, long increment) { return jedis.incrBy(key, increment); }