當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.incr方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.incr方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.incr方法的具體用法?Java Jedis.incr怎麽用?Java Jedis.incr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.incr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkJedisIsReusedWhenReturned

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void checkJedisIsReusedWhenReturned() {

  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:JedisPoolTest.java

示例2: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long incr(String key) {
	Jedis jedis = null;
	boolean success = true;
	long ret = -1;
	try {
		jedis = jedisPool.getResource();
		if (jedis == null) {
			success = false;
			return ret;
		}
		ret = jedis.incr(key);
	} catch (Exception e) {
		success = false;
		returnBrokenResource(jedis, "incr:" + key, e);
	} finally {
		releaseReidsSource(success, jedis);
	}
	return ret;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:RedisService.java

示例3: fetchDailyUUID

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long fetchDailyUUID(String key, Integer length, Boolean haveDay) {
    Jedis jedis = null;
    try {
        jedis = redisConnection.getJedis();
        jedis.select(dbIndex);
        Calendar now = new GregorianCalendar();
        String day = df.format(now.getTime());
        key = key + "_" + day;
        Long num = jedis.incr(key);
        //設置 key 過期時間
        if (num == 1) {
            jedis.expire(key, (24 - now.get(Calendar.HOUR_OF_DAY)) * 3600 + 1800);
        }
        if (haveDay) {
            return createUUID(num, day, length);
        } else {
            return num;
        }
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
 
開發者ID:gaochao2000,項目名稱:redis_util,代碼行數:25,代碼來源:UUIDServiceRedisImpl.java

示例4: fetchUUID

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long fetchUUID(String key, Integer length, Boolean haveDay) {
    Jedis jedis = null;
    try {
        jedis = redisConnection.getJedis();
        jedis.select(dbIndex);
        Calendar now = new GregorianCalendar();
        Long num = jedis.incr(key);

        if (haveDay) {
            String day = df.format(now.getTime());
            return createUUID(num, day, length);
        } else {
            return num;
        }
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
 
開發者ID:gaochao2000,項目名稱:redis_util,代碼行數:21,代碼來源:UUIDServiceRedisImpl.java

示例5: increame

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public long increame(String key) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        if (jedis != null) {
            return jedis.incr(key);
        } else {
            logger.error("increame opt connection null error!");
        }
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
            jedis = null;
        }
        logger.error("increame connect error:", e);
    } finally {
        returnJedisResource(jedis);
    }
    return 0L;
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:21,代碼來源:JedisUtil.java

示例6: main

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    Bench<JedisPool> bench = new JedisBench() {
        @Override
        public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
                MetricRegistry metrics) {
            Jedis jedis = benchInstance.getResource();
            
            Timer.Context time = metrics.timer("incr").time();
            jedis.incr("incr_" + threadNumber + "_" + iteration);
            time.stop();
            
            jedis.close();
        }
    };
    
    Benchmark benchmark = new Benchmark(bench);
    benchmark.run(args);
}
 
開發者ID:redisson,項目名稱:redisson-benchmark,代碼行數:19,代碼來源:AtomicLongIncBenchmark.java

示例7: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public long incr(String key) {
    Jedis jedis = jedisPool.getResource();
    Long result = null;
    try {
        result = jedis.incr(key);
    } catch (Exception e) {
        jedisPool.returnBrokenResource(jedis);
    } finally {
        jedisPool.returnResource(jedis);
    }
    return result;
}
 
開發者ID:melonlee,項目名稱:LazyREST,代碼行數:13,代碼來源:JedisClientImpl.java

示例8: checkPoolRepairedWhenJedisIsBroken

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void checkPoolRepairedWhenJedisIsBroken() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.quit();
  pool.returnBrokenResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:16,代碼來源:JedisPoolTest.java

示例9: checkPoolOverflow

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test(expected = JedisException.class)
public void checkPoolOverflow() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");

  Jedis newJedis = pool.getResource();
  newJedis.auth("foobared");
  newJedis.incr("foo");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:JedisPoolTest.java

示例10: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 自增
 *
 * @param key key
 * @return 0:失敗,非0:成功
 */
public Long incr(String key) {
    Jedis jedis = null;

    try {
        jedis = getConnect();
        return jedis.incr(key);
    } catch (Exception e) {
        logger.error("redis getRedisData data failed!", e);
        return 0L;
    } finally {
        close(jedis);
    }
}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:20,代碼來源:RedisUtil.java

示例11: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Long incr(String key) {
	Jedis jedis = jedisPool.getResource();
	Long result = jedis.incr(key);
	jedis.close();
	return result;
}
 
開發者ID:mmdsyl,項目名稱:BLOG-Microservice,代碼行數:8,代碼來源:JedisClientPool.java

示例12: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * incr
 * @param key
 * @return value
 */
public synchronized static Long incr(String key) {
	Jedis jedis = getJedis();
	if (null == jedis) {
		return null;
	}
	long value = jedis.incr(key);
	jedis.close();
	return value;
}
 
開發者ID:youngMen1,項目名稱:-Spring-SpringMVC-Mybatis-,代碼行數:15,代碼來源:RedisUtil.java

示例13: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * @Description 自增生成ID
 * 
 * @author butterfly
 * @param key
 * @param value
 * @throws Exception
 */
public Long incr(String key) throws Exception {
	Jedis jedis = null;
	try {
		jedis = jedisPool.getResource();
		Long index = jedis.incr(key);
		return index;
	} catch (Exception ex) {
		throw ex;
	} finally {
		// 返還到連接池
		if (null != jedis)
			jedis.close();
	}
}
 
開發者ID:butter-fly,項目名稱:belling-redis-id-generator,代碼行數:23,代碼來源:JedisClient.java

示例14: incr

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Long incr(String key) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.incr(key);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
開發者ID:wxiaoqi,項目名稱:ace-cache,代碼行數:16,代碼來源:RedisServiceImpl.java

示例15: increase

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public Long increase(String key) {
    Jedis jedis = null;

    Long var3;
    try {
        jedis = pool.getResource();
        var3 = jedis.incr(key);
    } catch (Exception var7) {
        throw new RuntimeException(var7);
    } finally {
        pool.returnResourceObject(jedis);
    }

    return var3;
}
 
開發者ID:bitstd,項目名稱:bitstd,代碼行數:16,代碼來源:RedisCacheWithoutCluster.java


注:本文中的redis.clients.jedis.Jedis.incr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。