simple.js 748 B

123456789101112131415161718192021222324
  1. var redis = require("redis"),
  2. client = redis.createClient();
  3. client.on("error", function (err) {
  4. console.log("error event - " + client.host + ":" + client.port + " - " + err);
  5. });
  6. client.set("string key", "string val", redis.print);
  7. client.hset("hash key", "hashtest 1", "some value", redis.print);
  8. client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
  9. client.hkeys("hash key", function (err, replies) {
  10. if (err) {
  11. return console.error("error response - " + err);
  12. }
  13. console.log(replies.length + " replies:");
  14. replies.forEach(function (reply, i) {
  15. console.log(" " + i + ": " + reply);
  16. });
  17. });
  18. client.quit(function (err, res) {
  19. console.log("Exiting from quit command.");
  20. });