1

I have a service built with spring boot and redis, which listens for HTTP requests.

I would like that when the server runs up, it populates some predefined data in redis cache.

I thought about having a .yml file and when the service starts it calls an endpoint like /addData with the information of that .yml file; but I think this is not an efficient way to achieve my goal.

Which is the best option to start a service with data cached in redis?

asked Aug 26, 2018 at 13:13

2 Answers 2

1

2 options either EventListener or on the main method

@EventListener(ApplicationReadyEvent.class)
public void loadRedis() {
 //do the work here
}

another option is to do it in springbootapplication main method.

public static void main(final String[] args) {
 ConfigurableApplicationContext context = 
 SpringApplication.run(Application.class, args);
 context.getBean(Whatever.class).loadRedis();
}
answered Aug 26, 2018 at 16:05
Sign up to request clarification or add additional context in comments.

Comments

1

using JedisPool

public static void initCache() {
 jedisPool = new JedisPool( new JedisPoolConfig() , "localhost",8081);
 }
answered Jun 8, 2019 at 9:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.