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
- 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.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