forked from mirror/ledisdb
add client command
This commit is contained in:
parent
1820190f96
commit
a75791f72c
|
@ -733,6 +733,70 @@ class Ledis(object):
|
||||||
"Return the score of element ``value`` in sorted set ``name``"
|
"Return the score of element ``value`` in sorted set ``name``"
|
||||||
return self.execute_command('ZSCORE', name, value)
|
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
|
# SPECIAL COMMANDS SUPPORTED BY LEDISDB
|
||||||
def zclear(self, name):
|
def zclear(self, name):
|
||||||
"Delete key of ``name`` from sorted set"
|
"Delete key of ``name`` from sorted set"
|
||||||
|
|
|
@ -93,6 +93,9 @@ module.exports = [
|
||||||
"zscore",
|
"zscore",
|
||||||
"zunionstore",
|
"zunionstore",
|
||||||
"zinterstore",
|
"zinterstore",
|
||||||
|
"zrangebylex",
|
||||||
|
"zremrangebylex",
|
||||||
|
"zlexcount",
|
||||||
|
|
||||||
|
|
||||||
"zclear",
|
"zclear",
|
||||||
|
|
|
@ -95,6 +95,12 @@ local commands = {
|
||||||
"zrevrank",
|
"zrevrank",
|
||||||
"zrevrangebyscore",
|
"zrevrangebyscore",
|
||||||
"zscore",
|
"zscore",
|
||||||
|
"zunionstore",
|
||||||
|
"zinterstore",
|
||||||
|
"zrangebylex",
|
||||||
|
"zremrangebylex",
|
||||||
|
"zlexcount",
|
||||||
|
|
||||||
--[[ledisdb special commands]]
|
--[[ledisdb special commands]]
|
||||||
"zclear",
|
"zclear",
|
||||||
"zmclear",
|
"zmclear",
|
||||||
|
|
|
@ -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
|
package main
|
||||||
|
|
||||||
var helpCommands = [][]string{
|
var helpCommands = [][]string{
|
||||||
|
@ -106,12 +106,15 @@ var helpCommands = [][]string{
|
||||||
{"ZEXPIREAT", "key timestamp", "ZSet"},
|
{"ZEXPIREAT", "key timestamp", "ZSet"},
|
||||||
{"ZINCRBY", "key increment member", "ZSet"},
|
{"ZINCRBY", "key increment member", "ZSet"},
|
||||||
{"ZINTERSTORE", "destkey numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]", "ZSet"},
|
{"ZINTERSTORE", "destkey numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]", "ZSet"},
|
||||||
|
{"ZLEXCOUNT", "key min max", "ZSet"},
|
||||||
{"ZMCLEAR", "key [key ...]", "ZSet"},
|
{"ZMCLEAR", "key [key ...]", "ZSet"},
|
||||||
{"ZPERSIST", "key", "ZSet"},
|
{"ZPERSIST", "key", "ZSet"},
|
||||||
{"ZRANGE", "key start stop [WITHSCORES]", "ZSet"},
|
{"ZRANGE", "key start stop [WITHSCORES]", "ZSet"},
|
||||||
|
{"ZRANGEBYLEX", "key min max [LIMIT offset count]", "ZSet"},
|
||||||
{"ZRANGEBYSCORE", "key min max [WITHSCORES] [LIMIT offset count]", "ZSet"},
|
{"ZRANGEBYSCORE", "key min max [WITHSCORES] [LIMIT offset count]", "ZSet"},
|
||||||
{"ZRANK", "key member", "ZSet"},
|
{"ZRANK", "key member", "ZSet"},
|
||||||
{"ZREM", "key member [member ...]", "ZSet"},
|
{"ZREM", "key member [member ...]", "ZSet"},
|
||||||
|
{"ZREMRANGBYLEX", "key min max", "ZSet"},
|
||||||
{"ZREMRANGEBYRANK", "key start stop", "ZSet"},
|
{"ZREMRANGEBYRANK", "key start stop", "ZSet"},
|
||||||
{"ZREMRANGEBYSCORE", "key min max", "ZSet"},
|
{"ZREMRANGEBYSCORE", "key min max", "ZSet"},
|
||||||
{"ZREVRANGE", "key start stop [WITHSCORES]", "ZSet"},
|
{"ZREVRANGE", "key start stop [WITHSCORES]", "ZSet"},
|
||||||
|
|
Loading…
Reference in New Issue