Skip to content

Commit 82ba699

Browse files
Merge pull request #1667 from PavelPashov/ioredis-migration-docs-suggestions
ioredis migration docs suggestions
2 parents 0d4fe4e + cea3609 commit 82ba699

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

content/develop/clients/nodejs/migration.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ each feature.
4343
| :-- | :-- | :-- |
4444
| [Command case](#command-case) | Lowercase only (eg, `hset`) | Uppercase or camel case (eg, `HSET` or `hSet`) |
4545
| [Command argument handling](#command-argument-handling) | Argument objects flattened and items passed directly | Argument objects parsed to generate correct argument list |
46-
| [Asynchronous command result handling](#async-result) | Callbacks and Promises | Promises only |
46+
| [Asynchronous command result handling](#async-result) | Callbacks and Promises | Promises (but supports callbacks via Legacy Mode) |
4747
| [Arbitrary command execution](#arbitrary-command-execution) | Uses the `call()` method | Uses the `sendCommand()` method |
4848

4949
### Techniques
@@ -85,7 +85,7 @@ to make the connection:
8585
```js
8686
import { createClient } from 'redis';
8787

88-
const client = await createClient();
88+
const client = createClient();
8989
await client.connect(); // Requires explicit connection.
9090
```
9191

@@ -137,7 +137,7 @@ objects are flattened into sequential key-value pairs:
137137

138138
```js
139139
// These commands are all equivalent.
140-
client.hset('user' {
140+
client.hset('user', {
141141
name: 'Bob',
142142
age: 20,
143143
description: 'I am a programmer',
@@ -189,7 +189,22 @@ client.get('mykey').then(
189189
`node-redis` supports only `Promise` objects for results, so
190190
you must always use a `then()` handler or the
191191
[`await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
192-
operator to receive them.
192+
operator to receive them. However, you can still use callbacks with the legacy mode if you need them:
193+
194+
```js
195+
// Promise
196+
await client.set('mykey', 'myvalue');
197+
198+
// Callback
199+
const legacyClient = client.legacy();
200+
legacyClient.set("mykey", "myvalue", (err, result) => {
201+
if (err) {
202+
console.error(err);
203+
} else {
204+
console.log(result);
205+
}
206+
});
207+
```
193208

194209
### Arbitrary command execution
195210

@@ -339,9 +354,8 @@ command with an explicit method:
339354
client.setnx('bike:1', 'bike');
340355
```
341356

342-
`node-redis` doesn't provide a `SETNX` method but implements the same
343-
functionality with the `NX` option to the [`SET`]({{< relref "/commands/set" >}})
344-
command:
357+
`node-redis` provides a `SETNX` method but this command is deprecated. Use the `NX` option to the [`SET`]({{< relref "/commands/set" >}})
358+
command to get the same functionality as `SETNX`:
345359

346360
```js
347361
await client.set('bike:1', 'bike', {'NX': true});

0 commit comments

Comments
 (0)