File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
This folder contains example scripts showing how to use Node Redis in different scenarios.
4
4
5
- | File Name | Description |
6
- | ------------------------ | ----------------------------------------------------------------------------- |
7
- | ` connect-as-acl-user.js ` | Connect to Redis 6 using an ACL user |
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 |
8
9
| ` lua-multi-incr.js ` | Define a custom lua script that allows you to perform INCRBY on multiple keys |
9
10
10
11
## Contributing
Original file line number Diff line number Diff line change
1
+ // This example shows how to use the blocking LPUSH command.
2
+
3
+ // This code shows how to run with isolation the blPop Command to block the script while waiting for a value to be pushed to the list.
4
+ // The script will be blocked until the LPUSH command is executed.
5
+ // After which we log the list and quit the client.
6
+
7
+ import { createClient , commandOptions } from 'redis' ;
8
+
9
+ async function blockingListPop ( ) {
10
+ const client = createClient ( ) ;
11
+
12
+ await client . connect ( ) ;
13
+
14
+ const keyName = 'keyName' ;
15
+
16
+ const blpopPromise = client . blPop (
17
+ commandOptions ( { isolated : true } ) ,
18
+ keyName ,
19
+ 0
20
+ ) ;
21
+
22
+ await client . lPush ( keyName , 'value' ) ;
23
+
24
+ await blpopPromise ;
25
+
26
+ console . log ( 'blpopPromise resolved' ) ;
27
+ console . log ( keyName ) ;
28
+
29
+ await client . quit ( ) ;
30
+ }
31
+
32
+ blockingListPop ( ) ;
You can’t perform that action at this time.
0 commit comments