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 hset/hget Object into/from redis, easy for Nodejs developer to use
- it support async/await usage
$ npm i pea-redis
(async () => {
await peaRedis.set('a',{'a':1});
const a = await peaRedis.get('a'); // a = {'a':1}
})();
(async () => {
await peaReids.setValue('b', 'this is string');
const c = await peaReids.getValue('b'); // b = this is string;
})();
(async () => {
await peaRedis.hset('c','c',{c:1});
const b = await peaRedis.hget('c', 'c'); // c = {c:1}
})();
(async () => {
await peaRedis.hsetValue('d','d','d');
const b = await peaRedis.hgetValue('d', 'd'); // d
})();
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'
})
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