cn.foxtech.common.entity.manager.EntityHashMapComponent Maven / Gradle / Ivy
package cn.foxtech.common.entity.manager;
import cn.foxtech.common.entity.service.redis.HashMapRedisService;
import cn.foxtech.common.entity.service.redis.BaseHashMapRedisService;
import cn.foxtech.utils.common.utils.redis.service.RedisService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* HashMap版的Redis的部件:它将数据以HashMap的方式,保存到本地缓存。
* 这样的好处是,消费这个数据的服务,并不需要知道跟生产者结构化定义
*/
@Data
@Component
public class EntityHashMapComponent {
/**
* 消费者:Entity结构的数据
*/
private final Set consumer = new HashSet<>();
@Autowired
public RedisTemplate redisTemplate;
@Autowired
private RedisService redisService;
protected T getEntity(Long id, Class clazz) {
if (this.consumer.contains(clazz.getSimpleName())) {
HashMapRedisService consumerRedisService = HashMapRedisService.getInstanceBySimpleName(clazz.getSimpleName(), this.redisService);
return (T) consumerRedisService.getEntity(id);
}
return null;
}
protected T getEntity(String entityKey, Class clazz) {
if (this.consumer.contains(clazz.getSimpleName())) {
HashMapRedisService consumerRedisService = HashMapRedisService.getInstanceBySimpleName(clazz.getSimpleName(), this.redisService);
return (T) consumerRedisService.getEntity(entityKey);
}
return null;
}
protected List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy