当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.expire方法代码示例

本文整理汇总了Java中redis.clients.jedis.Transaction.expire方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.expire方法的具体用法?Java Transaction.expire怎么用?Java Transaction.expire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.Transaction的用法示例。


在下文中一共展示了Transaction.expire方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: taskLockVersionOne

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
/**
 * 方案一的坏处:
 * 假如在极端情况下,可能出现集群各个服务器同时执行到taskLockVersionOne,或者 doTask执行时间过长,
 * 在redis事物还没提交的时候,会出现同时有多台服务器执行doTask。
 * @param id
 */
private static void taskLockVersionOne(String id) {
	String key = "default_task_id";
	String value = jedis.get(key);
	// 用redis 事物是防止 在set成功之后 在执行doTask或者其他情况导致程序终止没有执行到transaction.expire()
	// 导致单台机器一直占着锁会有单点事故
	Transaction transaction = null;
	try {
		transaction = jedis.multi();
		if (value == null) {
			transaction.set(key, id);
			doTask(id);
			// 设置过期是防止单点错误
			transaction.expire(key, 30);
		} else {
			if (value.equals(id)) {
				doTask(id);
			}
		}
	} catch (Exception e) {
		log.error("e" + e);
	} finally {
		transaction.exec();
	}
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:31,代码来源:TaskLock.java

示例2: taskLockVersionTwo

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
/**
 * 方案二:
 * 会重复两次回去jedis.get(key);
 * 同时如果expire时间小于doTask时间,也会出现同时有两个任务执行doTask情况。
 * @param id
 */
private static void taskLockVersionTwo(String id) {
	String key = "default_task_id";
	String value = jedis.get(key);
	// 用redis 事物是防止 在set成功之后 在执行doTask或者其他情况导致程序终止没有执行到transaction.expire()
	// 导致单台机器一直占着锁会有单点事故
	Transaction transaction = null;
	try {
		transaction = jedis.multi();
		if (value == null) {
			transaction.set(key, id);
			transaction.expire(key, 30);
		}
	} catch (Exception e) {
		log.error("e" + e);
	} finally {
		transaction.exec();
	}
	value = jedis.get(key);
	if (value.equals(id)) {
		doTask(id);
	}
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:29,代码来源:TaskLock.java

示例3: main

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
	ApplicationContext ac = new ClassPathXmlApplicationContext("root-context.xml");
	JedisPool pool = (JedisPool) ac.getBean("jedisPool");
	int count = 0;
	while (true) {
		Jedis jedis = pool.getResource();
		jedis.get("keyName");
		Transaction tx = jedis.multi();
		tx.incr("keyName");
		tx.expire("keyName", 10);
		tx.exec();	
		jedis.close();
		System.out.println("jedisPool active count:" + pool.getNumActive());
		System.out.println("jedisPool idle count:" + pool.getNumIdle());
		Thread.sleep(10);
	}

}
 
开发者ID:tangaiyun,项目名称:Netty-Resteasy-Spring,代码行数:19,代码来源:TestJedisPool.java

示例4: transactionNoPipeline

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
public void transactionNoPipeline() {
  Jedis jedis = pool.getResource();
  try {
    Transaction tx = jedis.multi();
    for (int i = 0; i < rowCount; i++) {
      String key = RandomStringUtils.randomAlphabetic(8);
      tx.set(key, RandomStringUtils.randomNumeric(5));
      tx.expire(key, 5 * 60);
    }
    tx.exec();
  } catch (Exception e) {
    pool.returnResource(jedis);
  }
}
 
开发者ID:nickevin,项目名称:Qihua,代码行数:15,代码来源:RedisTransactionTest.java

示例5: add

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
public void add(String key, String value) {
    if(fake) {
        ConcurrentLinkedQueue<String> stack = circularStackMap.get(key);
        if(stack==null) {
            synchronized(circularStackMap) {
                stack = circularStackMap.get(key);
                if(stack==null) {
                    stack = new ConcurrentLinkedQueue<String>();
                    circularStackMap.put(key, stack);
                }
            }
        }
        stack.add(value);
        while(stack.size() > capacity) {
            stack.poll();
        }
    } else {
        try(Jedis jedis = jedisPool.getResource()) {
            Transaction transaction = jedis.multi();
            transaction.lpush(key, value);
            transaction.ltrim(key, 0, capacity); // right away trim to capacity so that we can pretend it is a circular list
            transaction.expire(key, expireInSeconds); // don't keep the data forever
            transaction.exec();
        } catch (JedisException e) {
            // make sure we can find back jedis related stuff in kibana
            throw new IllegalStateException("problem connecting to jedis", e);
        }
    }
}
 
开发者ID:Inbot,项目名称:inbot-es-http-client,代码行数:30,代码来源:RedisBackedCircularStack.java

示例6: increment

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
public void increment(String key, int windowInSecond) throws Exception {

        long currentMs = System.currentTimeMillis();
        long maxScoreMs = currentMs - windowInSecond * 1000;

        Transaction redis = jedisPool.getResource().multi();
        redis.zremrangeByScore(key, 0, maxScoreMs);
        redis.zadd(key, currentMs, currentMs + "-" + Math.random()); //keep members unique
        redis.expire(key, windowInSecond);
        redis.exec();
    }
 
开发者ID:halilduygulu,项目名称:redis-sliding-window-counter,代码行数:12,代码来源:SlidingWindowCounter.java

示例7: onFailure

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
@Override
protected boolean onFailure(Map<String, Response<Long>> storedValue, Transaction jedisMulti) {
    if (storedValue.get(Const.REDIS_SERVICE_CAPACITY_DAILY_TTL).get() < 0) {
        String serviceId = requestInfo.getServiceId();
        String serviceQuota = ehcacheFactory.getServiceInfoCache()
                .get(serviceId).getDailyCapacity();
        jedisMulti.hset(Const.REDIS_SERVICE_CAPACITY_DAILY, serviceId, serviceQuota);
        jedisMulti.expire(Const.REDIS_SERVICE_CAPACITY_DAILY, Const.SECOND_OF_DAY);
        return true;
    }
    return false;
}
 
开发者ID:longcoding,项目名称:undefined-gateway,代码行数:13,代码来源:ServiceCapacityInterceptor.java

示例8: bumpTimeout

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
private void bumpTimeout() {
    try (Jedis jedis = sessionManager.jedisPool.getResource()) {
        Transaction transaction = jedis.multi();
        transaction.expire(sessionId, maxInactiveInterval);
        transaction.expire(sessionId + CREATED_FIELD, maxInactiveInterval);

        transaction.exec();
    }
}
 
开发者ID:coat,项目名称:undertow-redis-session,代码行数:10,代码来源:RedisSessionManager.java

示例9: setAndExpireWithTran

import redis.clients.jedis.Transaction; //导入方法依赖的package包/类
public void setAndExpireWithTran(){
    Jedis jedis = getResource();
    try {
        Transaction transaction = jedis.multi();
        transaction.set("x", Long.valueOf(count.incrementAndGet()).toString());
        transaction.expire("x", 600);
        transaction.exec();
    }finally {
        returnResource(jedis);
    }

}
 
开发者ID:Jdoing,项目名称:example,代码行数:13,代码来源:SeqGenerator.java


注:本文中的redis.clients.jedis.Transaction.expire方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。