Beispiel #1
0
    def execute(self, *args, shard_key=None, sock=None):
        """ Execute arbitrary redis command.

        :param args:
        :type args: list, int, float

        :param shard_key: (optional)
            Should be set to the key name you try to work with.
            Can not be used if sock is set.
        :type shard_key: string

        :param sock: (optional)
            The string representation of a socket, the command should be executed against.
            For example: "testhost_6379"
            Can not be used if shard_key is set.
        :type sock: string

        :return: result, exception
        """
        if not bool(shard_key) != bool(sock):
            raise PyRedisError('Ether shard_key or sock has to be provided')
        if not sock:
            sock = self._map[slot_from_key(shard_key)]
        conn = self._conns[sock]
        try:
            if not self._bulk:
                return self._execute_basic(conn=conn, *args)
            else:
                self._execute_bulk(conn=conn, *args)
        except PyRedisConnError as err:
            self.close()
            raise err
Beispiel #2
0
 def test_slot_from_key(self):
     key = u'blarg'.encode()
     result = slot_from_key(key)
     self.assertEqual(5534, result)
Beispiel #3
0
 def test_slot_from_key(self):
     key = 'blarg'.encode()
     result = slot_from_key(key)
     self.assertEqual(5534, result)