This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
/** | |
* Calculates the hash/checksum of a string. Default algorithm is MD5. | |
* | |
* @param {String} str | |
* @param {String} algorithm | |
* @return {String} checksum | |
* @api public | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
用node.js开发memcache协议的反向代理服务器 | |
分类 Javascript, 服务器 星期五, 13 五月 2011 penny | |
用node.js开发memcache协议的反向代理服务器 | |
memcache是常用的key-value缓存解决方案,它的协议也被用于nosql数据库tokyo tyrant。 | |
在实际项目中,出于负载均衡等考虑,php、java等客户端需要访问多个memcache,将一个对特定key的请求map到特定的memcache上。但这样就需要在每个客户端配置多个ip地址并实现map的算法,不便于管理和维护。最近正好在学习node.js,于是决定用node.js搭一个node.js的反向代理。对php、java等客户端,实现与memcache相同的协议。将客户端的请求,根据请求的key值分别转发到后端的数个memcache上。 | |
node基于v8和libevent开发,主要思想是用单线程+事件循环(event loop),来实现异步io服务器。这种模式类似于nginx,比起传统的多进程(例如apache的prefork模式)或者线程(例如tomcat等app server),速度更快。 |