Skip to content
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dde0207
Initial plan
Copilot Jul 8, 2025
9c17c6d
Replace redis-rb-cluster examples with Valkey GLIDE Node.js examples
Copilot Jul 8, 2025
450a79b
Update Valkey GLIDE client configuration to match official API
Copilot Jul 8, 2025
ede5dbf
Fix Valkey GLIDE Node.js example based on API feedback
Copilot Jul 8, 2025
428e425
Use ES6 shorthand property syntax for addresses parameter
Copilot Jul 8, 2025
d290d08
Replace line number references with descriptive section names in clus…
Copilot Jul 8, 2025
910843d
Validate and fix Valkey GLIDE Node.js API usage and text accuracy
Copilot Jul 8, 2025
83d43fd
Update Valkey GLIDE client configuration to match official API format
Copilot Jul 8, 2025
8078f28
Remove HTML test files and update .gitignore
Copilot Jul 8, 2025
2b298fc
Revise cluster tutorial structure and enhance command formatting for …
avifenesh Jul 10, 2025
915431a
Update topics/cluster-tutorial.md
avifenesh Aug 1, 2025
79add73
Update topics/cluster-tutorial.md
avifenesh Aug 1, 2025
83a24d2
Fix markdown formatting issues: tag code blocks correctly and fix nes…
Copilot Aug 1, 2025
c858bf1
Apply suggestion from @avifenesh
avifenesh Aug 1, 2025
c393a64
Apply suggestion from @avifenesh to improve section introduction
Copilot Aug 1, 2025
b538e31
Initial plan
Copilot Jul 8, 2025
551cb2e
add missing words to wordlist
avifenesh Aug 5, 2025
6113ff4
Initial plan
Copilot Jul 8, 2025
fb7fab9
Initial plan
Copilot Jul 8, 2025
b527e88
fix: ensure newline at end of file in wordlist
avifenesh Aug 5, 2025
67199c6
Replace MSET batching with individual SET operations to avoid cross-s…
Copilot Aug 5, 2025
ba2d5c5
Update example output to match individual SET operations
Copilot Aug 6, 2025
8872827
Merge branch 'main' into copilot/fix-147
avifenesh Aug 9, 2025
3423472
Update topics/cluster-tutorial.md
avifenesh Aug 14, 2025
3db73f9
Restore original Ruby logic in Node.js implementation and prepare fol…
Copilot Aug 14, 2025
9420d95
Remove Ruby references from Node.js example comments and descriptions
Copilot Aug 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions topics/cluster-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,24 +409,37 @@ async function runExample() {
console.log("Connected to Valkey cluster");

// Get the last counter value, or start from 0
let last = await client.get("__last__");
last = last ? parseInt(last) : 0;
let last = false;
while (!last) {
try {
last = await client.get("__last__");
last = last || 0;
} catch (error) {
console.log(`Error getting counter: ${error.message}`);
await new Promise(resolve => setTimeout(resolve, 1000));
}
}

console.log(`Starting from counter: ${last}`);

// Write keys sequentially with individual SET operations
for (let x = last + 1; x <= 1000000000; x++) {
// Write keys sequentially with verification, following original Ruby logic
for (let x = parseInt(last) + 1; x <= 1000000000; x++) {
try {
// Set the key
await client.set(`foo${x}`, x.toString());

// Update counter every 1000 operations and display progress
if (x % 1000 === 0) {
await client.set("__last__", x.toString());
console.log(`Progress: ${x} keys written`);
}
// Get and verify the value
const value = await client.get(`foo${x}`);
console.log(value);

// Update the counter
await client.set("__last__", x.toString());

// Add delay equivalent to Ruby's sleep 0.1
await new Promise(resolve => setTimeout(resolve, 100));

} catch (error) {
console.log(`Error writing key foo${x}: ${error.message}`);
console.log(`Error: ${error.message}`);
}
}
} catch (error) {
Expand All @@ -439,7 +452,7 @@ async function runExample() {
runExample().catch(console.error);
```

The application writes keys in the format `foo<number>` with their corresponding numeric values using individual `SET` operations. This approach ensures compatibility with cluster deployments where keys may be distributed across different nodes based on their hash slots.
The application writes keys in the format `foo<number>` to `number`, one after the other, following the same logic as the original Ruby example. For each key, it performs a SET operation, immediately verifies the value with a GET operation, updates a counter, and includes a small delay between operations.

The program includes comprehensive error handling to display errors instead of
crashing, so all cluster operations are wrapped in try-catch blocks.
Expand All @@ -455,21 +468,27 @@ discovers the complete cluster topology once it connects to any node.
Now that we have the cluster client instance, we can use it like any other
Valkey client to perform operations across the cluster.

The **counter initialization section** reads a counter so that when we restart the example
The **counter initialization section** reads a counter with retry logic so that when we restart the example
we don't start again with `foo0`, but continue from where we left off.
The counter is stored in Valkey itself using the key `__last__`.

The **main processing loop** sets keys sequentially using individual `SET` operations, updating progress every 1000 keys and displaying any errors that occur.
The **main processing loop** sets keys sequentially, immediately verifies each value with a GET operation, updates the counter after each key, and includes a 100ms delay between operations to match the original Ruby example's timing.

Starting the application produces the following output:

```
node example.js
Connected to Valkey cluster
Starting from counter: 0
Progress: 1000 keys written
Progress: 2000 keys written
Progress: 3000 keys written
1
2
3
4
5
6
7
8
9
^C (I stopped the program here)
```

Expand Down
Loading