Skip to content

Commit 13867a6

Browse files
committed
2 parents a9f750e + 5c3b5bf commit 13867a6

File tree

2 files changed

+82
-63
lines changed

2 files changed

+82
-63
lines changed

docs/develop/node/gettingstarted/index-gettingstarted.mdx

Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ id: index-gettingstarted
33
title: Getting Started with Node.js
44
sidebar_label: Getting Started
55
slug: /develop/node/gettingstarted
6+
authors: [ajeet, simon]
67
---
78

89
import Tabs from '@theme/Tabs';
@@ -14,99 +15,114 @@ Find tutorials, examples and technical articles that will help you to develop wi
1415

1516
## Introduction
1617

17-
Redis is a great database for use with Node.js. Both Redis Node.js share similar type conventions and threading models, which makes for a very predictable development experience. By pairing Node.js & Redis together you can achieve a scalable and productive development platform.
18+
Redis is a great database for use with Node.js. Both Redis and Node.js share similar type conventions and threading models, which makes for a very predictable development experience. By pairing Node.js and Redis together you can achieve a scalable and productive development platform.
1819

19-
Redis Node.js has two primary clients available [node_redis](https://github.com/NodeRedis/node_redis) and [ioredis](https://github.com/luin/ioredis). Both are available through npm. Both clients have pros and cons, but we generally suggest node_redis, as it has wide support for Redis modules, it is easily extensible and widely used. Ioredis has better integrated support for the Redis Enterprise Cluster API, but this is only relevant if you're specifically using [the Cluster API topology](https://redis.com/redis-enterprise/technology/linear-scaling-redis-enterprise/) instead of the more common Proxy topology. Node_redis’ support for the Cluster API is provided by an additional shim, redis-clustr. Node_redis has built-in support for Redis Enterprise features such as [Active Active geo distribution](https://redis.com/redis-enterprise/technology/active-active-geo-distribution/), allowing you to have one database that spans multiple clusters. Node_redis also supports Redis-on-Flash which enables extending your database into Flash SSD storage for warm values and DRAM for hot values. Nodejs redis enables you to integrate such features.
20+
Redis has two primary Node.js clients which are [node-redis](https://github.com/redis/node-redis) and [ioredis](https://github.com/luin/ioredis). Both are available through npm. We generally suggest using node-redis, as it has wide support for Redis modules, is easily extended, and is widely used.
2021

21-
The Node.js community has built many client libraries that you can find [here](https://redis.io/clients#nodejs).
22-
For your first steps with Node.js and Redis, this article will show how to use the recommended libraries: [ioredis](https://github.com/luin/ioredis) and [node-redis](https://github.com/NodeRedis/node-redis).
22+
Check out a list of Redis clients that the community has built for Node.js [here](https://redis.io/clients#nodejs).
2323

24+
This article shows how to get started with the recommended libraries: [node-redis](https://github.com/redis/node-redis) and [ioredis](https://github.com/luin/ioredis).
2425
<Tabs
25-
defaultValue="ioredis"
26+
defaultValue="node-redis"
2627
values={[
27-
{label: 'IO redis', value: 'ioredis'},
28-
{label: 'Node Redis', value: 'node_redis'},
28+
{label: 'node-redis', value: 'node-redis'},
29+
{label: 'ioredis', value: 'ioredis'},
2930
]}>
30-
<TabItem value="ioredis">
31+
<TabItem value="node-redis">
3132

3233

33-
#### Step 1. Install the ioredis library using `npm` (or `yarn`)
34+
#### Step 1. Install node-redis using `npm` (or `yarn`)
3435

3536
```bash
36-
npm install ioredis
37+
npm install redis
3738
```
3839

3940

40-
#### Step 2. Write your application code
41+
#### Step 2. Write your Application Code
4142

42-
```javascript
43-
const Redis = require("ioredis");
44-
const redis = new Redis(6379, "localhost");
43+
```javascript
44+
import { createClient } from 'redis';
4545

46-
redis.set("mykey", "Hello from io-redis!");
47-
redis.get("mykey", function(err, result){
48-
if (err) { throw err; }
49-
50-
console.log(result);
51-
});
46+
async function nodeRedisDemo () {
47+
try {
48+
const client = createClient();
49+
await client.connect();
5250

53-
// use the promise instead of callback
54-
redis.get("mykey").then(function (result) {
55-
console.log(result);
56-
});
51+
await client.set('mykey', 'Hello from node-redis!');
52+
const myKeyValue = await client.get('mykey');
53+
console.log(myKeyValue);
5754

58-
redis.zadd("vehicles", 0, "car", 0, "bike");
59-
redis.zrange("vehicles", 0, -1, "WITHSCORES").then((res) => console.log(res));
55+
const numAdded = await client.zAdd('vehicles', [
56+
{
57+
score: 4,
58+
value: 'car'
59+
},
60+
{
61+
score: 2,
62+
value: 'bike'
63+
}
64+
]);
65+
console.log(`Added ${numAdded} items.`);
6066

61-
```
67+
for await (const { score, value } of client.zScanIterator('vehicles')) {
68+
console.log(`${value} -> ${score}`);
69+
}
6270

63-
Find more information about Redis & io-redis connections in the "[Redis Connect](https://github.com/redis-developer/redis-connect/tree/master/node.js/ioredis)" repository.
71+
await client.quit();
72+
} catch (e) {
73+
console.error(e);
74+
}
75+
}
76+
77+
nodeRedisDemo();
78+
```
6479

6580
</TabItem>
66-
<TabItem value="node_redis">
81+
<TabItem value="ioredis">
6782

6883

69-
#### Step 1. Install the Redis library using `npm` (or `yarn`)
84+
#### Step 1. Install ioredis using `npm` (or `yarn`)
7085

7186
```bash
72-
npm install redis
87+
npm install ioredis
7388
```
7489

7590

76-
#### Step 2. Write your application code
91+
#### Step 2. Write your Application Code
7792

78-
```javascript
79-
const redis = require("redis");
80-
81-
const client = redis.createClient ({
82-
port : 6379,
83-
host : "localhost"
84-
});
93+
```javascript
94+
const Redis = require('ioredis');
8595

86-
client.set("mykey", "Hello from node-redis!");
87-
client.get("mykey", function(err, result){
88-
if (err) { throw err; }
89-
90-
console.log(result);
91-
});
96+
async function ioredisDemo() {
97+
try {
98+
const client = new Redis();
9299

93-
const vehiclesData = ["vehicles", 4, "car", 2, "bike"];
94-
client.zadd(vehiclesData, function(addError, addResponse) {
95-
if (addError) { throw addError; }
100+
await client.set('mykey', 'Hello from io-redis!');
101+
const myKeyValue = await client.get('mykey');
102+
console.log(myKeyValue);
96103

97-
console.log("added " + addResponse + " items.");
104+
const numAdded = await client.zadd('vehicles', 4, 'car', 2, 'bike');
105+
console.log(`Added ${numAdded} items.`);
98106

99-
const query = ["vehicles", 0, -1];
100-
client.zrange(query, function(rangeError, rangeResponse) {
101-
if (rangeError) {throw rangeError;}
102-
console.log("vehicles", rangeResponse);
103-
});
104-
});
107+
const stream = client.zscanStream('vehicles');
105108

106-
```
109+
stream.on('data', items => {
110+
// items = array of value, score, value, score...
111+
for (let n = 0; n < items.length; n += 2) {
112+
console.log(`${items[n]} -> ${items[n+1]}`);
113+
}
114+
});
107115

108-
Find more information about Redis & node-redis connections in the "[Redis Connect](https://github.com/redis-developer/redis-connect/tree/master/node.js/node-redis)" repository.
116+
stream.on('end', async () => {
117+
await client.quit();
118+
});
119+
} catch (e) {
120+
console.error(e);
121+
}
122+
}
109123

124+
ioredisDemo();
125+
```
110126

111127
</TabItem>
112128
</Tabs>

docs/get-involved/devcember/index-devcember.mdx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ Don't worry if you miss a stream - we'll post them on [YouTube](https://www.yout
2121

2222
We'll be on the [Redis channel on Twitch](https://www.twitch.tv/redisinc) and [YouTube](https://www.youtube.com/c/Redisinc/videos) each working day in December… times will vary and we'll update the schedule below daily, revealing each day's topic as we go.
2323

24-
|Date/Time |Topic |Join Us! |
25-
|----------------------|---------------------------------------------------------|------------------------------------------------------------------|
26-
|Wed 1 Dec, 9am UTC |Welcome to DEVcember, Get Started with Redis in the Cloud|<iframe src="https://www.youtube.com/embed/jf-lwkWUQHg" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>|
27-
|Thu 2 Dec, 10.30am UTC|Up and Running with RedisInsight |<iframe src="https://www.youtube.com/embed/S-CXWP50ewM" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>|
28-
|Fri 3 Dec, Time: TBA |A Beginner's Guide to Redis Lists | [Join us on Twitch](https://www.twitch.tv/redisinc) |
24+
|Date/Time |Topic |Join Us! |
25+
|------------------------|---------------------------------------------------------|------------------------------------------------------------------|
26+
|Wed 1 Dec, 9am UTC |Welcome to DEVcember, Get Started with Redis in the Cloud|<iframe src="https://www.youtube.com/embed/jf-lwkWUQHg" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>|
27+
|Thu 2 Dec, 10.30am UTC |Up and Running with RedisInsight |<iframe src="https://www.youtube.com/embed/S-CXWP50ewM" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>|
28+
|Fri 3 Dec, 8pm UTC |The Redis List goes on and on! |<iframe src="https://www.youtube.com/embed/OjoAmWOPk64" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>|
29+
|Sat 4 / Sun 5 Dec |First weekend hands-on exercise |[Take the challenge on GitHub](https://github.com/redis-developer/devcember/tree/main/challenges/weekend1) |
30+
|Mon 6 Dec, 4:30pm UTC |TBD |[Follow us on Twitch...](https://twitch.tv/redisinc/) |
31+
|Tue 7 Dec, 5pm UTC |TBD |[Follow us on Twitch...](https://twitch.tv/redisinc/) |
2932

3033
## Meet the Team
3134

@@ -51,7 +54,7 @@ We'll also feature guest appearances from other members of the Redis developer r
5154

5255
Be sure to [follow us on Twitch](https://www.twitch.tv/redisinc) to be notified when we're online! We'd also love to see you on the [Redis Discord](https://discord.gg/nrTwSyUvF2), where there's a dedicated channel for all things DEVcember. This is where you can chat with us throughout the day and get help and information about the fun Redis commands / coding challenges we'll post for you to try on weekends.
5356

54-
If you're on Twitter, use hashtag **#RedisDevcember** to join the conversation.
57+
If you're on Twitter, use hashtag **#RedisDEVcember** to join the conversation.
5558

5659
## Learn More
5760

0 commit comments

Comments
 (0)