Package
Simple Redis
This package is an abstraction layer on redis package to make functions more easy and with async/await usage in NodeJS. It's completelly written in TypeScript. It lets you use it for the Dictionary and also for the pub/sub system.
Installation
npm install redis-simple-client
Usage
const RedisSimpleClient = ;const redis = ;
Usage for dictionary
{ // You can set the URL for the connection, if the third argument is FALSE you will NOT use it for pub/sub. // The prefix helps you using the same redis client for different apps in the same database. // You will have prefix_variable, prefix_variable2, etc. in the redis store. await redis; // Set and get variables. await redis; const variable = redis; console; // outputs: 'value' // Set and get many variables. const variables = var1: 'Testing 1' var2: 'Testing 2' var10: 'Testing 3' ; await redis; let results = redis; console; // Outputs: {var1: 'Testing 1', var2: 'Testing 2'} results = redis; console; // Outpus: {var1: 'Testing 1', var10: 'Testing 3'} // Deleting values await redis; await redis; // Will delete var1 and var10. // Counting and getting keys with patterns. await redis; // Output: ['var2'] await redis; // Output: 1. // Get how many functions you realized. console; / Output get: 2 set: 5 count: 3 // Close the connection. await redis;}
Usage for pub/sub system
{ // You will still be able to use dictionary functions, but with TRUE you will also be able to use pub/sub. await redis; await redis; await redis; // Console will log "Hello!". await redis; await redis;}
All methods
Method | Description |
---|---|
getRedis | Gets original Redis Client. |
getCounts | Gets an object with how many times each function was executed. |
setPrefix | Establishes the prefix for all variables in Redis. |
isConnected | Gets if redis is connected or not. |
resetCounters | Sets all counters to zero. |
connect | Connects to the specified url and sets the prefix. |
get | Gets the entry with the specified key. |
getMany | Gets many entries with the specified keys. |
getWithPattern | Gets all the entries that fit the specified pattern. |
count | Counts how many entries fit the specified pattern. |
set | Sets the entry with the specified key |
setMany | Sets many entries at the same time. |
incrBy | Increases a variable by a specified number. |
decrBy | Decreases a variable by a specified number. |
incr | Executes incrBy with 1. |
decr | Executes decrBy with 1. |
del | Deletes all the specified entries. |
delWithPattern | Deletes all the entries that fit the specified pattern. |
empty | Deletes all entries. |
publish | Sends a message to the specified channel. |
subscribe | Listens to a specified channel. |
unsubscribe | Stops listening to a specified channel. |
close | Closes the connection. |
License
MIT © Matías Puig