Cassandra¶
This module is available only if you have cassandra-driver installed
wrap_future¶
-
satella.cassandra.
wrap_future
(future: satella.cassandra.common.ResponseFuture) → concurrent.futures._base.Future¶ Convert a Cassandra’s future to a normal Python future. The returned future will be marked as running.
future is returned when it’s already a Python future.
Parameters: future – cassandra future to wrap Returns: a standard Python future
parallel_for¶
If you have multiple async requests that would hit multiple nodes and you would prefer to make use of execute_async and want to better make use of them, here’s the routine to help you out.
-
satella.cassandra.
parallel_for
(cursor, query: Union[List[str], str, Statement, List[Statement]], arguments: Iterable[tuple]) → Iterator[collections.namedtuple]¶ Syntactic sugar for
>>> futures = [] >>> for args in arguments: >>> futures.append(cursor.execute_async(query, args)) >>> for future in futures: >>> yield future.result()
If query is a string or a Cassandra Statement, or else
>>> futures = [] >>> for query, args in zip(query, arguments): >>> futures.append(cursor.execute_async(query, args)) >>> for future in futures: >>> yield future.result()
Note that if None is encountered in the argument iterable, session.execute() will be called with a single argument. You better have it as a BoundStatement then!
Deprecated since version 2.14.22: Use Cassandra feature for that
Parameters: - cursor – the Cassandra cursor to use (obtained using connection.session())
- query – base query or a list of queries, if a different one is to be used
- arguments – iterable yielding arguments to use in execute_async
Note that if you specify an iterable instead of a string or a cassandra.query.Statement, different query will be applied to those arguments, as stemming from their ordering.