Reputation: 9027
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 ?
Upvotes: 3
Views: 7672
Reputation: 1895
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.
Upvotes: 1