Pea-redis is based on ioredis, it support async/await usage,it's a further encapsulated and functionally extended functional class. Based on the basic functions of ioredis, it adds operations on objects, and hash, making it easier for Nodejs developers to operate redis.
- set/get Object into/from redis, easy for Nodejs developer to use
- hash set and hash get more easy, only one line of code
$ npm i pea-redis
const peaRedis = require('pea-redis');
peaRedis.connect({}); //see the detail config of ioredis
// set object to the redis
await peaRedis.set('a',{'a':1});
// hash set object to the redis
await peaRedis.hset('obj','b',{b:1});
// set string to the redis
await peaReids.setValue('c', 'this is string');
// get object from the redis
const a = await peaRedis.get('a'); // a = {'a':1}
// hash get object from the redis
const b = await peaRedis.hget('obj', 'b'); // b = {b:1}
// get value from the redis
const c = await peaReids.getValue('c'); // c = this is string;
If you want to delete some cache in the redis, it's more easier than ioredis
For example:
await hdel('obj', 'b');
await del('a');
If you want to use the native method of ioredis, you only need to get the ioredis object and then you can use any ioredis method which you want
For example:
// get ioredis object
const ioRedis = peaRedis.getRedis();
// you can use the native method of ioredis through ioRedis object
ioRedis.set('foo', 'bar');
ioRedis.get('foo', function (err, result) {
console.log(result);
});
...
see more ioRedis function through: https://github.com/luin/ioredis
- connect to the redis
//set up your redis config, port, host, db, password, name, if you do not set up config, it will set default config
connect: function ({config, port, host, db, password, name}){}
//for example
peaRedis.connect({
port: 6379,
host: '127.0.0.1',
db: 'test',
password: 'test',
name: 'test'
})
- set object to the redis
//this only support object type
set: async function () {}
- get value from redis
//this only support String type
get: async function (key) {}
- hash set object to redis
//this only support object type
hset: async function (cacheName, key, value) {}
- get object from redis
hget: async function (cacheName, key) {}
- set string type to redis
//this only support string type
setValue: async function (key, value) {}
- get value from redis
getValue: async function (key) {}
- hash set string type to redis
//this only support string type
hsetValue: async function (cacheName, key, value) {}
- hash get value from redis
hgetValue: async function (cacheName, key) {}
- hash delete value from redis
hgetValue: async function (cacheName, key) {}
- delete value from redis
del: async function (key) {}
- get ioredis object
getRedis: () => {}
I'm happy to receive bug reports, fixes, documentation enhancements, and any other improvements.
And since I'm not a native English speaker, if you find any grammar mistakes in the documentation, please also let me know. :)
TimLiu1 | InCodingNowLiu |
MIT