Skip to content

Commit f3e64d8

Browse files
addressed comments
1 parent fddef4f commit f3e64d8

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

examples/set-scan.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/set.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@ import { createClient } from 'redis';
55
const client = createClient();
66
await client.connect();
77

8+
const setName = "user1:favorites";
9+
810
// if you try to add any data of type other than string you will get an error saying `Invalid argument type`
911
// so before adding make sure the value is of type string or convert it using toString() method
1012
// https://redis.io/commands/sadd/
11-
await client.SADD("user1:favorites", "1");
13+
await client.SADD(setName, "1");
1214

1315
// retrieve values of the set defined
1416
// https://redis.io/commands/smembers/
15-
const favorites = await client.SMEMBERS("user1:favorites");
17+
const favorites = await client.SMEMBERS(setName);
1618
for (const favorite of favorites) {
17-
console.log(favorite);
19+
console.log(favorite);
20+
}
21+
22+
// alternate way to retrieve data from set
23+
for await (const member of client.sScanIterator(setName)) {
24+
console.log(member);
1825
}
1926

27+
// another alternate way to retrieve values from the set
28+
// https://redis.io/commands/sscan/
29+
let iCursor = 0;
30+
do {
31+
const { cursor, members } = await client.SSCAN(setName, iCursor);
32+
members.forEach((member) => {
33+
console.log(member);
34+
});
35+
iCursor = cursor;
36+
} while (iCursor !== 0)
37+
38+
2039
await client.quit();

0 commit comments

Comments
 (0)