diff --git a/client/ledis-py/ledis/client.py b/client/ledis-py/ledis/client.py index 17cc1c4..2504e5d 100644 --- a/client/ledis-py/ledis/client.py +++ b/client/ledis-py/ledis/client.py @@ -733,6 +733,70 @@ class Ledis(object): "Return the score of element ``value`` in sorted set ``name``" return self.execute_command('ZSCORE', name, value) + def zinterstore(self, dest, keys, aggregate=None): + """ + Intersect multiple sorted sets specified by ``keys`` into + a new sorted set, ``dest``. Scores in the destination will be + aggregated based on the ``aggregate``, or SUM if none is provided. + """ + return self._zaggregate('ZINTERSTORE', dest, keys, aggregate) + + def zunionstore(self, dest, keys, aggregate=None): + """ + Union multiple sorted sets specified by ``keys`` into + a new sorted set, ``dest``. Scores in the destination will be + aggregated based on the ``aggregate``, or SUM if none is provided. + """ + return self._zaggregate('ZUNIONSTORE', dest, keys, aggregate) + + def _zaggregate(self, command, dest, keys, aggregate=None): + pieces = [command, dest, len(keys)] + if isinstance(keys, dict): + keys, weights = iterkeys(keys), itervalues(keys) + else: + weights = None + pieces.extend(keys) + if weights: + pieces.append(Token('WEIGHTS')) + pieces.extend(weights) + if aggregate: + pieces.append(Token('AGGREGATE')) + pieces.append(aggregate) + return self.execute_command(*pieces) + + def zrangebylex(self, name, min, max, start=None, num=None): + """ + Return the lexicographical range of values from sorted set ``name`` + between ``min`` and ``max``. + + If ``start`` and ``num`` are specified, then return a slice of the + range. + """ + if (start is not None and num is None) or \ + (num is not None and start is None): + raise RedisError("``start`` and ``num`` must both be specified") + pieces = ['ZRANGEBYLEX', name, min, max] + if start is not None and num is not None: + pieces.extend([Token('LIMIT'), start, num]) + return self.execute_command(*pieces) + + def zremrangebylex(self, name, min, max): + """ + Remove all elements in the sorted set ``name`` between the + lexicographical range specified by ``min`` and ``max``. + + Returns the number of elements removed. + """ + return self.execute_command('ZREMRANGEBYLEX', name, min, max) + + def zlexcount(self, name, min, max): + """ + Return the number of items in the sorted set ``name`` between the + lexicographical range ``min`` and ``max``. + """ + return self.execute_command('ZLEXCOUNT', name, min, max) + + # SPECIAL COMMANDS SUPPORTED BY LEDISDB def zclear(self, name): "Delete key of ``name`` from sorted set" diff --git a/client/nodejs/ledis/lib/commands.js b/client/nodejs/ledis/lib/commands.js index f116444..8a24f6c 100644 --- a/client/nodejs/ledis/lib/commands.js +++ b/client/nodejs/ledis/lib/commands.js @@ -93,6 +93,9 @@ module.exports = [ "zscore", "zunionstore", "zinterstore", + "zrangebylex", + "zremrangebylex", + "zlexcount", "zclear", diff --git a/client/openresty/ledis.lua b/client/openresty/ledis.lua index 07c3f2b..7834c2b 100644 --- a/client/openresty/ledis.lua +++ b/client/openresty/ledis.lua @@ -95,6 +95,12 @@ local commands = { "zrevrank", "zrevrangebyscore", "zscore", + "zunionstore", + "zinterstore", + "zrangebylex", + "zremrangebylex", + "zlexcount", + --[[ledisdb special commands]] "zclear", "zmclear", diff --git a/cmd/ledis-cli/const.go b/cmd/ledis-cli/const.go index b89e757..3bca898 100644 --- a/cmd/ledis-cli/const.go +++ b/cmd/ledis-cli/const.go @@ -1,4 +1,4 @@ -//This file was generated by .tools/generate_commands.py on Mon Sep 29 2014 14:19:33 +0800 +//This file was generated by .tools/generate_commands.py on Thu Oct 02 2014 15:24:07 +0800 package main var helpCommands = [][]string{ @@ -106,12 +106,15 @@ var helpCommands = [][]string{ {"ZEXPIREAT", "key timestamp", "ZSet"}, {"ZINCRBY", "key increment member", "ZSet"}, {"ZINTERSTORE", "destkey numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]", "ZSet"}, + {"ZLEXCOUNT", "key min max", "ZSet"}, {"ZMCLEAR", "key [key ...]", "ZSet"}, {"ZPERSIST", "key", "ZSet"}, {"ZRANGE", "key start stop [WITHSCORES]", "ZSet"}, + {"ZRANGEBYLEX", "key min max [LIMIT offset count]", "ZSet"}, {"ZRANGEBYSCORE", "key min max [WITHSCORES] [LIMIT offset count]", "ZSet"}, {"ZRANK", "key member", "ZSet"}, {"ZREM", "key member [member ...]", "ZSet"}, + {"ZREMRANGBYLEX", "key min max", "ZSet"}, {"ZREMRANGEBYRANK", "key start stop", "ZSet"}, {"ZREMRANGEBYSCORE", "key min max", "ZSet"}, {"ZREVRANGE", "key start stop [WITHSCORES]", "ZSet"},