File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,9 @@ if (!cache) {
24
24
25
25
module . exports = function ( opt ) {
26
26
/**
27
- * 这里像这样写的目的主要是为了进行测试
28
- 因为在使用sinon.js时, 如果你exports的是一个function,你就无法进行stub,
29
- */
27
+ * 这里像这样写的目的主要是为了进行测试
28
+ 因为在使用sinon.js时, 如果你exports的是一个function,你就无法进行stub,
29
+ */
30
30
return module . exports . getCmem ( opt ) ;
31
31
} ;
32
32
@@ -57,14 +57,29 @@ module.exports.getCmem = function(opt) {
57
57
return null ;
58
58
}
59
59
60
+ return fromCache ( opt ) ;
61
+ } ;
62
+
63
+ const fromCache = ( opt ) => {
60
64
const key = [ opt . modid , opt . cmd , opt . host ] . join ( ':' ) ;
61
65
62
66
if ( ! cache [ key ] ) {
63
67
const Memcached = require ( 'memcached' ) ;
64
- cache [ key ] = queueWrap ( new Memcached ( opt . host , opt ) ) ;
68
+ const poolSize = opt . poolSize || 1 ;
69
+ const queueWrapList = [ ] ;
70
+ const option = Object . assign ( { } , opt , {
71
+ poolSize : 1
72
+ } ) ;
73
+ for ( let i = 0 ; i < poolSize ; i ++ ) {
74
+ queueWrapList . push ( queueWrap ( new Memcached ( opt . host , option ) ) ) ;
75
+ }
76
+ queueWrapList . curr = 0 ;
77
+ cache [ key ] = queueWrapList ;
78
+ } else {
79
+ cache [ key ] . curr = ( cache [ key ] . curr + 1 ) % cache [ key ] . length ;
65
80
}
66
81
67
- return cache [ key ] ;
82
+ return cache [ key ] [ cache [ key ] . curr ] ;
68
83
} ;
69
84
70
85
You can’t perform that action at this time.
0 commit comments