RedisRegistrationProvider Class
Implements the necessary functions in order to be able to create and manage a service registry for PB processes in the cluster. This provider uses Redis as the storage. In addition, it leverages Redis's expiry functionality to expire entries automatically if they have not been touched. In order to retrieve all nodes/processes in the cluster the provider must execute Redis's "keys" function which is an expensive operation. To lessen the impact on production systems the provider creates and manages its own Redis client and switches to DB 2 in order to minimize the number of keys that need to be scanned since the rest of the PB system leverages DB 0.
Constructor
RedisRegistrationProvider
()
Item Index
Properties
- CLIENT static
- REGISTRY_DB static
- SEP static
Methods
flush
-
cb
Purges all statuses from storage.
Parameters:
-
cb
FunctionA callback that provides two parameters: cb(Error, [RESULT])
get
-
cb
Retrieves the entire cluster status as an array of status objects. The '_id' property uniquely identifies each process/node.
Parameters:
-
cb
FunctionA callback that provides two parameters: cb(Error, Array)
getKey
-
id
Creates the cache key used to store the status update
Parameters:
-
id
StringThe unique identifier for the node/process
Returns:
The cache key to be used for storing the update
getPattern
()
String
static
Creates the glob pattern to be used to find service registry keys
Returns:
The glob patern to be used to find all status updates
init
-
cb
This function should only be called once at startup. It is responsible for creating the Redis client that connects to the service registry. It also ensures the proper Redis DB is selected.
Parameters:
-
cb
FunctionA callback that takes two parameters. cb(Error, [RESULT])
set
-
id
-
status
-
cb
Updates the status of a single node.
Parameters:
-
id
StringThe unique identifier for the process/node
-
status
ObjectThe status information
-
cb
FunctionA callback that provides two parameters: cb(Error, [RESULT])
shutdown
-
id
-
cb
Should be called during shutdown. It is responsible for removing the process/node from the registry.
Parameters:
-
id
StringThe unique identifier for the node/process
-
cb
FunctionA callback that takes two parameters: cb(Error, [RESULT])
Properties
CLIENT
Integer
private
static
The Redis client used to connect to the service registry
REGISTRY_DB
Integer
private
static
The Redis DB used for storage
SEP
String
private
static
The character used to separate the registry key prefix from the unique value that identifies the process/node.