小编RAS*_*RAS的帖子

在 SpringBoot App 中使用 redis 创建 Repository

我有一个对象:

@Data
@AllArgsConstructor
public class ResultGeoObjectDto {
   private String addressLine;
   private String location;
   private double latitude;
   private double longitude;
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个服务,它与我的对象和Redis

@Service
public class RedisService {

private final RedisTemplate<String, List<ResultGeoObjectDto>> redisTemplate;

@Autowired
public RedisService(RedisTemplate<String, List<ResultGeoObjectDto>> redisTemplate) {
    this.redisTemplate = redisTemplate;
}

public void setValue(String key, List<ResultGeoObjectDto> value) {

    redisTemplate.opsForList().leftPush(key, value);
}

public List<ResultGeoObjectDto> getGeoObjectByKey(String key) {
    return redisTemplate.opsForList().range(key, -1, -1).get(0);
}

public boolean objectExistInRedisStore(String key) {
    return redisTemplate.hasKey(key);
}
Run Code Online (Sandbox Code Playgroud)

}

这很好用,但许多示例使用Repository模式。你能告诉我如何制作存储库吗?

例如这里使用静态键,我动态地形成了它。而且我还有一个对象列表,而不是一个。我无法理解我需要如何做正确的架构。

java spring repository-pattern redis spring-boot

1
推荐指数
1
解决办法
4684
查看次数

标签 统计

java ×1

redis ×1

repository-pattern ×1

spring ×1

spring-boot ×1