node.js的redis模块样例

/**
 * Created with JetBrains WebStorm.
 * User: hexie
 * Date: 12-12-13
 * Time: 上午10:17
 * To change this template use File | Settings | File Templates.
 */

var redis = require('redis');

var redis_ip='127.0.0.1',
    redis_port ='6379';

var i = 1;

var client = redis.createClient(redis_port,redis_ip);
client.on("error", function (err) {
    console.log("Error " + err);
    return false;
});

client.set("string key", "string val", redis.print);
client.hset("hash key", "hashtest 1", "some value", redis.print);
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
client.hkeys("hash key", function (err, replies) {
    console.log(replies.length + " replies:");
    replies.forEach(function (reply, i) {
        console.log("    " + i + ": " + reply);
    });
    client.quit();
});

你可能感兴趣的:(node.js的redis模块样例)