File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ // An example explaining how to add values to a set and how to retrive them
2+
3+ import { createClient } from 'redis' ;
4+
5+ const client = createClient ( ) ;
6+ await client . connect ( ) ;
7+
8+ // if you try to add any data of type other than string you will get an error saying `Invalid argument type`
9+ // so before adding make sure the value is of type string or convert it using toString() method
10+ // https://redis.io/commands/sadd/
11+ await client . SADD ( "user1:favorites" , "1" ) ;
12+
13+ // retrieve values of the set defined
14+ // https://redis.io/commands/smembers/
15+ const favorites = await client . SMEMBERS ( "user1:favorites" ) ;
16+ for ( const favorite of favorites ) {
17+ console . log ( favorite ) ;
18+ }
19+
20+ await client . quit ( ) ;
You can’t perform that action at this time.
0 commit comments