Example #1
0
 public long incr(String key) {
   ShardedJedis shardedJedis = null;
   try {
     shardedJedis = masterShardedJedisPool.getResource();
     return shardedJedis.incr(key);
   } catch (Exception ex) {
     logger.error("incr error.", ex);
   } finally {
     returnResource(shardedJedis);
   }
   return 0;
 }
 /**
  * 通过key 对value进行加值+1操作,当value不是int类型时会返回错误,当key不存在是则value为1
  *
  * @param key
  * @return 加值后的结果
  */
 public Long incr(String key) {
   ShardedJedis jedis = null;
   Long res = null;
   try {
     jedis = pool.getResource();
     res = jedis.incr(key);
   } catch (Exception e) {
     pool.returnBrokenResource(jedis);
     e.printStackTrace();
   } finally {
     returnResource(pool, jedis);
   }
   return res;
 }