我正在从我的 Spring 应用程序中的 google place API 获取数据。我想在弹性缓存redis中存储纬度和经度。
我已经创建了一个 EC2 实例。我创建了一个弹性缓存redis集群。我对 aws 和 spring 有点陌生。不知道如何继续前进。有详细的指南或视频可以参考吗?
如果您不熟悉 AWS/Spring,我建议您按照此 AWS 示例来更加熟悉如何创建可调用 AWS 服务操作的 Spring 应用程序。此示例构建了一个调用多项 AWS 服务的 Spring Boot Web 应用程序。
它将让您了解如何在 Spring Boot 项目中使用 AWS SDK for Java V2 来启动和运行(不要使用 V1,因为该版本即将弃用)。
一旦您习惯了在 Spring Boot 项目中使用适用于 Java V2 的 AWS 开发工具包,您就可以将此服务客户端用于您的用例。
例如:
String latitude = "your_latitude"; // Replace with the actual latitude
String longitude = "your_longitude"; // Replace with the actual longitude
ElastiCacheClient elastiCacheClient = ElastiCacheClient.builder()
.region(Region.YOUR_REGION) // Replace with your AWS region
.build();
elastiCacheClient.putObject(
PutObjectRequest.builder()
.cacheClusterId("your_cache_cluster_id") // Replace with your ElastiCache cluster ID
.key("your_key") // Replace with a unique key for your data
.value(latitude + "," + longitude)
.build()
);
我展示了如何将适用于 Java V2 的 AWS 开发工具包挂接到 Spring Boot 项目中,并为您指明了用于您的用例的服务客户端。