Code Duplication    Length = 21-26 lines in 2 locations

plumd/readers/memcache.py 1 location

@@ 167-192 (lines=26) @@
164
165
        return stats
166
167
    def connect(self):
168
        """Connect to memcached, returns True if sucessful, False otherwise.
169
170
        :rtype: bool
171
        """
172
        self.log.debug("Memcached: connecting: {0}".format(self.addr))
173
        if self.socket:
174
            self.disconnect()
175
        try:
176
            # create the socket
177
            self.socket = socket.socket(self.sfamily,
178
                                        socket.SOCK_STREAM)
179
            # set timeout for socket operations
180
            self.socket.settimeout(self.timeout)
181
            # connect
182
            self.socket.connect(self.addr)
183
            # log and return
184
            msg = "Memcached: connected: {0}"
185
            self.log.info(msg.format(self.addr))
186
            return True
187
        except Exception as exc:
188
            # log exception, ensure cleanup is done (disconnect)
189
            msg = "Memcached: {0}: connect: excception: {1}"
190
            self.log.error(msg.format(self.addr, exc))
191
            return False
192
        return False
193
194
    def disconnect(self):
195
        """Severe the memcached connection."""

plumd/readers/redis.py 1 location

@@ 305-325 (lines=21) @@
302
        self.buff_end = -1
303
        self.buff_i = -1
304
305
    def connect(self):
306
        """Connect to Redis.
307
308
        :raises RedisError: for any socket related exceptions
309
        :rtype: Exception or None
310
        """
311
        if self.sock:
312
            self.disconnect()
313
        try:
314
            # create the socket
315
            self.sock = socket.socket(self.sfamily, socket.SOCK_STREAM)
316
            # set timeout for socket operations
317
            self.sock.settimeout(self.timeout)
318
            self.sock.connect(self.addr)
319
            msg = "RedisNet: connected: {0}"
320
            self.log.info(msg.format(self.addr))
321
        except Exception as exc:
322
            msg = "RedisNet: Exception during connect: {0}"
323
            self.log.error(msg.format(exc))
324
            raise RedisError(msg.format(exc))
325
        return True
326
327
    def disconnect(self):
328
        """Disconnect from Redis.