本文整理匯總了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());
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
示例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");
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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;
}