nodejs之memcached连接池
来源:互联网 发布:成都程序员工资水平 编辑:程序博客网 时间:2024/06/07 01:31
nodejs之memcached连接池:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* memcached 连接池
**/
var
options = {
//'host': ['localhost:11211'],
'host'
:
'localhost:11211'
,
'connectionLimit'
:
'2'
,
'timeout'
: 50000
};
var
poolModule = require(
'generic-pool'
);
console.log(
"init pool for memcached start.."
);
var
pool = poolModule.Pool({
name :
'memcached'
,
create :
function
(callback){
var
Memcached = require(
'memcached'
);
memcached =
new
Memcached(options.host, {debug:
true
});
memcached.on(
"failure"
,
function
(detail) {})
.on(
'connect'
,
function
(detail) {})
.on(
'reconnect'
,
function
(detail) {})
.on(
'reconnecting'
,
function
(detail) {})
.on(
'remove'
,
function
(detail) {})
.on(
'issue'
,
function
(detail) {});
callback(
null
, memcached);
},
destory :
function
(client){
if
(client.connected){
try
{
client.end();
}
catch
(err){
console.log(
'Failed to memcached connection: '
+ err);
}
}
},
max : options.connectionLimit,
idleTimeoutMillis : options.timeout,
log :
false
});
console.log(
"init pool for memcached end...."
);
exports.set =
function
(key, val, expire, callback){
pool.acquire(
function
(err, client){
if
(err){
callback(err);
return
;
}
if
(!expire) expire = 172800;
client.set(key, val, expire,
function
(err, data){
pool.release(client);
if
(err){
callback(err,
null
);
return
;
}
callback(err, data);
});
});
};
exports.get =
function
(key, callback){
pool.acquire(
function
(err, client){
if
(err){
callback(err);
return
;
}
client.get(key,
function
(err, data){
pool.release(client);
if
(err){
callback(err,
null
);
return
;
}
callback(err, data);
});
});
};
阅读全文
0 0
- nodejs之memcached连接池
- nodejs之mysql连接池
- nodejs之pool连接池
- nodejs连接mysql之使用连接池pool
- nodejs mysql 连接池
- memcached客户端和连接池
- Memcached源码分析之网络连接建立
- Memcached源码解析之连接队列
- nodejs使用redis连接池
- nodejs连接池连接mysql数据库
- memcached--连接
- libmemcached支持连接池访问memcached
- nodejs + redis/mysql 连接池问题
- nodejs + redis/mysql 连接池问题
- nodejs + redis/mysql 连接池问题
- memcached之memcached介绍
- memcached之memcached安装
- memcached之memcached介绍
- 从零开始入门密码学_2
- 文件操作
- Java中的Map集合
- PHP中大括号的用法
- 自动化运维平台saltstack的使用与搭建
- nodejs之memcached连接池
- POJ
- java 枚举——java中枚举的运用和使用场景
- oozie框架案例之多Action执行
- php变量存在引号导致语句出错无法执行——解决办法
- ros vio2 + ps4 eye
- 一个字符串为空时再去连接另一个字符(串)
- 硬币游戏2 (SG)
- loadrunner函数之web_url,web_submit_data参数