1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-01 16:46:54 +03:00
Files
node-redis/examples/sorted-set.js
Simon Prickett f3462abf33 Updates examples. (#2219)
* Updates examples.

* Added command link for hset.
2022-08-15 08:39:28 -04:00

32 lines
634 B
JavaScript

// Add several values with their scores to a Sorted Set,
// then retrieve them all using ZSCAN.
import { createClient } from 'redis';
const client = createClient();
await client.connect();
await client.zAdd('mysortedset', [
{
score: 99,
value: 'Ninety Nine'
},
{
score: 100,
value: 'One Hundred'
},
{
score: 101,
value: 'One Hundred and One'
}
]);
// Get all of the values/scores from the sorted set using
// the scan approach:
// https://redis.io/commands/zscan
for await (const memberWithScore of client.zScanIterator('mysortedset')) {
console.log(memberWithScore);
}
await client.quit();