ntt-redis
v1.0.1
Published
[](https://www.npmjs.com/package/ntt-redis)
Downloads
4
Readme
ntt-redis
##基于 think-redis 1.0.7 开发, 加入 hset/hget/hgetall 方法
Install
npm install --save ntt-redis
How to Use
default options
You can find all the config options at https://github.com/luin/ioredis/blob/master/lib/redis.js
const defaultConfig = {
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
password: '',
};
usage
import Redis from '../index';
let redisInst = new Redis(config);
// set key
let s1 = await redisInst.set('name2', 'lushijie'); // never expire
let s2 = await redisInst.set('name3', 'lushijie', 3000); // milliseconds
let s3 = await redisInst.set('name4', 'lushijie', 'EX', 5); //seconds
let s4 = await redisInst.set('name5', 'lushijie', 'PX', 10000); //milliseconds
// get key's value
let g1 = await redisInst.get('name2');
// set hash key
let h1 = await redisInst.hset('hash_name', 'one', {'name':'lushijie', 'age':'18'});
let h2 = await redisInst.hset('hash_name', 'two', {'name':'lushijie', 'age':'19'});
let h3 = await redisInst.hset('hash_name', 'three', ['one', 'two']);
// get hash key value
let hg1 = await redisInst.hget('hash_name', 'one');
let hg2 = await redisInst.hget('hash_name');
let hg3 = await redisInst.hgetall('hash_name');
// delete key
let d1 = await redisInst.delete(key);
// add event listener, supported events see at https://github.com/luin/ioredis
redisInst.on('connect', function() {
// todo
});
// increase 1, if key not exist, set key's value eq 0 and then increase 1
await redisInst.increase(key);
// decrease 1, if key not exist, set key's value eq 0 then decrease 1
await redisInst.decrease(key);