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
Leibale 05f9f0ee0d WIP
2023-06-07 11:41:23 -04:00

32 lines
631 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);
}
client.destroy();