1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-03 04:01:40 +03:00
Files
node-redis/examples/sorted-set.js
Simon Prickett ac7d50c731 Added sorted set example. (#2005)
* Added sorted set example.

* Update sorted-set.js

Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
2022-02-24 18:04:06 -05:00

36 lines
737 B
JavaScript

// Add several values with their scores to a Sorted Set,
// then retrieve them all using ZSCAN.
import { createClient } from 'redis';
async function addToSortedSet() {
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();
}
addToSortedSet();