//npm install redis
//首先加载node_redis模块
var redis = require(‘redis‘);
// 创建redis连接
var client = redis.createClient(‘6379‘, ‘127.0.0.1‘);
client.on("error", function(err) {
console.log("Error " + err);
});
client.set(‘foo‘, ‘bar‘, function() {
client.get(‘foo‘, function(error, fooValue) {
console.log(fooValue);
});
});
client.append(‘foo‘, ‘CCC‘, function() {
client.get(‘foo‘, function(error, value) {
console.log(value);
});
});
// 通过key获取值
exports.get = function(key, callback) {
client.get(key, function(error, value) {
console.log(value);
callback(value);
});
}
// 设定key的值
exports.set = function(key, value) {
client.set(key, value, function() {
});
}
// key追加值
exports.append = function(key, value) {
client.append(key, value, function() {
});
}
时间: 2024-10-26 08:36:53