Implementation of the Redis protocol.
This abstract class provides a Python interface to all Redis commands
and an implementation of the Redis protocol.
Connection and Pipeline derive from this, implementing how the
commands are sent and received to the Redis server
|
__init__(self,
host=' localhost ' ,
port=6379,
db=0,
password=None,
socket_timeout=None,
connection_pool=None,
charset=' utf-8 ' ,
errors=' strict ' ,
decode_responses=False,
unix_socket_path=None)
x.__init__(...) initializes x; see help(type(x)) for signature |
source code
|
|
|
set_response_callback(self,
command,
callback)
Set a custom Response Callback |
source code
|
|
|
pipeline(self,
transaction=True,
shard_hint=None)
Return a new pipeline object that can queue multiple commands for
later execution. |
source code
|
|
|
transaction(self,
func,
*watches,
**kwargs)
Convenience method for executing the callable `func` as a transaction
while watching all keys specified in `watches`. |
source code
|
|
|
lock(self,
name,
timeout=None,
sleep=0.1)
Return a new Lock object using key ``name`` that mimics the behavior
of threading.Lock. |
source code
|
|
|
|
|
execute_command(self,
*args,
**options)
Execute a command and return a parsed response |
source code
|
|
|
parse_response(self,
connection,
command_name,
**options)
Parses a response from the Redis server |
source code
|
|
|
bgrewriteaof(self)
Tell the Redis server to rewrite the AOF file from data in memory. |
source code
|
|
|
|
|
config_get(self,
pattern=' * ' )
Return a dictionary of configuration based on the ``pattern`` |
source code
|
|
|
config_set(self,
name,
value)
Set config item ``name`` with ``value`` |
source code
|
|
|
dbsize(self)
Returns the number of keys in the current database |
source code
|
|
|
time(self)
Returns the server time as a 2-item tuple of ints: (seconds since
epoch, microseconds into this second). |
source code
|
|
|
debug_object(self,
key)
Returns version specific metainformation about a give key |
source code
|
|
|
delete(self,
*names)
Delete one or more keys specified by ``names`` |
source code
|
|
|
__delitem__(self,
*names)
Delete one or more keys specified by ``names`` |
source code
|
|
|
echo(self,
value)
Echo the string back from the server |
source code
|
|
|
flushall(self)
Delete all keys in all databases on the current host |
source code
|
|
|
flushdb(self)
Delete all keys in the current database |
source code
|
|
|
info(self)
Returns a dictionary containing information about the Redis server |
source code
|
|
|
lastsave(self)
Return a Python datetime object representing the last time the Redis
database was saved to disk |
source code
|
|
|
object(self,
infotype,
key)
Return the encoding, idletime, or refcount about the key |
source code
|
|
|
|
|
save(self)
Tell the Redis server to save its data to disk, blocking until the
save is complete |
source code
|
|
|
|
|
slaveof(self,
host=None,
port=None)
Set the server to be a replicated slave of the instance identified by
the ``host`` and ``port``. |
source code
|
|
|
append(self,
key,
value)
Appends the string ``value`` to the value at ``key``. |
source code
|
|
|
getrange(self,
key,
start,
end)
Returns the substring of the string value stored at ``key``,
determined by the offsets ``start`` and ``end`` (both are inclusive) |
source code
|
|
|
bitcount(self,
key,
start=None,
end=None)
Returns the count of set bits in the value of ``key``. |
source code
|
|
|
bitop(self,
operation,
dest,
*keys)
Perform a bitwise operation using ``operation`` between ``keys`` and
store the result in ``dest``. |
source code
|
|
|
decr(self,
name,
amount=1)
Decrements the value of ``key`` by ``amount``. |
source code
|
|
|
exists(self,
name)
Returns a boolean indicating whether key ``name`` exists |
source code
|
|
|
__contains__(self,
name)
Returns a boolean indicating whether key ``name`` exists |
source code
|
|
|
expire(self,
name,
time)
Set an expire flag on key ``name`` for ``time`` seconds. |
source code
|
|
|
|
|
get(self,
name)
Return the value at key ``name``, or None if the key doesn't exist |
source code
|
|
|
__getitem__(self,
name)
Return the value at key ``name``, raises a KeyError if the key
doesn't exist. |
source code
|
|
|
getbit(self,
name,
offset)
Returns a boolean indicating the value of ``offset`` in ``name`` |
source code
|
|
|
getset(self,
name,
value)
Set the value at key ``name`` to ``value`` if key doesn't exist
Return the value at key ``name`` atomically |
source code
|
|
|
incr(self,
name,
amount=1)
Increments the value of ``key`` by ``amount``. |
source code
|
|
|
keys(self,
pattern=' * ' )
Returns a list of keys matching ``pattern`` |
source code
|
|
|
mget(self,
keys,
*args)
Returns a list of values ordered identically to ``keys`` |
source code
|
|
|
mset(self,
mapping)
Sets each key in the ``mapping`` dict to its corresponding value |
source code
|
|
|
msetnx(self,
mapping)
Sets each key in the ``mapping`` dict to its corresponding value if
none of the keys are already set |
source code
|
|
|
move(self,
name,
db)
Moves the key ``name`` to a different Redis database ``db`` |
source code
|
|
|
persist(self,
name)
Removes an expiration on ``name`` |
source code
|
|
|
randomkey(self)
Returns the name of a random key |
source code
|
|
|
rename(self,
src,
dst)
Rename key ``src`` to ``dst`` |
source code
|
|
|
renamenx(self,
src,
dst)
Rename key ``src`` to ``dst`` if ``dst`` doesn't already exist |
source code
|
|
|
set(self,
name,
value)
Set the value at key ``name`` to ``value`` |
source code
|
|
|
__setitem__(self,
name,
value)
Set the value at key ``name`` to ``value`` |
source code
|
|
|
setbit(self,
name,
offset,
value)
Flag the ``offset`` in ``name`` as ``value``. |
source code
|
|
|
setex(self,
name,
time,
value)
Set the value of key ``name`` to ``value`` that expires in ``time``
seconds. |
source code
|
|
|
setnx(self,
name,
value)
Set the value of key ``name`` to ``value`` if key doesn't exist |
source code
|
|
|
setrange(self,
name,
offset,
value)
Overwrite bytes in the value of ``name`` starting at ``offset`` with
``value``. |
source code
|
|
|
strlen(self,
name)
Return the number of bytes stored in the value of ``name`` |
source code
|
|
|
substr(self,
name,
start,
end=-1)
Return a substring of the string at key ``name``. |
source code
|
|
|
ttl(self,
name)
Returns the number of seconds until the key ``name`` will expire |
source code
|
|
|
type(self,
name)
Returns the type of key ``name`` |
source code
|
|
|
watch(self,
*names)
Watches the values at keys ``names``, or None if the key doesn't
exist |
source code
|
|
|
unwatch(self)
Unwatches the value at key ``name``, or None of the key doesn't exist |
source code
|
|
|
blpop(self,
keys,
timeout=0)
LPOP a value off of the first non-empty list named in the ``keys``
list. |
source code
|
|
|
brpop(self,
keys,
timeout=0)
RPOP a value off of the first non-empty list named in the ``keys``
list. |
source code
|
|
|
brpoplpush(self,
src,
dst,
timeout=0)
Pop a value off the tail of ``src``, push it on the head of ``dst``
and then return it. |
source code
|
|
|
lindex(self,
name,
index)
Return the item from list ``name`` at position ``index`` |
source code
|
|
|
linsert(self,
name,
where,
refvalue,
value)
Insert ``value`` in list ``name`` either immediately before or after
[``where``] ``refvalue`` |
source code
|
|
|
llen(self,
name)
Return the length of the list ``name`` |
source code
|
|
|
lpop(self,
name)
Remove and return the first item of the list ``name`` |
source code
|
|
|
lpush(self,
name,
*values)
Push ``values`` onto the head of the list ``name`` |
source code
|
|
|
lpushx(self,
name,
value)
Push ``value`` onto the head of the list ``name`` if ``name`` exists |
source code
|
|
|
lrange(self,
name,
start,
end)
Return a slice of the list ``name`` between position ``start`` and
``end`` |
source code
|
|
|
lrem(self,
name,
count,
value)
Remove the first ``count`` occurrences of elements equal to ``value``
from the list stored at ``name``. |
source code
|
|
|
lset(self,
name,
index,
value)
Set ``position`` of list ``name`` to ``value`` |
source code
|
|
|
ltrim(self,
name,
start,
end)
Trim the list ``name``, removing all values not within the slice
between ``start`` and ``end`` |
source code
|
|
|
rpop(self,
name)
Remove and return the last item of the list ``name`` |
source code
|
|
|
rpoplpush(self,
src,
dst)
RPOP a value off of the ``src`` list and atomically LPUSH it on to
the ``dst`` list. |
source code
|
|
|
rpush(self,
name,
*values)
Push ``values`` onto the tail of the list ``name`` |
source code
|
|
|
rpushx(self,
name,
value)
Push ``value`` onto the tail of the list ``name`` if ``name`` exists |
source code
|
|
|
sort(self,
name,
start=None,
num=None,
by=None,
get=None,
desc=False,
alpha=False,
store=None)
Sort and return the list, set or sorted set at ``name``. |
source code
|
|
|
sadd(self,
name,
*values)
Add ``value(s)`` to set ``name`` |
source code
|
|
|
scard(self,
name)
Return the number of elements in set ``name`` |
source code
|
|
|
sdiff(self,
keys,
*args)
Return the difference of sets specified by ``keys`` |
source code
|
|
|
sdiffstore(self,
dest,
keys,
*args)
Store the difference of sets specified by ``keys`` into a new set
named ``dest``. |
source code
|
|
|
sinter(self,
keys,
*args)
Return the intersection of sets specified by ``keys`` |
source code
|
|
|
sinterstore(self,
dest,
keys,
*args)
Store the intersection of sets specified by ``keys`` into a new set
named ``dest``. |
source code
|
|
|
sismember(self,
name,
value)
Return a boolean indicating if ``value`` is a member of set ``name`` |
source code
|
|
|
smembers(self,
name)
Return all members of the set ``name`` |
source code
|
|
|
smove(self,
src,
dst,
value)
Move ``value`` from set ``src`` to set ``dst`` atomically |
source code
|
|
|
spop(self,
name)
Remove and return a random member of set ``name`` |
source code
|
|
|
srandmember(self,
name)
Return a random member of set ``name`` |
source code
|
|
|
srem(self,
name,
*values)
Remove ``values`` from set ``name`` |
source code
|
|
|
sunion(self,
keys,
*args)
Return the union of sets specifiued by ``keys`` |
source code
|
|
|
sunionstore(self,
dest,
keys,
*args)
Store the union of sets specified by ``keys`` into a new set named
``dest``. |
source code
|
|
|
zadd(self,
name,
*args,
**kwargs)
Set any number of score, element-name pairs to the key ``name``. |
source code
|
|
|
zcard(self,
name)
Return the number of elements in the sorted set ``name`` |
source code
|
|
|
|
|
zincrby(self,
name,
value,
amount=1)
Increment the score of ``value`` in sorted set ``name`` by ``amount`` |
source code
|
|
|
zinterstore(self,
dest,
keys,
aggregate=None)
Intersect multiple sorted sets specified by ``keys`` into a new
sorted set, ``dest``. |
source code
|
|
|
zrange(self,
name,
start,
end,
desc=False,
withscores=False,
score_cast_func=<type 'float'>)
Return a range of values from sorted set ``name`` between ``start``
and ``end`` sorted in ascending order. |
source code
|
|
|
zrangebyscore(self,
name,
min,
max,
start=None,
num=None,
withscores=False,
score_cast_func=<type 'float'>)
Return a range of values from the sorted set ``name`` with scores
between ``min`` and ``max``. |
source code
|
|
|
zrank(self,
name,
value)
Returns a 0-based value indicating the rank of ``value`` in sorted
set ``name`` |
source code
|
|
|
zrem(self,
name,
*values)
Remove member ``values`` from sorted set ``name`` |
source code
|
|
|
zremrangebyrank(self,
name,
min,
max)
Remove all elements in the sorted set ``name`` with ranks between
``min`` and ``max``. |
source code
|
|
|
zremrangebyscore(self,
name,
min,
max)
Remove all elements in the sorted set ``name`` with scores between
``min`` and ``max``. |
source code
|
|
|
zrevrange(self,
name,
start,
num,
withscores=False,
score_cast_func=<type 'float'>)
Return a range of values from sorted set ``name`` between ``start``
and ``num`` sorted in descending order. |
source code
|
|
|
zrevrangebyscore(self,
name,
max,
min,
start=None,
num=None,
withscores=False,
score_cast_func=<type 'float'>)
Return a range of values from the sorted set ``name`` with scores
between ``min`` and ``max`` in descending order. |
source code
|
|
|
zrevrank(self,
name,
value)
Returns a 0-based value indicating the descending rank of ``value``
in sorted set ``name`` |
source code
|
|
|
zscore(self,
name,
value)
Return the score of element ``value`` in sorted set ``name`` |
source code
|
|
|
zunionstore(self,
dest,
keys,
aggregate=None)
Union multiple sorted sets specified by ``keys`` into a new sorted
set, ``dest``. |
source code
|
|
|
hdel(self,
name,
*keys)
Delete ``keys`` from hash ``name`` |
source code
|
|
|
hexists(self,
name,
key)
Returns a boolean indicating if ``key`` exists within hash ``name`` |
source code
|
|
|
hget(self,
name,
key)
Return the value of ``key`` within the hash ``name`` |
source code
|
|
|
hgetall(self,
name)
Return a Python dict of the hash's name/value pairs |
source code
|
|
|
hincrby(self,
name,
key,
amount=1)
Increment the value of ``key`` in hash ``name`` by ``amount`` |
source code
|
|
|
hkeys(self,
name)
Return the list of keys within hash ``name`` |
source code
|
|
|
hlen(self,
name)
Return the number of elements in hash ``name`` |
source code
|
|
|
hset(self,
name,
key,
value)
Set ``key`` to ``value`` within hash ``name`` Returns 1 if HSET
created a new field, otherwise 0 |
source code
|
|
|
hsetnx(self,
name,
key,
value)
Set ``key`` to ``value`` within hash ``name`` if ``key`` does not
exist. |
source code
|
|
|
hmset(self,
name,
mapping)
Sets each key in the ``mapping`` dict to its corresponding value in
the hash ``name`` |
source code
|
|
|
hmget(self,
name,
keys,
*args)
Returns a list of values ordered identically to ``keys`` |
source code
|
|
|
hvals(self,
name)
Return the list of values within hash ``name`` |
source code
|
|
|
|
|
eval(self,
script,
numkeys,
*keys_and_args)
Execute the LUA ``script``, specifying the ``numkeys`` the script
will touch and the key names and argument values in
``keys_and_args``. |
source code
|
|
|
evalsha(self,
sha,
numkeys,
*keys_and_args)
Use the ``sha`` to execute a LUA script already registered via EVAL
or SCRIPT LOAD. |
source code
|
|
|
script_exists(self,
*args)
Check if a script exists in the script cache by specifying the SHAs
of each script as ``args``. |
source code
|
|
|
script_flush(self)
Flush all scripts from the script cache |
source code
|
|
|
script_kill(self)
Kill the currently executing LUA script |
source code
|
|
|
|
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|