Hello World with Node.js and Redis

This section shows the basics of creating a JavaScript program using Redis. It is important to understand this foundation since the upcoming examples use the same principles.

Note

In this book, all filenames, function names, and variable names are italicized. Some sentences follow this convention:

  • Create a file called my-filename.js.
  • Execute the function myFunctionName.
  • Create a variable called myVariableName.

Create a file called hello.js with the following code:

var redis = require("redis"); // 1
var client = redis.createClient(); // 2
client.set("my_key", "Hello World using Node.js and Redis"); // 3
client.get("my_key", redis.print); // 4
client.quit(); // 5

Note

Please note that all the code snippets in this book ...

Get Redis Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.