Java Code Examples for redis.clients.jedis.Jedis#decrBy()

The following examples show how to use redis.clients.jedis.Jedis#decrBy() . 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 vote down vote up
/**
 * 递减数字
 *
 * @param key 键
 * @param by  步长
 * @return
 */
public static long decr(String key, long by) {
    long result = 0;
    Jedis jedis = null;
    try {
        jedis = getResource();
        if (by > 0) {
            result = jedis.decrBy(key, by);
        } else {
            result = jedis.decr(key);
        }

    } catch (Exception e) {
        logger.warn("decr 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 vote down vote up
@Override
public void decrByEx(String key, Long value, Integer ttl) {
    Jedis jedis = null;
    try {
        jedis = getInstance();
        jedis.decrBy(key, value);
        if (ttl != null) {
            jedis.expire(key, ttl);
        }
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Cannot send Redis with decrBy command with decrement {}  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 vote down vote up
@Override
public void decrBy(String key, Long value) {
    Jedis jedis = null;
    try {
        jedis = getInstance();
        jedis.decrBy(key, value);
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Cannot send Redis with decrBy command with increment {}  error message {}",
                    key, value, e.getMessage());
        }
        throw e;
    } finally {
        releaseInstance(jedis);
    }
}
 
Example 4
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 减去指定的值
 * </p>
 *
 * @param key
 * @param integer
 * @return
 */
public Long decrBy(String key, Long integer) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.decrBy(key, integer);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 5
Source File: RedisClient.java    From springboot-learn with MIT License 5 votes vote down vote up
public Long decr(final String key, final Integer by) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        return jedis.decrBy(key, by);
    } catch (Exception e) {
        logger.error("[RedisClient] decr e,", e);
        throw new IllegalArgumentException("减1异常");
    } finally {
        close(jedis);
    }
}
 
Example 6
Source File: RedisClient.java    From springboot-learn with MIT License 5 votes vote down vote up
public Long decr(final String key, final Integer by) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        return jedis.decrBy(key, by);
    } catch (Exception e) {
        logger.error("[RedisClient] decr e,", e);
        throw new IllegalArgumentException("减1异常");
    } finally {
        close(jedis);
    }
}
 
Example 7
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public Long decrBy(String key, Long integer) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.decrBy(key, integer);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 8
Source File: ObjectCacheOperate.java    From xian with Apache License 2.0 4 votes vote down vote up
public static long decrBy(Jedis jedis, String key, long value) {
    return jedis.decrBy(key, value);
}
 
Example 9
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long decrby0(Jedis j, String key, long decrement) {
	return j.decrBy(key, decrement);
}
 
Example 10
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 将key对应的value减去指定的值,只有value可以转为数字时该方法才可用
 * 
 * @param  key
 * @param   number 要减去的值
 * @return long 减指定值后的值
 */
public long decrBy(String key, long number) {
	Jedis jedis = getJedis();
	long len = jedis.decrBy(key, number);
	jedis.close();
	return len;
}
 
Example 11
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 将key对应的value减去指定的值,只有value可以转为数字时该方法才可用
 * 
 * @param String
 *            key
 * @param long number 要减去的值
 * @return long 减指定值后的值
 * */
public long decrBy(String key, long number) {
	Jedis jedis = getJedis();
	long len = jedis.decrBy(key, number);
	returnJedis(jedis);
	return len;
}