예제 #1
0
 def remove_node(self, node):
     """Removes `node` from the hash ring and its replicas.
     """
     self.nodes.remove(node)
     for x in xrange(self.replicas):
         crckey = zlib.crc32(b("%s:%d" % (node, x)))
         self.ring.remove(crckey)
         self.sorted_keys.remove(crckey)
예제 #2
0
 def remove_node(self, node):
     """Removes `node` from the hash ring and its replicas.
     """
     self.nodes.remove(node)
     for x in xrange(self.replicas):
         crckey = zlib.crc32(b("%s:%d" % (node, x)))
         self.ring.remove(crckey)
         self.sorted_keys.remove(crckey)
예제 #3
0
 def test_pipeline_script(self):
     pipe = self.client.pipeline()
     for i in range(100):
         pipe.eval("""
             redis.call('set', KEYS[1], ARGV[1])
         """, 1, 'testx%d' % i, i)
     pipe.execute()
     for i in range(100):
         eq_(self.client.get('testx%d' % i), b('%d' % i))
예제 #4
0
 def test_pipeline_script(self):
     pipe = self.client.pipeline()
     for i in range(100):
         pipe.eval("""
             redis.call('set', KEYS[1], ARGV[1])
         """, 1, 'testx%d' % i, i)
     pipe.execute()
     for i in range(100):
         eq_(self.client.get('testx%d' % i), b('%d' % i))
예제 #5
0
    def add_node(self, node):
        """Adds a `node` to the hash ring (including a number of replicas).
        """
        self.nodes.append(node)
        for x in xrange(self.replicas):
            crckey = zlib.crc32(b("%s:%d" % (node, x)))
            self.ring[crckey] = node
            self.sorted_keys.append(crckey)

        self.sorted_keys.sort()
예제 #6
0
    def add_node(self, node):
        """Adds a `node` to the hash ring (including a number of replicas).
        """
        self.nodes.append(node)
        for x in xrange(self.replicas):
            crckey = zlib.crc32(b("%s:%d" % (node, x)))
            self.ring[crckey] = node
            self.sorted_keys.append(crckey)

        self.sorted_keys.sort()
예제 #7
0
    def get_node_pos(self, key):
        """Given a string key a corresponding node in the hash ring is returned
        along with it's position in the ring.

        If the hash ring is empty, (`None`, `None`) is returned.
        """
        if len(self.ring) == 0:
            return [None, None]
        crc = zlib.crc32(b(key))
        idx = bisect.bisect(self.sorted_keys, crc)
        idx = min(idx, (self.replicas * len(self.nodes)) - 1)
        # prevents out of range index
        return [self.ring[self.sorted_keys[idx]], idx]
예제 #8
0
    def get_node_pos(self, key):
        """Given a string key a corresponding node in the hash ring is returned
        along with it's position in the ring.

        If the hash ring is empty, (`None`, `None`) is returned.
        """
        if len(self.ring) == 0:
            return [None, None]
        crc = zlib.crc32(b(key))
        idx = bisect.bisect(self.sorted_keys, crc)
        idx = min(idx, (self.replicas * len(self.nodes)) - 1)
                  # prevents out of range index
        return [self.ring[self.sorted_keys[idx]], idx]
예제 #9
0
 def test_evalsha(self):
     sha = self.client.script_load("""
         return redis.call('set', KEYS[1], ARGV[1])
     """)
     eq_(self.client.evalsha(sha, 1, 'test8', b('8')), b('OK'))
     eq_(self.client.get('test8'), b('8'))
예제 #10
0
 def test_eval(self):
     self.client.eval("""
         return redis.call('set', KEYS[1], ARGV[1])
     """, 1, 'test7', '7')
     eq_(self.client.get('test7'), b('7'))
예제 #11
0
 def test_mset(self):
     self.client.mset({'test4': 4, 'test5': 5, 'test6': 6})
     eq_(self.client.get('test4'), b('4'))
     eq_(self.client.mget('test4', 'test5', 'test6'), [b('4'), b('5'), b('6')])
예제 #12
0
 def test_mget(self):
     self.client.set('test1', 1)
     self.client.set('test2', 2)
     self.client.set('test3', 3)
     eq_(self.client.mget('test1', 'test2', 'test3'), [b('1'), b('2'), b('3')])
예제 #13
0
 def test_evalsha(self):
     sha = self.client.script_load("""
         return redis.call('set', KEYS[1], ARGV[1])
     """)
     eq_(self.client.evalsha(sha, 1, 'test8', b('8')), b('OK'))
     eq_(self.client.get('test8'), b('8'))
예제 #14
0
 def test_eval(self):
     self.client.eval("""
         return redis.call('set', KEYS[1], ARGV[1])
     """, 1, 'test7', '7')
     eq_(self.client.get('test7'), b('7'))
예제 #15
0
 def test_mset(self):
     self.client.mset({'test4': 4, 'test5': 5, 'test6': 6})
     eq_(self.client.get('test4'), b('4'))
     eq_(self.client.mget('test4', 'test5', 'test6'), [b('4'), b('5'), b('6')])
예제 #16
0
 def test_mget(self):
     self.client.set('test1', 1)
     self.client.set('test2', 2)
     self.client.set('test3', 3)
     eq_(self.client.mget('test1', 'test2', 'test3'), [b('1'), b('2'), b('3')])