File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ This folder contains example scripts showing how to use Node Redis in different
15
15
| ` search-hashes.js ` | Uses [ RediSearch] ( https://redisearch.io ) to index and search data in hashes |
16
16
| ` search-json.js ` | Uses [ RediSearch] ( https://redisearch.io/ ) and [ RedisJSON] ( https://redisjson.io/ ) to index and search JSON data |
17
17
| ` set-scan.js ` | An example script that shows how to use the SSCAN iterator functionality |
18
+ | ` sorted-set.js ` | Add members with scores to a Sorted Set and retrieve them using the ZSCAN iteractor functionality |
18
19
| ` stream-producer.js ` | Adds entries to a [ Redis Stream] ( https://redis.io/topics/streams-intro ) using the ` XADD ` command |
19
20
| ` stream-consumer.js ` | Reads entries from a [ Redis Stream] ( https://redis.io/topics/streams-intro ) using the blocking ` XREAD ` command |
20
21
| ` time-series.js ` | Create, populate and query timeseries data with [ Redis Timeseries] ( https://redistimeseries.io ) |
Original file line number Diff line number Diff line change
1
+ // Add several values with their scores to a Sorted Set,
2
+ // then retrieve them all using ZSCAN.
3
+
4
+ import { createClient } from 'redis' ;
5
+
6
+ async function addToSortedSet ( ) {
7
+ const client = createClient ( ) ;
8
+ await client . connect ( ) ;
9
+
10
+ await client . zAdd ( 'mysortedset' , [
11
+ {
12
+ score : 99 ,
13
+ value : 'Ninety Nine'
14
+ } ,
15
+ {
16
+ score : 100 ,
17
+ value : 'One Hundred'
18
+ } ,
19
+ {
20
+ score : 101 ,
21
+ value : 'One Hundred and One'
22
+ }
23
+ ] ) ;
24
+
25
+ // Get all of the values/scores from the sorted set using
26
+ // the scan approach:
27
+ // https://redis.io/commands/zscan
28
+ for await ( const memberWithScore of client . zScanIterator ( 'mysortedset' ) ) {
29
+ console . log ( memberWithScore ) ;
30
+ }
31
+
32
+ await client . quit ( ) ;
33
+ }
34
+
35
+ addToSortedSet ( ) ;
You can’t perform that action at this time.
0 commit comments