I remember using the pipeline function in node-redis to batch commands and execute them together. Is this function now deprecated? Has it been replaced with automatic pipelining within the client?
Here’s an example of how I’ve been using the pipeline function:
const redis = require("redis");
const client = redis.createClient();
client.on("error", (err) => {
console.error("Error:", err);
});
async function usePipelining() {
try {
await client.connect();
// Create a pipeline
const pipeline = client.pipeline();
pipeline.set("key1", "value1");
pipeline.set("key2", "value2");
pipeline.set("key3", "value3");
pipeline.get("key1");
pipeline.get("key2");
pipeline.get("key3");
// Execute the pipeline and handle results
const results = await pipeline.exec();
console.log("Pipeline results:");
results.forEach((result, index) => {
if (result[0]) {
console.error("Pipeline Error:", result[0]);
} else {
console.log(`Result ${index + 1}:`, result[1]);
}
});
} catch (err) {
console.error("Pipeline Execution Error:", err);
} finally {
client.quit();
}
}
usePipelining().catch((err) => {
console.error("Unexpected Error:", err);
});
Can someone clarify if the pipeline function is still the recommended way to batch commands, or should we rely on automatic pipelining features in newer versions of node-redis?
Has client.pipeline()
or client.batch()
been deprecated?
I know commands that are written on the same “tick” are auto-pipelined in the node-redis package’s new version:
const replies = await Promise.all([
client.get('a'),
client.get('b')
]);
Environment details:
- Node.js version: v22.2.0
- node-redis version: v4.6.15
- Redis Server version: v7.0.15
- Operating System: Ubuntu 24.04