我有一个对象:
@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模式。你能告诉我如何制作存储库吗?
例如这里使用静态键,我动态地形成了它。而且我还有一个对象列表,而不是一个。我无法理解我需要如何做正确的架构。