Skip to content

Commit fdffa23

Browse files
authored
Add command-with-modifiers.js example (#1695)
* Adds TypeScript note and corrects a typo. * Adds command-with-modifiers example. (#1688) * Adds command-with-modifiers example. (#1688) * Adds command-with-modifiers example. (#1688) * Removed callbacks. Co-authored-by: Simon Prickett <[email protected]> Closes #1688.
1 parent 9c3c42f commit fdffa23

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

examples/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
This folder contains example scripts showing how to use Node Redis in different scenarios.
44

5-
| File Name | Description |
6-
|--------------------------|--------------------------------------|
7-
| `connect-as-acl-user.js` | Connect to Redis 6 using an ACL user |
8-
| `blocking-list-pop.js` | Block until an element is pushed to a list |
9-
| `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys |
5+
| File Name | Description |
6+
|-----------------------------|--------------------------------------|
7+
| `connect-as-acl-user.js` | Connect to Redis 6 using an ACL user |
8+
| `blocking-list-pop.js` | Block until an element is pushed to a list |
9+
| `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys |
10+
| `command-with-modifiers.js` | Define a script that allows to run a command with several modifiers |
1011

1112
## Contributing
1213

examples/command-with-modifiers.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Define a custom script that shows example of SET command
2+
// with several modifiers.
3+
4+
import { createClient } from 'redis';
5+
6+
async function commandWithModifiers() {
7+
const client = createClient();
8+
9+
await client.connect();
10+
await client.del('mykey');
11+
12+
let result = await client.set('mykey', 'myvalue', {
13+
EX: 60,
14+
GET: true
15+
}
16+
);
17+
18+
console.log(result); //nil
19+
20+
result = await client.set('mykey', 'newvalue', {
21+
EX: 60,
22+
GET: true
23+
}
24+
);
25+
26+
console.log(result); //myvalue
27+
28+
await client.quit();
29+
}
30+
31+
commandWithModifiers();
32+

0 commit comments

Comments
 (0)