Exemple #1
0
    def __zadd(self, set_name, *args, **kwargs):
        """
        Custom ZADD interface that adapts to match the argument order of the currently
        used backend.  Using this method makes it transparent whether you use a Redis
        or a StrictRedis connection.

        Found this code at https://github.com/ui/rq-scheduler/pull/17.
        """
        conn = self.redis

        # If we're dealing with StrictRedis, flip each pair of imaginary
        # (name, score) tuples in the args list
        if conn.__class__ is redis.StrictRedis:  # StrictPipeline is a subclass of StrictRedis, too
            args = tuple(flip_pairs(args))

        return conn.zadd(set_name, *args)
Exemple #2
0
    def __zadd(self, set_name, *args, **kwargs):
        """
        Custom ZADD interface that adapts to match the argument order of the currently
        used backend.  Using this method makes it transparent whether you use a Redis
        or a StrictRedis connection.

        Found this code at https://github.com/ui/rq-scheduler/pull/17.
        """
        conn = self.redis

        # If we're dealing with StrictRedis, flip each pair of imaginary
        # (name, score) tuples in the args list
        if conn.__class__ is redis.StrictRedis:  # StrictPipeline is a subclass of StrictRedis, too
            args = tuple(flip_pairs(args))

        return conn.zadd(set_name, *args)
Exemple #3
0
    def test_can_flip_pairs(self):
        from retools.util import flip_pairs
        items = [1, 2, 3, 4]

        eq_(list(flip_pairs(items)), [2, 1, 4, 3])
Exemple #4
0
    def test_can_flip_pairs(self):
        from retools.util import flip_pairs
        items = [1, 2, 3, 4]

        eq_(list(flip_pairs(items)), [2, 1, 4, 3])