diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2014-07-06 23:03:07 -0400 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2014-07-06 23:03:07 -0400 |
commit | 55da7fd3569335354cc79ea25c7f192e78baff9f (patch) | |
tree | e0f0be9dcca18269d72880a2145274aecc57e6dc /redis/client.py | |
parent | 83013b5df1ea32213a77f81be08ffb40d56bace6 (diff) | |
parent | b993b322556fc366e6369b7d80d054ada2a75d7f (diff) | |
download | redis-py-55da7fd3569335354cc79ea25c7f192e78baff9f.tar.gz |
Merge pull request #501 from jettify/master
Added bitpos command
Diffstat (limited to 'redis/client.py')
-rwxr-xr-x | redis/client.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/redis/client.py b/redis/client.py index 9271e68..74cca86 100755 --- a/redis/client.py +++ b/redis/client.py @@ -293,10 +293,10 @@ class StrictRedis(object): bool ), string_keys_to_dict( - 'BITCOUNT DECRBY DEL GETBIT HDEL HLEN INCRBY LINSERT LLEN LPUSHX ' - 'PFADD PFCOUNT RPUSHX SADD SCARD SDIFFSTORE SETBIT SETRANGE ' - 'SINTERSTORE SREM STRLEN SUNIONSTORE ZADD ZCARD ZLEXCOUNT ZREM ' - 'ZREMRANGEBYLEX ZREMRANGEBYRANK ZREMRANGEBYSCORE', + 'BITCOUNT BITPOS DECRBY DEL GETBIT HDEL HLEN INCRBY LINSERT LLEN ' + 'LPUSHX PFADD PFCOUNT RPUSHX SADD SCARD SDIFFSTORE SETBIT ' + 'SETRANGE SINTERSTORE SREM STRLEN SUNIONSTORE ZADD ZCARD ' + 'ZLEXCOUNT ZREM ZREMRANGEBYLEX ZREMRANGEBYRANK ZREMRANGEBYSCORE', int ), string_keys_to_dict('INCRBYFLOAT HINCRBYFLOAT', float), @@ -792,6 +792,26 @@ class StrictRedis(object): """ return self.execute_command('BITOP', operation, dest, *keys) + def bitpos(self, key, bit, start=None, end=None): + """ + Return the position of the first bit set to 1 or 0 in a string. + ``start`` and ``end`` difines search range. The range is interpreted + as a range of bytes and not a range of bits, so start=0 and end=2 + means to look at the first three bytes. + """ + if bit not in (0, 1): + raise RedisError('bit must be 0 or 1') + params = [key, bit] + + start is not None and params.append(start) + + if start is not None and end is not None: + params.append(end) + elif start is None and end is not None: + raise RedisError("start argument is not set, " + "when end is specified") + return self.execute_command('BITPOS', *params) + def decr(self, name, amount=1): """ Decrements the value of ``key`` by ``amount``. If no key exists, |