Example usage for org.springframework.data.redis.support.collections RedisList expire

List of usage examples for org.springframework.data.redis.support.collections RedisList expire

Introduction

In this page you can find the example usage for org.springframework.data.redis.support.collections RedisList expire.

Prototype

@Nullable
Boolean expire(long timeout, TimeUnit unit);

Source Link

Document

Sets the key time-to-live/expiration.

Usage

From source file:com.greenline.guahao.biz.manager.cache.hrs.ShiftCaseCacheManager.java

/**
 * ?/*from   w  w w.j a v a  2 s.co m*/
 * 
 * @param list
 */
public void setShiftCases(ShiftQuery query, final List<ShiftCaseDO> list) {
    if (query == null) {
        return;
    }

    if (list == null || list.isEmpty()) {
        String key = getIsCachedKey(queryKey(query));
        // 
        String isCached = template.opsForValue().get(key);
        if (StringUtils.isEmpty(isCached)) {
            setExpire(key, "true");
        }
        return;
    }
    // add to list
    final RedisList<String> redislist = shiftQueryList(query);
    redislist.clear();
    redislist.getOperations().execute(new SessionCallback<Object>() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public Object execute(RedisOperations operations) throws DataAccessException {
            operations.watch(redislist.getKey());
            operations.multi();
            for (ShiftCaseDO obj : list) {
                redislist.add(jackjson.writeString(obj));
            }
            operations.exec();
            return null;
        }
    });
    // 
    boolean expire = redislist.expire(this.getExpireTime(), TimeUnit.SECONDS);
    if (!expire) {
        // ??key
        template.delete(queryKey(query));
    }
}