Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connecting to cluster example (#2298)
* Connecting to cluster example * Connecting to cluster example * Making changes according to review * Adding example to Readme.md in alphabetical order * Fixed order of scripts so they are alphabetic. Co-authored-by: Simon Prickett <simon@redis.com> Closes #2281.
- Loading branch information
1 parent
d0bfa77
commit 1eed12e
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This is an example script to connect to a running cluster. | ||
// After connecting to the cluster the code sets and get a value. | ||
|
||
// To setup this cluster you can follow the guide here: | ||
// https://redis.io/docs/manual/scaling/ | ||
// In this guide the ports which are being used are 7000 - 7005 | ||
|
||
|
||
import { createCluster } from 'redis'; | ||
|
||
const cluster = createCluster({ | ||
rootNodes : [ | ||
{ | ||
url : 'redis://127.0.0.1:7001' | ||
}, | ||
{ | ||
url : 'redis://127.0.0.1:7002' | ||
}, | ||
{ | ||
url : 'redis://127.0.0.1:7003' | ||
} | ||
] | ||
}); | ||
|
||
cluster.on('error', (err) => console.log('Redis Client Error', err)); | ||
|
||
await cluster.connect(); | ||
|
||
await cluster.set('hello', 'cluster'); | ||
const value = await cluster.get('hello'); | ||
console.log(value); | ||
|
||
await cluster.quit(); |