def zrevrangebyscore(self, name, min, max, start=None, num=None, withscores=False): """ Return a range of values from the sorted set ``name`` with scores between ``min`` and ``max`` in descending order. If ``start`` and ``num`` are specified, then return a slice of the range. ``withscores`` indicates to return the scores along with the values. The return type is a list of (value, score) pairs """ if (start is not None and num is None) or \ (num is not None and start is None): raise LedisError("``start`` and ``num`` must both be specified") pieces = ['ZREVRANGEBYSCORE', name, min, max] if start is not None and num is not None: pieces.extend(['LIMIT', start, num]) if withscores: pieces.append('withscores') options = {'withscores': withscores} return self.execute_command(*pieces, **options)
def bcount(self, key, start=None, end=None): "" params = [key] if start is not None and end is not None: params.append(start) params.append(end) elif (start is not None and end is None) or \ (start is None and end is not None): raise LedisError("Both start and end must be specified") return self.execute_command("BCOUNT", *params)
def mset(self, *args, **kwargs): """ Sets key/values based on a mapping. Mapping can be supplied as a single dictionary argument or as kwargs. """ if args: if len(args) != 1 or not isinstance(args[0], dict): raise LedisError('MSET requires **kwargs or a single dict arg') kwargs.update(args[0]) items = [] for pair in iteritems(kwargs): items.extend(pair) return self.execute_command('MSET', *items)
def bmsetbit(self, name, *args): """ Set any number of offset, value pairs to the key ``name``. Pairs can be specified in the following way: offset1, value1, offset2, value2, ... """ pieces = [] if args: if len(args) % 2 != 0: raise LedisError("BMSETBIT requires an equal number of " "offset and value") pieces.extend(args) return self.execute_command("BMSETBIT", name, *pieces)
def zadd(self, name, *args, **kwargs): """ Set any number of score, element-name pairs to the key ``name``. Pairs can be specified in two ways: As *args, in the form of: score1, name1, score2, name2, ... or as **kwargs, in the form of: name1=score1, name2=score2, ... The following example would add four values to the 'my-key' key: ledis.zadd('my-key', 1.1, 'name1', 2.2, 'name2', name3=3.3, name4=4.4) """ pieces = [] if args: if len(args) % 2 != 0: raise LedisError("ZADD requires an equal number of " "values and scores") pieces.extend(args) for pair in iteritems(kwargs): pieces.append(pair[1]) pieces.append(pair[0]) return self.execute_command('ZADD', name, *pieces)