redis-node
Version:
A Complete Redis Client for Node.js
30 lines (26 loc) • 1.06 kB
JavaScript
// See ./examples/tour.js
var sys = require("sys");
var redis = require("redis-node");
var client = redis.createClient(); // Create the client
client.select(2); // Select database 2
// Assign the string "world" to the "hello" key.
// You can provide a callback to handle the response from Redis
// that gets asynchronously run upon seeing the response.
var specialChars = "АБВГДЕЁЖЗИЙКЛМНЭЮЯ 你好 大红袍";
var input = specialChars;
// var buf = new Buffer(64)
// , size = buf.write(specialChars, 0, "utf8")
// , input = buf.slice(0, size);
client.set("hello", input, function (err, status) {
if (err) throw err;
console.log(status); // true
});
client.get('hello', function (err, str) {
console.log(str);
console.log(str === specialChars);
});
// We may or may not be connected yet, but that's ok, since // the client queues up any commands.
// Close the connection
setTimeout( function () {
client.close();
}, 1000);