redis-clients
redis client factories for nodejs
Requirements
Installation
$ npm install --save redis-clients
Usage
//initialize redis-clients with default optionsconst redis = options; //obtain normal redis clientconst client = redis; //set dataclient;client;client; //count keys based on patternredis; //count keys based on patternredis; //obtain pub/sub clientsconst publisher subscriber = redis; //clear users dataredisclear'users*' { ...}; //clear all dataredisclear{ ...}; //reset and quit all clientsredis;
Options
prefix:String
- redis key prefix. default tor
separator:String
- redis key separator. default to:
redis:Object|String
- redis connections options or connection string.
To initialize redis
with custom options use
const redis = prefix:'q' separator:'-' redis: port: 6379 host: '127.0.0.1' ; ... or const redis = prefix:'q' separator:'-' redis: 'redis://localhost:6379';
API
createClient([options:Object]):Object
Create a new instance of redis client
const redis = ;const client = redis; ...
pubsub():{publisher:Object, subscriber:Object}
Obtain existing or create new instances of publisher and subscriber redis clients
const redis = ;const publisher subscriber = redis; ...
client():Object
Obtain existing or create new instance of redis client
const redis = ;const client = redis; ...
multi():Object
Create new instance of redis multi command object
const redis = ;const client = redis; ...
info(done:Function):Object
Obtain informations of the current redis server.
const redis = ;redis;
key(...args):String
Build redis storage key using prefix
and separator
options
const redis = ; //generate random keyconst key = redis;toexist;tohavelength2; const key = redis;tobe; const key = redis;tobe; const key = redis;tobe; ...
clear(pattern:String,[done:Function]):Array[String>
clear data using specified pattern. if pattern not provided all data will be deleted
const redis = ; //clear all dataredisclear{ ...}; //clear all key 'users*'redisclear'users'{ ...}; ...
reset()
Reset current state of redis
const redis = ;redis; ...
count(pattern:String, done:Function)
Count(or obtain size) of keys based on the specified pattern. If no pattern specified all keys will be counted.
const redis = ;redis; ...
Testing
-
Clone this repository
-
Install all development dependencies
$ npm install
- Then run test
$ npm test
Contribute
It will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.
Licence
The MIT License (MIT)
Copyright (c) 2017 lykmapipo & Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.