Module Session

This module provides a session to interact with a Cassandra cluster.

A session must be opened, can be reused and closed once you're done with it. In the context of Nginx, a session used the underlying cosocket API which allows one to put a socket in the connection pool, before reusing it later. Otherwise, we fallback on luasocket as the underlying socket implementation.

Socket functions

connect (contact_points, port, options) Connect a session to a node coordinator.
set_timeout (...) Change the timeout value of the underlying socket object.
set_keepalive (...) Put the underlying socket into the cosocket connection pool.
get_reused_times () Return the number of successfully reused times for the underlying socket.
close () Close a connected session.

Queries functions

execute (operation, args, options) Execute an operation (query, prepared statement, batch statement).
set_keyspace (keyspace) Set a keyspace for that session.
prepare (query, tracing) Prepare a query.


Socket functions

connect (contact_points, port, options)
Connect a session to a node coordinator.

Parameters:

  • contact_points A string or an array of strings containing the IP addresse(s) to connect to. Strings can be of the form "host:port" if some nodes are running on another port than the specified or default one.
  • port Default: 9042. The port on which to connect to.
  • options Options for the connection. auth: An authenticator if remote requires authentication. See auth.lua. ssl: A boolean indicating if the connection must use SSL. ssl_verify: A boolean indicating whether to perform SSL verification. If using nginx, see the lua_ssl_trusted_certificate directive. If using Luasocket, see the ca_file option. See the ssl.lua example ca_file: Path to the certificate authority file. See the ssl.lua example.

Returns:

  1. connected boolean indicating the success of the connection.
  2. err Any server/client Error encountered during the connection.

Raises:

Any error due to a wrong usage of the driver (invalid parameter, non correctly initialized session...).

Usage:

  • local ok, err = session:connect("127.0.0.1", 9042)
  • local ok, err = session:connect({"127.0.0.1", "52.5.149.55:9888"}, 9042)
set_timeout (...)
Change the timeout value of the underlying socket object. Wrapper around the cosocket (or luasocket) "settimeout()" depending on what context you are using it. See the related implementation of "settimeout()" for parameters.

Parameters:

  • ...

Returns:

    The underlying result from tcpsock or luasocket.

Raises:

Exception if the session does not have an underlying socket (not correctly initialized).

See also:

set_keepalive (...)
Put the underlying socket into the cosocket connection pool. This method is only available when using the cosocket API. Wrapper around the cosocket "setkeepalive()" method.

Parameters:

  • ...

Raises:

Exception if the session does not have an underlying socket (not correctly initialized).

See also:

get_reused_times ()
Return the number of successfully reused times for the underlying socket. This method is only available when using the cosocket API. Wrapper round the cosocket "getreusedtimes()" method.

Raises:

Exception if the session does not have an underlying socket (not correctly initialized).

See also:

close ()
Close a connected session. Wrapper around the cosocket (or luasocket) "close()" depending on what context you are using it.

Returns:

    The underlying closing result from tcpsock or luasocket

Raises:

Exception if the session does not have an underlying socket (not correctly initialized).

See also:

Queries functions

execute (operation, args, options)
Execute an operation (query, prepared statement, batch statement).

Parameters:

  • operation The operation to execute. Whether it being a plain string query, a prepared statement or a batch.
  • args (Optional) An array of arguments to bind to the operation if it is a query or a statement.
  • options (Optional) A table of options for this query.

Returns:

  1. response The parsed response from Cassandra.
  2. err Any Error encountered during the execution.
set_keyspace (keyspace)
Set a keyspace for that session. Execute a "USE keyspace_name" query.

Parameters:

  • keyspace Name of the keyspace to use.

Returns:

    Results from execute.
prepare (query, tracing)
Prepare a query.

Parameters:

  • query The query to prepare.
  • tracing A boolean indicating if the preparation of this query should be traced.

Returns:

    statement A prepared statement to be given to execute.
generated by LDoc 1.4.3 Last updated 2015-07-30 16:28:43