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

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

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

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

/**
 * /*w w  w.  ja v a  2  s  .c o  m*/
 * 
 * @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 w  w  . j a  v a2 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));
    }
}

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

/**
 * /*from   ww w.ja  v  a 2 s.  c  o 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 v  a2 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

/**
 * /*from   w w w  .  jav a  2s.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);
    }
}

From source file:org.springframework.integration.redis.outbound.RedisCollectionPopulatingMessageHandler.java

@SuppressWarnings("unchecked")
private void handleList(RedisList<Object> list, Message<?> message) {
    Object payload = message.getPayload();
    if (this.extractPayloadElements) {
        if (payload instanceof Collection<?>) {
            list.addAll((Collection<? extends Object>) payload);
        } else {//www  . ja v  a  2 s . c o m
            list.add(payload);
        }
    } else {
        list.add(payload);
    }
}

From source file:org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler.java

@SuppressWarnings("unchecked")
private void writeToList(RedisList<Object> list, Message<?> message) {
    Object payload = message.getPayload();
    if (this.extractPayloadElements) {
        if (payload instanceof Collection<?>) {
            list.addAll((Collection<? extends Object>) payload);
        } else {/*from www .ja  v  a 2  s .co m*/
            list.add(payload);
        }
    } else {
        list.add(payload);
    }
}