package com.hcsc.repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import com.hcsc.entity.Insurance;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
@Repository
public class RedisRepositoryImpl implements RedisRepository {
private static final String KEY = "Insurance";
private RedisTemplate redisTemplate;
private HashOperations hashOperations;
@Autowired
public RedisRepositoryImpl(RedisTemplate redisTemplate){
this.redisTemplate = redisTemplate;
}
@PostConstruct
private void init(){
hashOperations = redisTemplate.opsForHash();
}
public void add(final Insurance insurance) {
Map> insuranceMap = new HashMap<>();
List insurances=new ArrayList<>();
insurances.add(insurance.getInsuranceId());
insurances.add(insurance.getTitle());
insurances.add(insurance.getCategory());
insuranceMap.put(insurance.getInsuranceId(),insurances);
if(!insuranceMap.isEmpty()){
hashOperations.putAll(KEY, insuranceMap);
}
}
/*
public void add(final Insurance insurance) {
Map> insuranceMap = new HashMap>();
List insurances=new ArrayList<>();
insurances.add(new Insurance(insurance.getInsuranceId(),insurance.getTitle(),insurance.getCategory()));
insuranceMap.put(insurance.getInsuranceId(),insurances);
if(!insuranceMap.isEmpty()){
hashOperations.putAll(KEY, insuranceMap);
}
}*/
public void delete(final String id) {
hashOperations.delete(KEY, id);
}
public Insurance findInsurance(final String id){
return (Insurance) hashOperations.get(KEY, id);
}
public Insurance findInsurances(final Collection insurances){
return (Insurance) hashOperations.multiGet(KEY, insurances);
}
public Map
return hashOperations.entries(KEY);
}
@Override
public void bulkInsert(List insuranceList) {
// TODO Auto-generated method stub
Map> insuranceMapRedis = new HashMap<>();
List insurances=new ArrayList<>();
insuranceMapRedis.put(KEY,insuranceList);
if(!insuranceMapRedis.isEmpty()){
hashOperations.putAll(KEY, insuranceMapRedis);
}
System.out.println("insuranceMapRedis"+insuranceMapRedis);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import com.hcsc.entity.Insurance;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
@Repository
public class RedisRepositoryImpl implements RedisRepository {
private static final String KEY = "Insurance";
private RedisTemplate
private HashOperations hashOperations;
@Autowired
public RedisRepositoryImpl(RedisTemplate
this.redisTemplate = redisTemplate;
}
@PostConstruct
private void init(){
hashOperations = redisTemplate.opsForHash();
}
public void add(final Insurance insurance) {
Map
List
insurances.add(insurance.getInsuranceId());
insurances.add(insurance.getTitle());
insurances.add(insurance.getCategory());
insuranceMap.put(insurance.getInsuranceId(),insurances);
if(!insuranceMap.isEmpty()){
hashOperations.putAll(KEY, insuranceMap);
}
}
/*
public void add(final Insurance insurance) {
Map
List
insurances.add(new Insurance(insurance.getInsuranceId(),insurance.getTitle(),insurance.getCategory()));
insuranceMap.put(insurance.getInsuranceId(),insurances);
if(!insuranceMap.isEmpty()){
hashOperations.putAll(KEY, insuranceMap);
}
}*/
public void delete(final String id) {
hashOperations.delete(KEY, id);
}
public Insurance findInsurance(final String id){
return (Insurance) hashOperations.get(KEY, id);
}
public Insurance findInsurances(final Collection
return (Insurance) hashOperations.multiGet(KEY, insurances);
}
public Map
return hashOperations.entries(KEY);
}
@Override
public void bulkInsert(List
// TODO Auto-generated method stub
Map
List
insuranceMapRedis.put(KEY,insuranceList);
if(!insuranceMapRedis.isEmpty()){
hashOperations.putAll(KEY, insuranceMapRedis);
}
System.out.println("insuranceMapRedis"+insuranceMapRedis);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
No comments:
Post a Comment