[Node.js]31. Level 7: Redis coming for Node.js, Simple Redis Commands

本文介绍了如何使用Node.js中的Redis模块来创建Redis客户端,并通过该客户端设置和获取Redis中的键值对。首先演示了如何设置一个名为'name'的键并赋值为'Zhentian'。随后展示了如何从Redis中获取另一个键'question'的值。

Let's start practicing using the redis key-value store from our node application. First require the redismodule, and then create a redis client that we can use to call commands on our redis server.

Use the client to set the name key to your name.

var redis = require('redis');
var client = redis.createClient();
client.set("name", "Zhentian");

 

We already have stored a value in the question key. Use the redis client to issue a get command to redis to retrieve and then log the value.

var redis = require('redis');
var client = redis.createClient();
client.get("question", function(err, data){
    console.log(data);    
});

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值