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 beNone
when it’s not on any transaction.
-
get
(key, value_type=<class 'sider.types.ByteString'>)¶ Loads the value from the
key
. Ifvalue_type
is present the value will be treated as it, orByteString
by default.Parameters: - key (
str
) – the Redis key to load - value_type (
Value
,type
) – the type of the value to load. default isByteString
Returns: the loaded value
- key (
-
mark_manipulative
(keys=frozenset([]))¶ Marks it is manipulative.
Parameters: keys ( collections.Iterable
) – optional set of keys to watchNote
This method is for internal use.
-
mark_query
(keys=frozenset([]))¶ Marks it is querying.
Parameters: keys ( collections.Iterable
) – optional set of keys to watchRaises 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 thekey
. Ifvalue_type
is present the value will be treated as it, orByteString
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 thevalue
. default isByteString
Returns: the Python representation of the saved value. it is equivalent to the given
value
but may not equal nor the same to- key (
-
transaction
¶ (
sider.transaction.Transaction
) The transaction object for the session.Transaction
objects are callable and so you can use thistransaction
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__()
- Method
-
verbose_transaction_error
= None¶ (
bool
) If it is set toTrue
, 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.
-