In my previous post I showed you how to install and use Redis with Node.js. Today I’m going to take that a step further and walk through some of the things you can do with node_redis using Redis’s TTL and EXPIRE commands.
Note: If you haven’t gone through my previous article make sure to do that now as I’ll assume you have Node.js and Redis up and running.
Create a new folder and put a new text file in it called: app.js
Inside the app.js file we will add some simple code to set a value that doesn’t have a time to live (or expiration on it):
CODE:
var redis = require("redis")
, client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.on("connect", runSample);
function runSample() {
// Set a value
client.set("string key", "Hello World", function (err, reply) {
console.log(reply.toString());
});
// Get a value
client.get("string key", function (err, reply) {
console.log(reply.toString());
});
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/301743/viewspace-731262/
,如需转载,请注明出处,否则将追究法律责任。