Java Code Examples for redis.clients.jedis.Jedis#decr()
The following examples show how to use
redis.clients.jedis.Jedis#decr() .
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 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: SeckillServiceImpl.java From jseckill with Apache License 2.0 | 6 votes |
/** * 在Redis中真正进行秒杀操作 * @param seckillId * @param userPhone * @throws SeckillException */ @Override public void handleInRedis(long seckillId, long userPhone) throws SeckillException { Jedis jedis = jedisPool.getResource(); String inventoryKey = RedisKeyPrefix.SECKILL_INVENTORY + seckillId; String boughtKey = RedisKeyPrefix.BOUGHT_USERS + seckillId; String inventoryStr = jedis.get(inventoryKey); int inventory = Integer.valueOf(inventoryStr); if (inventory <= 0) { logger.info("handleInRedis SECKILLSOLD_OUT. seckillId={},userPhone={}", seckillId, userPhone); throw new SeckillException(SeckillStateEnum.SOLD_OUT); } if (jedis.sismember(boughtKey, String.valueOf(userPhone))) { logger.info("handleInRedis SECKILL_REPEATED. seckillId={},userPhone={}", seckillId, userPhone); throw new SeckillException(SeckillStateEnum.REPEAT_KILL); } jedis.decr(inventoryKey); jedis.sadd(boughtKey, String.valueOf(userPhone)); logger.info("handleInRedis_done"); }
Example 3
Source File: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
/** * <p> * 对key的值做减减操作,如果key不存在,则设置key为-1 * </p> * * @param key * @return */ public Long decr(String key) { Jedis jedis = null; Long res = null; try { jedis = jedisPool.getResource(); res = jedis.decr(key); } catch (Exception e) { log.error(e.getMessage()); } finally { returnResource(jedisPool, jedis); } return res; }
Example 4
Source File: RedisPoolUtil.java From seconds-kill with MIT License | 5 votes |
/** * key - value 自减 */ public static Long decr (String key) { Jedis jedis = null; Long result = null; try { jedis = RedisPool.getJedis(); result = jedis.decr(key); } catch (Exception e) { log.error("listGet key:{} error", key, e); } finally { RedisPool.jedisPoolClose(jedis); } return result; }
Example 5
Source File: RedisService.java From seckill with Apache License 2.0 | 5 votes |
/** * 减少值 * * @param prefix * @param key * @param <T> * @return */ 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); } }
Example 6
Source File: RedisClient.java From Mykit with Apache License 2.0 | 5 votes |
public Long decr(String key) { Jedis client = jedisPool.getResource(); try { return client.decr(key); } finally { // 向连接池“归还”资源 jedisPool.returnResourceObject(client); } }
Example 7
Source File: RedisUtil.java From zhcc-server with Apache License 2.0 | 5 votes |
/** * 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; }
Example 8
Source File: RedisServiceImpl.java From ace-cache with Apache License 2.0 | 5 votes |
@Override public Long decr(String key) { Jedis jedis = null; Long res = null; try { jedis = pool.getResource(); res = jedis.decr(key); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { returnResource(pool, jedis); } return res; }
Example 9
Source File: RedisUtil.java From zheng with MIT License | 5 votes |
/** * 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; }
Example 10
Source File: ObjectCacheOperate.java From xian with Apache License 2.0 | 4 votes |
public static long decr(Jedis jedis, String key) { return jedis.decr(key); }
Example 11
Source File: SeckillLock.java From javabase with Apache License 2.0 | 4 votes |
private static void doTask(Jedis jedis, String value) { jedis.decr(ITEM_NUMBER_KEY); log.info("{} 秒杀成功!", value); }
Example 12
Source File: DefaultRedis.java From craft-atom with MIT License | 4 votes |
private Long decr0(Jedis j, String key) { return j.decr(key); }