Example usage for org.springframework.data.redis.core RedisOperations watch

List of usage examples for org.springframework.data.redis.core RedisOperations watch

Introduction

In this page you can find the example usage for org.springframework.data.redis.core RedisOperations watch.

Prototype

void watch(Collection<K> keys);

Source Link

Document

Watch given keys for modifications during transaction started with #multi() .

Usage

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

/**
 * //from  w  ww .  j a  v  a2s.  com
 * 
 * @param list
 */
public void setDicts(String dictId, final List<DictDO> list) {

    if (StringUtils.isEmpty(dictId) || list == null || list.isEmpty()) {
        return;
    }

    final RedisList<String> redislist = dictList(dictId);
    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 (DictDO obj : list) {
                redislist.add(jackjson.writeString(obj));
            }
            operations.exec();
            return null;
        }
    });

    setExpire(redislist);
}

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

/**
 * ?// w ww  .j  a v  a2s  .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));
    }
}

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

/**
 * //from www .  j a v a2 s .  co  m
 * 
 * @param list
 */
public void setHospLevels(final List<HospitalLevelDO> list) {
    if (list == null || list.isEmpty()) {
        return;
    }

    final RedisList<String> leveList = hospitallevels();
    leveList.clear();
    leveList.getOperations().execute(new SessionCallback<Object>() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public Object execute(RedisOperations operations) throws DataAccessException {
            operations.watch(leveList.getKey());
            operations.multi();
            for (HospitalLevelDO obj : list) {
                leveList.add(jackjson.writeString(obj));
            }
            operations.exec();
            return null;
        }
    });
    // 
    setExpire(leveList);
}

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

/**
 * ?//from  www  .j a  va  2 s .c  o  m
 * 
 * @param hospitalId
 * @param list
 */
public void setClinicTypes(String hospitalId, final List<ClinicTypeDO> list) {
    if (StringUtils.isEmpty(hospitalId) || list == null || list.isEmpty()) {
        return;
    }
    final RedisList<String> clinicTypes = clinicTypes(hospitalId);
    clinicTypes.clear();
    clinicTypes.getOperations().execute(new SessionCallback<Object>() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public Object execute(RedisOperations operations) throws DataAccessException {
            operations.watch(clinicTypes.getKey());
            operations.multi();
            for (ClinicTypeDO obj : list) {
                clinicTypes.add(obj.getId());
            }
            operations.exec();
            return null;
        }
    });

    for (ClinicTypeDO obj : list) {
        setClinicType(obj.getId(), obj);
    }
    setExpire(clinicTypes);
}

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

/**
 * //  w  ww.  j  a v a2  s . c  om
 * 
 * @param hospitalId
 * @param list
 */
public void setHospitalDepts(String hospitalId, final List<HospitalDepartmentDO> list) {
    if (hospitalId == null || list == null || list.isEmpty()) {
        return;
    }
    // 
    final RedisList<String> hDepts = hospitalDepts(hospitalId);
    // 
    hDepts.clear();
    // 
    hDepts.getOperations().execute(new SessionCallback<Object>() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        public Object execute(RedisOperations operations) throws DataAccessException {
            operations.watch(hDepts.getKey());
            operations.multi();
            for (HospitalDepartmentDO obj : list) {
                hDepts.add(obj.getId());
            }
            operations.exec();
            return null;
        }
    });
    setExpire(hDepts);
    // ?
    for (HospitalDepartmentDO obj : list) {
        setHospitalDept(obj.getId(), obj);
    }
}