예제 #1
0
파일: pymemc.py 프로젝트: Alesh/pymemc
    def close(self):
        """
        Close the connections to all servers.

        >>> c = Client('localhost:11211')
        >>> c.close()
        """
        self.quit()
        for r in self.hash.all_nodes():
            with connpool.pooled_connection(r) as sock:
                sock.close()
예제 #2
0
파일: pymemc.py 프로젝트: Alesh/pymemc
    def _per_host_version(self, cpool, rmap):
        with connpool.pooled_connection(cpool) as sock:
            socksend(sock, _qnsv(M._version))
            (_, _, keylen, _, _, status, bodylen, _, _, extra) = sockresponse(sock)

            if status != R._no_error:
                raise MemcachedError("%d: %s" % (status, extra))

            version_string = struct.unpack('!%ds' % ((bodylen-keylen), ), extra)[0]
            host_key = tuple(sock.getpeername())
            rmap[host_key] = version_string
예제 #3
0
파일: pymemc.py 프로젝트: Alesh/pymemc
    def quit(self):
        """
        The quit command closes the remote socket.

        >>> c = Client('localhost:11211')
        >>> c.quit()
        True
        """
        for r in self.hash.all_nodes():
            with connpool.pooled_connection(r) as sock:
                socksend(sock, _qnsv(M._quit))
                (_, _, _, _, _, status, _, _, _, extra) = sockresponse(sock)
                if status != R._no_error:
                    raise MemcachedError("%d: %s" % (status, extra))
        return True
예제 #4
0
파일: pymemc.py 프로젝트: Alesh/pymemc
 def _per_host_stats(self, cpool, rmap):
     host_stats = {}
     with connpool.pooled_connection(cpool) as sock:
         socksend(sock, _qnsv(M._stat))
         while 1:
             (_, _, keylen, _, _, status, bodylen, _, _, extra) = sockresponse(sock)
             if status != R._no_error:
                 raise MemcachedError("%d: %s" % (status, extra))
             if keylen == 0: # last response?
                 host_key = tuple(sock.getpeername())
                 rmap[host_key] = host_stats
                 break
             else:
                 key, value = struct.unpack('!%ds%ds' % (keylen, (bodylen-keylen)), extra)
                 host_stats[key] = value
예제 #5
0
파일: pymemc.py 프로젝트: Alesh/pymemc
    def noop(self):
        """
        The noop command Flushes outstanding getq/getkq's and can be used
        as a keep-alive.

        >>> c = Client('localhost:11211')
        >>> c.noop()
        True
        """
        for r in self.hash.all_nodes():
            with connpool.pooled_connection(r) as sock:
                socksend(sock, _qnsv(M._noop))
                (_, _, _, _, _, status, _, _, _, extra) = sockresponse(sock)
                if status != R._no_error:
                    raise MemcachedError("%d: %s" % (status, extra))
        return True
예제 #6
0
파일: pymemc.py 프로젝트: Alesh/pymemc
    def flush_all(self, expire=0):
        """
        The flush command flushes all data the DB. Optionally this will happen
        after `expire` seconds.

        >>> c = Client('localhost:11211')
        >>> c.flush_all()
        True
        """
        for r in self.hash.all_nodes():
            with connpool.pooled_connection(r) as sock:
                socksend(sock, _f(M._flush, expire))
                (_, _, _, _, _, status, _, _, _, extra) = sockresponse(sock)
                if status != R._no_error:
                    raise MemcachedError("%d: %s" % (status, extra))
        return True
예제 #7
0
파일: pymemc.py 프로젝트: Alesh/pymemc
 def sock4key(self, key):
     r = self.hash.get_node(key)
     with connpool.pooled_connection(r) as sock:
         yield sock