Implementation of the Redis protocol.
This abstract class provides a Python interface to all LedisDB commands and an implementation of the Redis protocol.
Connection and Pipeline derive from this, implementing how the commands are sent and received to the Ledis server
Set timeout on key name with time
Set any number of offset, value pairs to the key name. Pairs can be specified in the following way:
offset1, value1, offset2, value2, ...
Perform a bitwise operation using operation between keys and store the result in dest. operation is one of and, or, xor, not.
Removes an expiration on name
Returns the number of seconds until the key name will expire
Decrements the value of key by amount. If no key exists, the value will be initialized as 0 - amount
Decrements the value of key by amount. If no key exists, the value will be initialized as 0 - amount
Delete one or more keys specified by names
Echo the string back from the server
Execute a command and return a parsed response
Returns a boolean indicating whether key name exists
Set an expire flag on key name for time seconds. time can be represented by an integer or a Python timedelta object.
Set an expire flag on key name. when can be represented as an integer indicating unix time or a Python datetime object.
Return a Ledis client object configured from the given URL.
For example:
ledis://localhost:6380/0
unix:///path/to/socket.sock?db=0
There are several ways to specify a database number. The parse function will return the first specified option:
- A db querystring option, e.g. ledis://localhost?db=0
- If using the ledis:// scheme, the path argument of the url, e.g. ledis://localhost/0
- The db argument to this function.
If none of these options are specified, db=0 is used.
Any additional querystring arguments and keyword arguments will be passed along to the ConnectionPool class’s initializer. In the case of conflicting arguments, querystring arguments always win.
Return the value at key name, or None if the key doesn’t exist
Set the value at key name to value if key doesn’t exist Return the value at key name atomically
Delete key name from hash
Delete keys from hash name
Returns a boolean indicating if key exists within hash name
Set an expire flag on key name for time milliseconds. time can be represented by an integer or a Python timedelta object.
Set an expire flag on key name. when can be represented as an integer representing unix time in milliseconds (unix time * 1000) or a Python datetime object.
Return the value of key within the hash name
Return a Python dict of the hash’s name/value pairs
Increment the value of key in hash name by amount
Return the list of keys within hash name
Return the number of elements in hash name
Delete multiple keys names from hash
Returns a list of values ordered identically to keys
Sets each key in the mapping dict to its corresponding value in the hash name
Removes an expiration on name
Set key to value within hash name Returns 1 if HSET created a new field, otherwise 0
Returns the number of seconds until the key name will expire
Return the list of values within hash name
Increments the value of key by amount. If no key exists, the value will be initialized as amount
Increments the value of key by amount. If no key exists, the value will be initialized as amount
Return
Delete the key of name
Set an expire flag on key name for time seconds. time can be represented by an integer or a Python timedelta object.
Set an expire flag on key name. when can be represented as an integer indicating unix time or a Python datetime object.
Return the item from list name at position index
Negative indexes are supported and will return an item at the end of the list
Return the length of the list name
Delete multiple keys of name
Removes an expiration on name
Remove and return the first item of the list name
Push values onto the head of the list name
Return a slice of the list name between position start and end
start and end can be negative numbers just like Python slicing notation
Returns the number of seconds until the key name will expire
Returns a list of values ordered identically to keys
Sets key/values based on a mapping. Mapping can be supplied as a single dictionary argument or as kwargs.
Parses a response from the Ledis server
Removes an expiration on name
Ping the Ledis server
Remove and return the last item of the list name
Push values onto the tail of the list name
Add value(s) to set name
Return the number of elements in set name
Delete key name from set
Return the difference of sets specified by keys
Store the difference of sets specified by keys into a new set named dest. Returns the number of keys in the new set.
Set the value of key name to value.
Set a custom Response Callback
Set the value of key name to value if key doesn’t exist
Set an expire flag on key name for time milliseconds. time can be represented by an integer or a Python timedelta object.
Set an expire flag on key name. when can be represented as an integer representing unix time in milliseconds (unix time * 1000) or a Python datetime object.
Return the intersection of sets specified by keys
Store the intersection of sets specified by keys into a new set named dest. Returns the number of keys in the new set.
Return a boolean indicating if value is a member of set name
Delete multiple keys names from set
Return all members of the set name
Removes an expiration on name
Remove values from set name
Returns the number of seconds until the key name will expire
Return the union of sets specified by keys
Store the union of sets specified by keys into a new set named dest. Returns the number of keys in the new set.
Returns the number of seconds until the key name will expire
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)
Return the number of elements in the sorted set name
Delete key of name from sorted set
Return the number of elements in the sorted set at key name with a score between min and max. The min and max arguments have the same semantic as described for ZRANGEBYSCORE.
Set timeout on key name with time
Increment the score of value in sorted set name by amount
Delete multiple keys of names from sorted set
Removes an expiration on name
Return a range of values from sorted set name between start and end sorted in ascending order.
start and end can be negative, indicating the end of the range.
desc a boolean indicating whether to sort the results descendingly
withscores indicates to return the scores along with the values. The return type is a list of (value, score) pairs
Return a range of values from the sorted set name with scores between min and max.
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
Returns a 0-based value indicating the rank of value in sorted set name
Remove member values from sorted set name
Remove all elements in the sorted set name with ranks between min and max. Values are 0-based, ordered from smallest score to largest. Values can be negative indicating the highest scores. Returns the number of elements removed
Remove all elements in the sorted set name with scores between min and max. Returns the number of elements removed.
Return a range of values from sorted set name between start and num sorted in descending order.
start and num can be negative, indicating the end of the range.
withscores indicates to return the scores along with the values The return type is a list of (value, score) pairs
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
Returns a 0-based value indicating the descending rank of value in sorted set name
Return the score of element value in sorted set name
Returns the number of seconds until the key name will expire
Generic connection pool
Disconnects all connections in the pool
Return a connection pool configured from the given URL.
For example:
ledis://localhost:6380/0
unix:///path/to/socket.sock?db=0
There are several ways to specify a database number. The parse function will return the first specified option:
- A db querystring option, e.g. ledis://localhost?db=0
- If using the ledis:// scheme, the path argument of the url, e.g. ledis://localhost/0
- The db argument to this function.
If none of these options are specified, db=0 is used.
Any additional querystring arguments and keyword arguments will be passed along to the ConnectionPool class’s initializer. In the case of conflicting arguments, querystring arguments always win.
Get a connection from the pool
Create a new connection
Releases the connection back to the pool
Thread-safe blocking connection pool:
>>> from ledis.client import Ledis
>>> client = Ledis(connection_pool=BlockingConnectionPool())
It performs the same function as the default :py:class: ~ledis.connection.ConnectionPool implementation, in that, it maintains a pool of reusable connections that can be shared by multiple ledis clients (safely across threads if required).
The difference is that, in the event that a client tries to get a connection from the pool when all of connections are in use, rather than raising a :py:class: ~ledis.exceptions.ConnectionError (as the default :py:class: ~ledis.connection.ConnectionPool implementation does), it makes the client wait (“blocks”) for a specified number of seconds until a connection becomes available.
Use max_connections to increase / decrease the pool size:
>>> pool = BlockingConnectionPool(max_connections=10)
Use timeout to tell it either how many seconds to wait for a connection to become available, or to block forever:
# Block forever. >>> pool = BlockingConnectionPool(timeout=None)
# Raise a ConnectionError after five seconds if a connection is # not available. >>> pool = BlockingConnectionPool(timeout=5)
Disconnects all connections in the pool.
Get a connection, blocking for self.timeout until a connection is available from the pool.
If the connection returned is None then creates a new connection. Because we use a last-in first-out queue, the existing connections (having been returned to the pool after the initial None values were added) will be returned before None values. This means we only create new connections when we need to, i.e.: the actual number of connections will only increase in response to demand.
Make a fresh connection.
Reinstatiate this instance within a new process with a new connection pool set.
Releases the connection back to the pool.
Manages TCP communication to and from a Ledis server
Connects to the Ledis server if not already connected
Disconnects from the Ledis server
Return a bytestring representation of the value
Initialize the connection, authenticate and select a database
Pack a series of arguments into a value Ledis command
Read the response from a previously sent command
Pack and send a command to the Ledis server
Send an already packed command to the Ledis server
Returns an active Ledis client generated from the given database URL.
Will attempt to extract the database id from the path url fragment, if none is provided.