@@ -8,7 +8,7 @@ class Server
8
8
attr_accessor :port
9
9
attr_accessor :weight
10
10
attr_accessor :options
11
-
11
+
12
12
DEFAULTS = {
13
13
# seconds between trying to contact a remote server
14
14
:down_retry_delay => 1 ,
@@ -37,7 +37,7 @@ def initialize(attribs, options = {})
37
37
@sock = nil
38
38
@msg = nil
39
39
end
40
-
40
+
41
41
# Chokepoint method for instrumentation
42
42
def request ( op , *args )
43
43
raise Dalli ::NetworkError , "#{ hostname } :#{ port } is down: #{ @error } #{ @msg } " unless alive?
@@ -65,7 +65,7 @@ def alive?
65
65
66
66
if @last_down_at && @last_down_at + options [ :down_retry_delay ] >= Time . now
67
67
time = @last_down_at + options [ :down_retry_delay ] - Time . now
68
- Dalli . logger . debug { "down_retry_delay not reached for #{ hostname } :#{ port } (%.3f seconds left)" % time }
68
+ Dalli . logger . debug ( "down_retry_delay not reached for #{ hostname } :#{ port } (%.3f seconds left)" % time )
69
69
return false
70
70
end
71
71
@@ -92,7 +92,7 @@ def unlock!
92
92
private
93
93
94
94
def failure!
95
- Dalli . logger . info { "#{ hostname } :#{ port } failed (count: #{ @fail_count } )" }
95
+ Dalli . logger . info ( "#{ hostname } :#{ port } failed (count: #{ @fail_count } )" )
96
96
97
97
@fail_count += 1
98
98
if @fail_count >= options [ :socket_max_failures ]
@@ -101,18 +101,18 @@ def failure!
101
101
sleep ( options [ :socket_failure_delay ] ) if options [ :socket_failure_delay ]
102
102
end
103
103
end
104
-
104
+
105
105
def down!
106
106
close
107
107
108
108
@last_down_at = Time . now
109
109
110
110
if @down_at
111
111
time = Time . now - @down_at
112
- Dalli . logger . debug { "#{ hostname } :#{ port } is still down (for %.3f seconds now)" % time }
112
+ Dalli . logger . debug ( "#{ hostname } :#{ port } is still down (for %.3f seconds now)" % time )
113
113
else
114
114
@down_at = @last_down_at
115
- Dalli . logger . warn { "#{ hostname } :#{ port } is down" }
115
+ Dalli . logger . warn ( "#{ hostname } :#{ port } is down" )
116
116
end
117
117
118
118
@error = $! && $!. class . name
@@ -123,7 +123,7 @@ def down!
123
123
def up!
124
124
if @down_at
125
125
time = Time . now - @down_at
126
- Dalli . logger . warn { "#{ hostname } :#{ port } is back (downtime was %.3f seconds)" % time }
126
+ Dalli . logger . warn ( "#{ hostname } :#{ port } is back (downtime was %.3f seconds)" % time )
127
127
end
128
128
129
129
@fail_count = 0
@@ -163,7 +163,7 @@ def add(key, value, ttl, cas, options)
163
163
write ( req )
164
164
generic_response unless multi?
165
165
end
166
-
166
+
167
167
def replace ( key , value , ttl , options )
168
168
( value , flags ) = serialize ( key , value , options )
169
169
req = [ REQUEST , OPCODES [ multi? ? :replaceq : :replace ] , key . bytesize , 8 , 0 , 0 , value . bytesize + key . bytesize + 8 , 0 , 0 , flags , ttl , key , value ] . pack ( FORMAT [ :replace ] )
@@ -193,7 +193,7 @@ def decr(key, count, ttl, default)
193
193
body = generic_response
194
194
body ? longlong ( *body . unpack ( 'NN' ) ) : body
195
195
end
196
-
196
+
197
197
def incr ( key , count , ttl , default )
198
198
expiry = default ? ttl : 0xFFFFFFFF
199
199
default ||= 0
@@ -204,7 +204,7 @@ def incr(key, count, ttl, default)
204
204
body = generic_response
205
205
body ? longlong ( *body . unpack ( 'NN' ) ) : body
206
206
end
207
-
207
+
208
208
# Noop is a keepalive operation but also used to demarcate the end of a set of pipelined commands.
209
209
# We need to read all the responses at once.
210
210
def noop
@@ -376,7 +376,7 @@ def read(count)
376
376
end
377
377
378
378
def connect
379
- Dalli . logger . debug { "Dalli::Server#connect #{ hostname } :#{ port } " }
379
+ Dalli . logger . debug ( "Dalli::Server#connect #{ hostname } :#{ port } " )
380
380
381
381
begin
382
382
@sock = KSocket . open ( hostname , port , :timeout => options [ :socket_timeout ] )
@@ -401,7 +401,7 @@ def longlong(a, b)
401
401
402
402
REQUEST = 0x80
403
403
RESPONSE = 0x81
404
-
404
+
405
405
RESPONSE_CODES = {
406
406
0 => 'No error' ,
407
407
1 => 'Key not found' ,
@@ -414,7 +414,7 @@ def longlong(a, b)
414
414
0x81 => 'Unknown command' ,
415
415
0x82 => 'Out of memory' ,
416
416
}
417
-
417
+
418
418
OPCODES = {
419
419
:get => 0x00 ,
420
420
:set => 0x01 ,
@@ -440,7 +440,7 @@ def longlong(a, b)
440
440
:auth_request => 0x21 ,
441
441
:auth_continue => 0x22 ,
442
442
}
443
-
443
+
444
444
HEADER = "CCnCCnNNQ"
445
445
OP_FORMAT = {
446
446
:get => 'a*' ,
@@ -470,7 +470,7 @@ def longlong(a, b)
470
470
def need_auth?
471
471
@options [ :username ] || ENV [ 'MEMCACHE_USERNAME' ]
472
472
end
473
-
473
+
474
474
def username
475
475
@options [ :username ] || ENV [ 'MEMCACHE_USERNAME' ]
476
476
end
@@ -480,7 +480,7 @@ def password
480
480
end
481
481
482
482
def sasl_authentication
483
- Dalli . logger . info { "Dalli/SASL authenticating as #{ username } " }
483
+ Dalli . logger . info ( "Dalli/SASL authenticating as #{ username } " )
484
484
485
485
# negotiate
486
486
req = [ REQUEST , OPCODES [ :auth_negotiation ] , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] . pack ( FORMAT [ :noop ] )
0 commit comments