Skip to content

Commit

Permalink
Fix node examples (#2345)
Browse files Browse the repository at this point in the history
Fix node example: 1. Use the latest version from npm. 2. Clear up the doc. 3. Comment out the cluster mode in the example, leaving standalone mode by default.

Signed-off-by: ikolomi <ikolomin@amazon.com>
  • Loading branch information
ikolomi authored Sep 23, 2024
1 parent 589f4ee commit aae64fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
25 changes: 3 additions & 22 deletions examples/node/README.MD
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
## Pre-requirements
- GCC
- pkg-config
- protobuf-compiler (protoc)
- openssl
- libssl-dev

Installation for ubuntu:
`sudo apt install -y gcc pkg-config protobuf-compiler openssl libssl-dev python3`

### node 16 (or newer)

This is required for the NodeJS wrapper, and for running benchmarks.

### Install node 16 (or newer)
```
curl -s https://deb.nodesource.com/setup_16.x | sudo bash
apt-get install nodejs npm
npm i -g npm@8
```

## Build
To build GLIDE's Node client, run (on unix based systems):
## Install GLIDE package and build the example
```
cd valkey-glide/node
git submodule update --init --recursive
npm install
rm -rf build-ts
npm run build:release
cd valkey-glide/examples/node
npm install
npx tsc
```

## Run
To run the example:
To run the example (make sure redis/valkey server is available at the address used in the example):
```
cd valkey-glide/examples/node
node index.js
Expand Down
9 changes: 6 additions & 3 deletions examples/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { GlideClient, GlideClusterClient, Logger } from "@valkey/valkey-glide";

async function sendPingToNode() {
async function sendPingToStandAloneNode() {
// When in Redis is in standalone mode, add address of the primary node, and any replicas you'd like to be able to read from.
const addresses = [
{
Expand Down Expand Up @@ -64,6 +64,9 @@ function setConsoleLogger() {
}

setFileLogger();
await sendPingToNode();
setConsoleLogger();
await sendPingToRandomNodeInCluster();
// Enable for standalone mode
await sendPingToStandAloneNode();

// Enable for cluster mode
// await sendPingToRandomNodeInCluster();
2 changes: 1 addition & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"dependencies": {
"@valkey/valkey-glide": "^1.1.0",
"@valkey/valkey-glide": "latest",
"@types/node": "^20.4.8"
},
"devDependencies": {
Expand Down

0 comments on commit aae64fb

Please sign in to comment.