Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions content/develop/clients/nodejs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ each feature.
| :-- | :-- | :-- |
| [Command case](#command-case) | Lowercase only (eg, `hset`) | Uppercase or camel case (eg, `HSET` or `hSet`) |
| [Command argument handling](#command-argument-handling) | Argument objects flattened and items passed directly | Argument objects parsed to generate correct argument list |
| [Asynchronous command result handling](#async-result) | Callbacks and Promises | Promises only |
| [Asynchronous command result handling](#async-result) | Callbacks and Promises | Promises and Callbacks (via Legacy Mode) |
| [Arbitrary command execution](#arbitrary-command-execution) | Uses the `call()` method | Uses the `sendCommand()` method |

### Techniques
Expand Down Expand Up @@ -85,7 +85,7 @@ to make the connection:
```js
import { createClient } from 'redis';

const client = await createClient();
const client = createClient();
await client.connect(); // Requires explicit connection.
```

Expand Down Expand Up @@ -137,7 +137,7 @@ objects are flattened into sequential key-value pairs:

```js
// These commands are all equivalent.
client.hset('user' {
client.hset('user', {
name: 'Bob',
age: 20,
description: 'I am a programmer',
Expand Down Expand Up @@ -189,7 +189,22 @@ client.get('mykey').then(
`node-redis` supports only `Promise` objects for results, so
you must always use a `then()` handler or the
[`await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
operator to receive them.
operator to receive them, however callbacks are still supported via the legacy mode:

```js
// Promise
await client.set('mykey', 'myvalue');

// Callback
const legacyClient = client.legacy();
legacyClient.set("mykey", "myvalue", (err, result) => {
if (err) {
console.error(err);
} else {
console.log(result);
}
});
```

### Arbitrary command execution

Expand Down Expand Up @@ -339,9 +354,9 @@ command with an explicit method:
client.setnx('bike:1', 'bike');
```

`node-redis` doesn't provide a `SETNX` method but implements the same
functionality with the `NX` option to the [`SET`]({{< relref "/commands/set" >}})
command:
`node-redis` provides a `SETNX` method but due to the command being deprecated the same
functionality can be achieved with the `NX` option to the [`SET`]({{< relref "/commands/set" >}})
command instead:

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