redis_ipc module

This is a Python module to provide ‘thin’ client/server classes implementing a light-weight IPC mechanism using JSON formatting and the Redis server as ‘message bus’.

class redis_ipc.RedisClient(component, thread='main')[source]

Bases: object

Provide a friendly component name for calling program (e.g. how it is labeled on system architecture diagrams as opposed to exact executable name). Allows IPC from multiple threads in a multi-threaded program.

Parameters:
  • component – name of component

  • thread – friendly name for specific thread of execution

redis_ipc_send_and_receive(dest, cmd, tmout)[source]
Parameters:
  • dest – name of the component to handle this command (string)

  • cmd – the command to send (dictionary)

  • tmout – timeout for receiving a response (float seconds)

exception redis_ipc.RedisIpcExc[source]

Bases: Exception

Generic redis-ipc error, used with one of the exception definitions defined below.

class redis_ipc.RedisServer(component)[source]

Bases: object

Provide a friendly component name for calling program (e.g. how it is labeled on system architecture diagrams as opposed to exact executable name).

Parameters:

component – name of component

redis_ipc_receive_command()[source]

Blocks for command string to arrive in own command queue.

Returns:

dictionary

redis_ipc_send_reply(cmd, result)[source]

This routine does not block, it just sends the reply to the back of the queue.

Parameters:

cmd – command that was processed so result is now available

Return result:

the generated result

redis_ipc.get_runtimepath()[source]

Get the runtime socket path.

Returns:

socket path string

redis_ipc.get_serveraddr()[source]

Get the redis server address if defined in ENV (should be either a resolvable hostname or localhost).

Returns:

address or None

redis_ipc.is_jsonable(obj)[source]

Test if an object can be dumped as JSON.

Parameters:

obj – object to test

Returns:

True if dumpable else False

redis_ipc.is_unjsonable(obj)[source]

Test if an object can be loaded as JSON.

Parameters:

obj – object to test

Returns:

True if loadable else False

redis_ipc.jdic2pdic(jstr)[source]

Convert JSON to a dictionary, list, etc.

Parameters:

jstr – a JSON string

Returns:

an object

redis_ipc.pdic2jdic(pdic)[source]

Covert an object to JSON.

Parameters:

pdic – a dictionary

Returns:

a JSON string

redis_ipc.redis_connect(socket_path='/tmp/redis-ipc/socket', server_addr=None)[source]

Attempt to open a connection to the Redis server, and raise an exception if this does not work. Return the connection object if successful.

Parameters:
  • socket_path – path to redis socket

  • server_addr – address of redis server

Returns:

client object

Raises:

NoRedis