Install redis

  1. wget http://download.redis.io/releases/redis-3.0.0.tar.gz

  2. tar xvfz redis-3.0.0.tar.gz

  3. cd redis-3.0.0

  4. make

  5. server and client are placed in src/redis-server and src/redis-cli respectively.

Install node.js redis client

  1. npm install redis

  2. create test script

  3. var redis = require("redis"),
        client = redis.createClient();
    
    client.on("error", function (err) {
        console.log("error event - " + client.host + ":" + client.port + " - " + err);
    });
    
    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) {
        if (err) {
            return console.error("error response - " + err);
        }   
    
        console.log(replies.length + " replies:");
        replies.forEach(function (reply, i) {
            console.log("    " + i + ": " + reply);
        }); 
    });
    
    client.quit(function (err, res) {
        console.log("Exiting from quit command.");
    });
    
    for more info, check
    http://redis.io/
    
  4. for more info, check

    http://redis.io/

    https://github.com/mranney/node_redis

arrow
arrow
    全站熱搜

    Perry Wu 發表在 痞客邦 留言(0) 人氣()