Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: get all data using Promise #1857

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ redis.get("mykey").then((result) => {
console.log(result); // Prints "value"
});

// Get All data from Redis using Promise
let data = []; // Initialize an empty array to store data
const keys = await redis.keys('*'); // Fetch all keys from Redis
const pipeline = redis.pipeline(); // Create a pipeline to execute Redis commands sequentially
keys.forEach(key => {
pipeline.get(key); // Add Redis commands to fetch data corresponding to each key into the pipeline
});
const results = await pipeline.exec(); // Execute the pipeline to fetch data from Redis

redis.zadd("sortedSet", 1, "one", 2, "dos", 4, "quatro", 3, "three");
redis.zrange("sortedSet", 0, 2, "WITHSCORES").then((elements) => {
// ["one", "1", "dos", "2", "three", "3"] as if the command was `redis> ZRANGE sortedSet 0 2 WITHSCORES`
Expand Down