node-redis操作hash

cnpm install node-redis –save

var redis = require('redis');
var client = redis.createClient("6379","127.0.0.1",{auth_pass: "yoursecret"});
client.on("error", function (err) {
    console.log("redis client连接失败",err);
});
client.on('ready', function (res) {
    console.log('client ready');
});
client.on('connect', function () {
    client.hset("hash key", "field 1", "v1", redis.print);
    client.hset(["hash key", "field 2", "v2"], redis.print);
    client.hget("hash key", "field 1", redis.print);
    client.hgetall("hash key",function (err, items) {
        console.log(err,items);
    });
    client.hmset("hash key 2", "field3", "3", "field4", "4");
    client.hgetall("hash key 2", function (err, obj) {
        console.log("hgetall:",obj);
    });
    client.hmset("hash key 3", {
        "012345": "abcdefghij", // NOTE: key and value will be coerced to strings
        "field5": "5"
    });
    client.hgetall("hash key 3", function (err, obj) {
        console.log("hgetall:",obj);
    });
    client.hkeys("hash key", function (err, replies) {
        console.log("hkeys:",err,replies);
        replies.forEach(function (reply, i) {
            console.log("    " + i + ": " + reply);
        });
    });
    //client.quit();
});
client.on("error", function (err) {
    console.log("Error " + err);
});
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值