Skip to content

TimLiu1/pea-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm package

Features

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.

  1. set/get hset/hget Object into/from redis, easy for Nodejs developer to use
  2. it support async/await usage

Quick Start

Install

$ npm i pea-redis

Basic Usage

set/get Object

(async () => {
await peaRedis.set('a',{'a':1});
const a = await peaRedis.get('a'); // a = {'a':1} 
})();

set/get Value

(async () => {
 await peaReids.setValue('b', 'this is string');
const c = await peaReids.getValue('b'); // b = this is string;
})();

hset/hget Object

(async () => {
await peaRedis.hset('c','c',{c:1});
const b = await peaRedis.hget('c', 'c'); // c = {c:1}
})();

hset/hget Value

(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

Function and params Details:

  1. 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'
})

Join in!

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. :)

Contributors

TimLiu1

InCodingNowLiu

License

MIT

About

a middle for operating redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published