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());
});
}
OK Hello World
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 with an expiration
client.set('string key', 'Hello World', redis.print);
// Expire in 3 seconds
client.expire('string key', 3);
// This timer is only to demo the TTL
// Runs every second until the timeout
// occurs on the value
var myTimer = setInterval(function() {
client.get('string key', function (err, reply) {
if(reply) {
console.log('I live: ' + reply.toString());
} else {
clearTimeout(myTimer);
console.log('I expired');
client.quit();
}
});
}, 1000);
}
Reply: OK I live: Hello World I live: Hello World I live: Hello World I expired
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', redis.print);
// Expire in 3 seconds
client.expire('string key', 3);
// This timer is only to demo the TTL
// Runs every second until the timeout
// occurs on the value
var myTimer = setInterval(function() {
client.get('string key', function (err, reply) {
if(reply) {
console.log('I live: ' + reply.toString());
client.ttl('string key', writeTTL);
} else {
clearTimeout(myTimer);
console.log('I expired');
client.quit();
}
});
}, 1000);
}
function writeTTL(err, data) {
console.log('I live for this long yet: ' + data);
}
Reply: OK I live: Hello World I live for this long yet: 2 I live: Hello World I live for this long yet: 1 I live: Hello World I live for this long yet: 0 I expired
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有