3

We are planning to use Redis cache in our app , our requirement is first we need to load some 6 month data into Redis cache before actual app starts , i am thinking that if we execute one command at a time in loop like to insert key values into Redis , it will take too much time , is their way we can retrieve the data from database and insert all the data into Redis in one shot ?

can any one please suggest ?

asked Nov 10, 2017 at 10:11

1 Answer 1

1

Redis provides support for pipelining, which involves sending multiple commands to the server without waiting for the replies and then reading the replies in a single step. Pipelining can improve performance when you need to send several commands in a row, such as adding many elements to the same List.

Spring Data Redis provides several RedisTemplate methods for executing commands in a pipeline.

One example:

//pop a specified number of items from a queue
List<Object> results = stringRedisTemplate.executePipelined(
 new RedisCallback<Object>() {
 public Object doInRedis(RedisConnection connection) throws DataAccessException {
 StringRedisConnection stringRedisConn = (StringRedisConnection)connection;
 for(int i=0; i< batchSize; i++) {
 stringRedisConn.rPop("myqueue");
 }
 return null;
 }
});

You can follow this link

Or you can use Redis Mass insertion facility too.

answered Nov 10, 2017 at 15:03
Sign up to request clarification or add additional context in comments.

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.