[toc]
## 引入模块
```
const redis = require('redis');
```
## 创建链接
```
const client = redis.createClient(6379,'localhost');
```
## 监听
```
client.on('error',function(err){
console.log(err);
});
```
## set
```
client.set('home','beijing',function(err,result){
console.log(err); //null
console.log(result); //OK
});
```
p={username:ahhh,age:9}
```
client.hmset('p','username','ahhh','age','9',function(err,result){
console.log(err); //null
console.log(result); //OK
})
```
## 获取key&value
组合成key value的形式
```
client.hkeys('p1',function(err,keys){
console.log(keys);
keys.forEach(function(key,index,keys){
client.hget('p1',key,function(err,value){
console.log(key,value)
})
});
client.hget('p1',key);
})
```
![](https://box.kancloud.cn/34f574dfbe9243337ba8ab509ca9b66d_212x94.png)