Closed vincentjames501 closed 5 years ago
This works! Here is a link to my repo: https://github.com/wbijen/jesque
public static void doBulkEnqueue(Jedis jedis, String namespace, String queue, List<String> jobJsonList, int batchSize) {
jedis.sadd(JesqueUtils.createKey(namespace, new String[]{"queues"}), new String[]{queue});
Pipeline pipeline = jedis.pipelined();
String key = JesqueUtils.createKey(namespace, new String[]{"queue", queue});
int i = 0;
for (String jobJson : jobJsonList) {
String jobJson = it.next();
jedis.rpush(key, new String[]{jobJson});
++i;
if (i == batchSize) {
pipeline.sync();
pipeline = jedis.pipelined();
i = 0;
}
}
if (i > 0) {
pipeline.sync();
}
}
It would be nice to add to the
Client
interface the ability to batch queue jobs. In our case we need to batch queue around 40-100k jobs and it would be nice to do it in a single pipeline w/ Jedis.