Skip to content

Instantly share code, notes, and snippets.

@toritori0318
Created August 9, 2012 09:08
Show Gist options
  • Select an option

  • Save toritori0318/3302530 to your computer and use it in GitHub Desktop.

Select an option

Save toritori0318/3302530 to your computer and use it in GitHub Desktop.
Redisの検証用 expressアプリケーション
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes');
var redis = require('redis');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
// redis nocache
app.get('/redis', function (req, res) {
var redisc = redis.createClient('6379', '127.0.0.1');
redisc.get('aaa', function(){
// quit
redisc.quit();
console.log('redis get')
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('');
});
});
// redis cache
var rediscc = redis.createClient('6379', '127.0.0.1');
app.get('/redis_cache', function (req, res) {
rediscc.get('aaa', function(){
console.log('redis get')
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('');
});
});
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
var mc = require('mc');
var redis = require('redis');
var mcc = new mc.Client();
var memcache = require('memcache');
var memcachec = new memcache.Client();
memcachec.port = 11211;
memcachec.host = 'localhost';
/*
* GET home page.
*/
exports.full = function(req, res){
mcc.connect(function() {
mcc.disconnect();
redisc.get('hoge', function(){
//redisc.quit();
});
});
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('full');
};
exports.mc = function(req, res){
mcc.connect(function() {
console.log('memd get')
mcc.get('key', function(err, hoge) {
console.log('xxx')
console.log(err)
mcc.disconnect();
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('memcache');
});
});
};
exports.redis = function(req, res){
var redisc = redis.createClient('6379', '127.0.0.1');
redisc.get('aaa', function(){
//redisc.quit();
console.log('redis get')
redisc.quit();
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('');
});
};
var redisc = redis.createClient('6379', '127.0.0.1');
exports.redis_cache = function(req, res){
redisc.get('aaa', function(){
//redisc.quit();
console.log('redis get')
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('');
});
};
exports.memcache = function(req, res){
memcachec.connect();
memcachec.get('key', function(error, result){
console.log('memd conn')
//memcachec.close();
res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
res.end('memcache');
});
};
//exports.redis = function(req, res){
// console.log('test1')
// redisfunc(redisc, function() {
// console.log('test4')
// redisc.quit();
//
// })
// res.writeHead(200, {'Content-Type':'text/plain; charset=utf-8'});
// res.end('');
//};
//
//function redisfunc(client, cb) {
// console.log('test2')
// client.get('aaa', function(){
// console.log('test3')
// cb();
// });
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment