ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Working With Node.js and Redis

Working With Node.js and Redis

原创 Linux操作系统 作者:jieforest 时间:2012-05-28 12:55:36 0 删除 编辑
In my previous post I showed you how to install and use Redis with Node.js. Today I’m going to take that a step further and walk through some of the things you can do with node_redis using Redis’s TTL and EXPIRE commands.

Note: If you haven’t gone through my previous article make sure to do that now as I’ll assume you have Node.js and Redis up and running.

Create a new folder and put a new text file in it called: app.js

Inside the app.js file we will add some simple code to set a value that doesn’t have a time to live (or expiration on it):

CODE:

var redis = require("redis")
    , client = redis.createClient();

client.on("error", function (err) {
    console.log("Error " + err);
});

client.on("connect", runSample);

function runSample() {
    // Set a value
    client.set("string key", "Hello World", function (err, reply) {
        console.log(reply.toString());
    });
    // Get a value
    client.get("string key", function (err, reply) {
        console.log(reply.toString());
    });
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/301743/viewspace-731262/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    443
  • 访问量
    510263