Working With Node.js and Redis
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):
, 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());
});
}
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部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-731262/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- node.js應用RedisNode.jsRedis
- Node.js 花盒:Redis 的使用Node.jsRedis
- Working with State
- node.js 連線外網redisNode.jsRedis
- working with ASH and AWR
- Working with Errors in Go 1.13ErrorGo
- Working with Matplotlib on OSX
- 在centos7中安裝redis,並通過node.js操作redisCentOSRedisNode.js
- RxSwift (二) Working with SubjectsSwift
- SCC.369 Working with GPIO
- Get a working copy of a bare repository
- eclipse Working Set設定Eclipse
- node.js 中使用redis實現分散式事務鎖Node.jsRedis分散式
- Node.js 中使用 Redis 來實現定時任務Node.jsRedis
- Vim tips——Working with external commands
- Android working with Volley LibraryAndroid
- ejb object too much ,how server working??ObjectServer
- android TV-Working with Channel DataAndroid
- Probable reasons when Credit check is not working
- nohup not working, another way to get the script run in the background
- HOW TO CHECK IF ASYNCHRONOUS I/O IS WORKING ON LINUXLinux
- 使用Node.js驅動Redis,實現一個訊息佇列!Node.jsRedis佇列
- MAC下安裝Node.js(Express框架)連線redis資料庫MacNode.jsExpress框架Redis資料庫
- Lerning Entity Framework 6 ------ Working with in-memory dataFramework
- [MetalKit]39-Working-with-Particles-in-Metal粒子系統
- Microsoft FIM: Working with Domino Connector v8ROS
- In 10g/11g,working with ASH and AWR
- Effective C#-Working with Strings (翻譯) (轉)C#
- ? 那些能幫我愉快Working的Mac軟體Mac
- [MetalKit]34-Working-with-memory-in-Metal記憶體管理記憶體
- Shale Shaker Units and Decanter Centrifuge Working in Turkey
- OGG4DB2 for IBM i PURGEOLDEXTRACTS not workingDB2IBM
- visual studio 2012 has stopped working
- Chapter 5:Perl One-Liners:Working with Arrays and StringsAPT
- [iOS]The following untracked working tree files would be overwritten by mergeiOS
- SharePoint 2013 workflows stop working (Failed on started.)AI
- Eclipse-建的Working set目錄在這裡Eclipse
- Codeforces 429B Working out:dp【列舉交點】