sider.session — Sessions

What sessions mainly do are identity map and unit of work.

class sider.session.Session(client)

Session is an object which manages Python objects that represent Redis values e.g. lists, sets, hashes. It maintains identity maps between Redis values and Python objects, and deals with transactions.

Parameters:client (redis.client.StrictRedis) – the Redis client
current_transaction

(Transaction) The current transaction. It could be None when it’s not on any transaction.

get(key, value_type=<class 'sider.types.ByteString'>)

Loads the value from the key. If value_type is present the value will be treated as it, or ByteString by default.

Parameters:
  • key (str) – the Redis key to load
  • value_type (Value, type) – the type of the value to load. default is ByteString
Returns:

the loaded value

mark_manipulative(keys=frozenset([]))

Marks it is manipulative.

Parameters:keys (collections.Iterable) – optional set of keys to watch

Note

This method is for internal use.

mark_query(keys=frozenset([]))

Marks it is querying.

Parameters:keys (collections.Iterable) – optional set of keys to watch
Raises sider.exceptions.CommitError:
 when it is tried during commit phase

Note

This method is for internal use.

server_version

(str) Redis server version string e.g. '2.2.11'.

server_version_info

(tuple) Redis server version triple e.g. (2, 2, 11). You can compare versions using this property.

set(key, value, value_type=<class 'sider.types.ByteString'>)

Stores the value into the key. If value_type is present the value will be treated as it, or ByteString by default.

Parameters:
  • key (str) – the Redis key to save the value into
  • value – the value to be saved
  • value_type (Value, type) – the type of the value. default is ByteString
Returns:

the Python representation of the saved value. it is equivalent to the given value but may not equal nor the same to

transaction

(sider.transaction.Transaction) The transaction object for the session.

Transaction objects are callable and so you can use this transaction property as like a method:

def block(trial, transaction):
    list_[0] = list_[0].upper()
session.transaction(block)

Or you can use it in a for loop:

for trial in session.transaction:
    list_[0] = list_[0].upper()

See also

Method sider.transaction.Transaction.__call__()
Executes a given block in the transaction.
Method sider.transaction.Transaction.__iter__()
More explicit way to execute a routine in the transaction than Transaction.__call__()
verbose_transaction_error = None

(bool) If it is set to True, error messages raised by transactions will contain tracebacks where they started query/commit phase.

It is mostly for debug purpose, and you can set this to True if it’s needed.