redis node 常用命令

命令窗口

flushall //清空全库

keys * //查看所有 HMSET user1 name liujinyu age 25 //哈希 添加多个值 HSET user1 sex man //哈希 添加一个值 HGETALL user1 //获取对应值

node redis

读取一个Key的所有 哈希键/值,多用于JSON对象读取

这两个命令即是在NodeJS中存取JSON对象的关键,

    //写入JavaScript(JSON)对象
    client.hmset('userid:1', { username: '刘金宇1', password: '斯蒂芬森1' }, function(err) {
        console.log(err)
    })
    //写入JavaScript(JSON)对象
    client.hmset('userid:2', { username: '刘金宇2', password: '斯蒂芬森2' }, function(err) {
        console.log(err)
    })

    //读取JavaScript(JSON)对象
    client.keys('userid:*', function(err, keys) {

        for(var i = keys.length-1;i>=0;i--){
            client.hgetall(keys[i],function(err,reply){
                console.log(reply)
            })
        }
    })

  

原文地址:https://www.cnblogs.com/liujinyu/p/5302245.html