I have already a running instance of Redis Cache in AWS Account. How can I use the redis instance using the redis instance Endpoint in my java code to store the data.
I don't have any idea how to start with Redis Cache in java. Please help me out to resolve this.
- 
 1Start with github.com/redis/jediskgiannakakis– kgiannakakis2021年11月25日 18:44:59 +00:00Commented Nov 25, 2021 at 18:44
1 Answer 1
You can use spring-data-redis by including following dependency.
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-data-redis</artifactId>
 <version>2.2.6.RELEASE</version> 
</dependency>
Then specify properties as below:
spring.redis.database=0
spring.redis.host="Specify URL"
spring.redis.port=6379
spring.redis.password=mypass
spring.redis.timeout=60000
Then using RedisTemplate
@Autowired
private RedisTemplate<Long, Book> redisTemplate;
public void save(Book book) {
 redisTemplate.opsForValue().set(book.getId(), book);
}
public Book findById(Long id) {
 return redisTemplate.opsForValue().get(id);
}
 answered Nov 25, 2021 at 18:49
 
 
 
 shrm 
 
 1,1402 gold badges9 silver badges20 bronze badges
 
 
 Sign up to request clarification or add additional context in comments.
 
 
 
 3 Comments
Kakashi
 Thank you @shrm.
  Kakashi
 I am trying this method which you given. In the application.properties what I have to fill in spring.redis.host="Specify URL", spring.redis.password=mypass. Which hostname and password I have to add here?
  shrm
 @Kakashi The property name should give you a hint.
  Explore related questions
See similar questions with these tags.
lang-java