@@ 245-273 (lines=29) @@ | ||
242 | return stats |
|
243 | ||
244 | ||
245 | def connect(self): |
|
246 | """Connect to Redis, returns True if sucessful, False otherwise. |
|
247 | ||
248 | :rtype: bool |
|
249 | """ |
|
250 | self.log.debug("Redis: connecting: {0}".format(self.addr)) |
|
251 | for i in xrange(0, self.retry_cnt): |
|
252 | if self.socket: |
|
253 | self.disconnect() |
|
254 | try: |
|
255 | # create the socket |
|
256 | self.socket = socket.socket(socket.AF_INET, |
|
257 | socket.SOCK_STREAM) |
|
258 | # set timeout for socket operations |
|
259 | self.socket.settimeout(self.timeout) |
|
260 | # connect |
|
261 | self.socket.connect(self.addr) |
|
262 | # log and return |
|
263 | msg = "Redis: connected: {0}" |
|
264 | self.log.info(msg.format(self.addr)) |
|
265 | return True |
|
266 | except Exception as e: |
|
267 | # log exception, ensure cleanup is done (disconnect) |
|
268 | msg = "Redis: {0}: connect: excception: {1}" |
|
269 | self.log.error(msg.format(self.addr, e)) |
|
270 | # pause before reconnecting |
|
271 | time.sleep(self.retry_time) |
|
272 | self.disconnect() |
|
273 | return False |
|
274 | ||
275 | ||
276 | def disconnect(self): |
@@ 186-214 (lines=29) @@ | ||
183 | return stats |
|
184 | ||
185 | ||
186 | def connect(self): |
|
187 | """Connect to memcached, returns True if sucessful, False otherwise. |
|
188 | ||
189 | :rtype: bool |
|
190 | """ |
|
191 | self.log.debug("Memcached: connecting: {0}".format(self.addr)) |
|
192 | for i in xrange(0, self.retry_cnt): |
|
193 | if self.socket: |
|
194 | self.disconnect() |
|
195 | try: |
|
196 | # create the socket |
|
197 | self.socket = socket.socket(socket.AF_INET, |
|
198 | socket.SOCK_STREAM) |
|
199 | # set timeout for socket operations |
|
200 | self.socket.settimeout(self.timeout) |
|
201 | # connect |
|
202 | self.socket.connect(self.addr) |
|
203 | # log and return |
|
204 | msg = "Memcached: connected: {0}" |
|
205 | self.log.info(msg.format(self.addr)) |
|
206 | return True |
|
207 | except Exception as e: |
|
208 | # log exception, ensure cleanup is done (disconnect) |
|
209 | msg = "Memcached: {0}: connect: excception: {1}" |
|
210 | self.log.error(msg.format(self.addr, e)) |
|
211 | # pause before reconnecting |
|
212 | time.sleep(self.retry_time) |
|
213 | self.disconnect() |
|
214 | return False |
|
215 | ||
216 | ||
217 | def disconnect(self): |