| @@ 169-194 (lines=26) @@ | ||
| 166 | ||
| 167 | return stats |
|
| 168 | ||
| 169 | def connect(self): |
|
| 170 | """Connect to memcached, returns True if sucessful, False otherwise. |
|
| 171 | ||
| 172 | :rtype: bool |
|
| 173 | """ |
|
| 174 | #self.log.debug("Memcached: connecting: {0}".format(self.addr)) |
|
| 175 | if self.socket: |
|
| 176 | self.disconnect() |
|
| 177 | try: |
|
| 178 | # create the socket |
|
| 179 | self.socket = socket.socket(self.sfamily, |
|
| 180 | socket.SOCK_STREAM) |
|
| 181 | # set timeout for socket operations |
|
| 182 | self.socket.settimeout(self.timeout) |
|
| 183 | # connect |
|
| 184 | self.socket.connect(self.addr) |
|
| 185 | # log and return |
|
| 186 | msg = "Memcached: connected: {0}" |
|
| 187 | self.log.info(msg.format(self.addr)) |
|
| 188 | return True |
|
| 189 | except Exception as e: |
|
| 190 | # log exception, ensure cleanup is done (disconnect) |
|
| 191 | msg = "Memcached: {0}: connect: excception: {1}" |
|
| 192 | self.log.error(msg.format(self.addr, e)) |
|
| 193 | return False |
|
| 194 | return False |
|
| 195 | ||
| 196 | def disconnect(self): |
|
| 197 | """Severe the memcached connection.""" |
|
| @@ 312-333 (lines=22) @@ | ||
| 309 | self.buff_end = -1 |
|
| 310 | self.buff_i = -1 |
|
| 311 | ||
| 312 | def connect(self): |
|
| 313 | """Connect to Redis. |
|
| 314 | ||
| 315 | :raises RedisError: for any socket related exceptions |
|
| 316 | :rtype: Exception or None |
|
| 317 | """ |
|
| 318 | #self.log.debug("RedisNet: connect") |
|
| 319 | if self.sock: |
|
| 320 | self.disconnect() |
|
| 321 | try: |
|
| 322 | # create the socket |
|
| 323 | self.sock = socket.socket(self.sfamily, socket.SOCK_STREAM) |
|
| 324 | # set timeout for socket operations |
|
| 325 | self.sock.settimeout(self.timeout) |
|
| 326 | self.sock.connect(self.addr) |
|
| 327 | msg = "RedisNet: connected: {0}" |
|
| 328 | self.log.info(msg.format(self.addr)) |
|
| 329 | except Exception as e: |
|
| 330 | msg = "RedisNet: Exception during connect: {0}" |
|
| 331 | self.log.error(msg.format(e)) |
|
| 332 | raise RedisError(msg.format(e)) |
|
| 333 | return True |
|
| 334 | ||
| 335 | def disconnect(self): |
|
| 336 | """Disconnect from Redis. |
|