From d409120e5be6e96a3d5d6efef1e4532f48b45182 Mon Sep 17 00:00:00 2001 From: Kalki Date: Thu, 28 Oct 2021 02:24:12 +0530 Subject: [PATCH] Issue # 1697 FIX - creates an example script that shows how to use the SSCAN iterator (#1699) * #1697 fix for set scan example * adds the js file * adds comment * Minor layout and comment adjustment. Co-authored-by: srawat2 Co-authored-by: Simon Prickett Closes #1697. --- examples/README.md | 1 + examples/set-scan.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 examples/set-scan.js diff --git a/examples/README.md b/examples/README.md index 07cbf8b373..2b8fbec927 100644 --- a/examples/README.md +++ b/examples/README.md @@ -8,6 +8,7 @@ This folder contains example scripts showing how to use Node Redis in different | `blocking-list-pop.js` | Block until an element is pushed to a list | | `lua-multi-incr.js` | Define a custom lua script that allows you to perform INCRBY on multiple keys | | `command-with-modifiers.js` | Define a script that allows to run a command with several modifiers | +| `set-scan.js` | An example script that shows how to use the SSCAN iterator functionality | ## Contributing diff --git a/examples/set-scan.js b/examples/set-scan.js new file mode 100644 index 0000000000..3cca05b152 --- /dev/null +++ b/examples/set-scan.js @@ -0,0 +1,19 @@ +// An example script that shows how to use the SSCAN iterator functionality to retrieve the contents of a Redis set. +// Create the set in redis-cli with this command: +// sadd setName a b c d e f g h i j k l m n o p q + +import { createClient } from 'redis'; + +async function setScan() { + const client = createClient(); + await client.connect(); + + const setName = 'setName'; + for await (const member of client.sScanIterator(setName)) { + console.log(member); + } + + await client.quit(); +} + +setScan();