Code Duplication    Length = 26-29 lines in 2 locations

plumd/plugins/readers/redis.py 1 location

@@ 274-302 (lines=29) @@
271
        return stats
272
273
274
    def connect(self):
275
        """Connect to Redis, returns True if sucessful, False otherwise.
276
277
        :rtype: bool
278
        """
279
        self.log.debug("Redis: connecting: {0}".format(self.addr))
280
        for i in xrange(0, self.retry_cnt):
281
            if self.socket:
282
                self.disconnect()
283
            try:
284
                # create the socket
285
                self.socket = socket.socket(self.sfamily,
286
                                            socket.SOCK_STREAM)
287
                # set timeout for socket operations
288
                self.socket.settimeout(self.timeout)
289
                # connect
290
                self.socket.connect(self.addr)
291
                # log and return
292
                msg = "Redis: connected: {0}"
293
                self.log.info(msg.format(self.addr))
294
                return True
295
            except Exception as e:
296
                # log exception, ensure cleanup is done (disconnect)
297
                msg = "Redis: {0}: connect: excception: {1}"
298
                self.log.error(msg.format(self.addr, e))
299
                # pause before reconnecting
300
                time.sleep(self.retry_time)
301
                self.disconnect()
302
        return False
303
304
305
    def disconnect(self):

plumd/plugins/readers/memcache.py 1 location

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