You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/develop/node/gettingstarted/index-gettingstarted.mdx
+73-57Lines changed: 73 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@ id: index-gettingstarted
3
3
title: Getting Started with Node.js
4
4
sidebar_label: Getting Started
5
5
slug: /develop/node/gettingstarted
6
+
authors: [ajeet, simon]
6
7
---
7
8
8
9
importTabsfrom'@theme/Tabs';
@@ -14,99 +15,114 @@ Find tutorials, examples and technical articles that will help you to develop wi
14
15
15
16
## Introduction
16
17
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.
18
19
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.
20
21
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).
23
23
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).
24
25
<Tabs
25
-
defaultValue="ioredis"
26
+
defaultValue="node-redis"
26
27
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'},
29
30
]}>
30
-
<TabItemvalue="ioredis">
31
+
<TabItemvalue="node-redis">
31
32
32
33
33
-
#### Step 1. Install the ioredis library using `npm` (or `yarn`)
34
+
#### Step 1. Install node-redis using `npm` (or `yarn`)
34
35
35
36
```bash
36
-
npm install ioredis
37
+
npm install redis
37
38
```
38
39
39
40
40
-
#### Step 2. Write your application code
41
+
#### Step 2. Write your Application Code
41
42
42
-
```javascript
43
-
constRedis=require("ioredis");
44
-
constredis=newRedis(6379, "localhost");
43
+
```javascript
44
+
import { createClient } from'redis';
45
45
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
+
asyncfunctionnodeRedisDemo () {
47
+
try {
48
+
constclient=createClient();
49
+
awaitclient.connect();
52
50
53
-
// use the promise instead of callback
54
-
redis.get("mykey").then(function (result) {
55
-
console.log(result);
56
-
});
51
+
awaitclient.set('mykey', 'Hello from node-redis!');
forawait (const { score, value } ofclient.zScanIterator('vehicles')) {
68
+
console.log(`${value} -> ${score}`);
69
+
}
62
70
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
+
awaitclient.quit();
72
+
} catch (e) {
73
+
console.error(e);
74
+
}
75
+
}
76
+
77
+
nodeRedisDemo();
78
+
```
64
79
65
80
</TabItem>
66
-
<TabItemvalue="node_redis">
81
+
<TabItemvalue="ioredis">
67
82
68
83
69
-
#### Step 1. Install the Redis library using `npm` (or `yarn`)
84
+
#### Step 1. Install ioredis using `npm` (or `yarn`)
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.
0 commit comments