On this page

# RedisStateManager

RedisStateManager

This is the implementation of the state manager leveraging Redis as state storage. This is the manager to be used when a multi-process instance of the SDK is needed.

## Constructor

### new RedisStateManager(redisOptions, logger)

The RedisStateManager constructor.

Parameters:

Name | Type | Description
--- | --- | ---
`redisOptions` | Object |
`logger` | Logger |

Source
  - models/redis.state.manager.js, line 24

## Classes

RedisStateManager

## Members

### (private) cache :Redis|null

The Redis handler for performing cache updates and reads.

Type:

- Redis | null

Source
  - models/redis.state.manager.js, line 39

### (private) inboxId :string|null

The `inboxId` to be read for messages received from other state managers/worker threads.

Type:

- string | null

Source
  - models/redis.state.manager.js, line 31

### (private) logger :Logger

Logger handler.

Type:

- Logger

Source
  - models/redis.state.manager.js, line 71

### (private) pubSubChannel :string|null

The channel to subscribe to.

Type:

- string | null

Source
  - models/redis.state.manager.js, line 63

### (private) publishChannel :Redis|null

The Redis subscription channel for publishing updates to other state managers.

Type:

- Redis | null

Source
  - models/redis.state.manager.js, line 47

### (private) subscriptionChannel :Redis|null

The Redis subscription channel for receiving updates from other state managers.

Type:

- Redis | null

Source
  - models/redis.state.manager.js, line 55

## Methods

### (async, private) _acquireLock(lock) → {Promise.<boolean>}

Attempts to acquire the `lock`.

Parameters:

Name | Type | Description
--- | --- | ---
`lock` |  |

Source
  - models/redis.state.manager.js, line 382

Returns:

Type:
  Promise.<boolean>

### (async, private) _waitForLock(lock, retryInterval, maxRetries) → {Promise.<boolean>}

Waits for aquiring the `lock` for a specified amount of time defined by the `retryInterval` and number of `maxRetries`.

Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`lock` | string |  |
`retryInterval` | number | 100 |
`maxRetries` | number | 10 |

Source
  - models/redis.state.manager.js, line 403

Returns:

Type:
  Promise.<boolean>

### broadcastIgnoreRequestId(requestId, watches)

Signals the subscribed threads to remove the watch for a specific session id.

Parameters:

Name | Type | Description
--- | --- | ---
`requestId` | string |
`watches` | Array.<string> |

Source
  - models/redis.state.manager.js, line 149

### broadcastPayloadStickySession(stickySessionId)

Broadcast a sticky id that is to be found in the payloads. Any payload containing this session-id should be routed to this specific process.

Parameters:

Name | Type | Description
--- | --- | ---
`stickySessionId` | string |

Source
  - models/redis.state.manager.js, line 167

### broadcastRequestId(requestId, watches)

Broadcasts interest for a specific session id to all the subscribed threads. The session id will be used for correct routing of the received notifications from the network.

Parameters:

Name | Type | Description
--- | --- | ---
`requestId` | string |
`watches` | Array.<string> |

Source
  - models/redis.state.manager.js, line 131

### broadcastUpdateFleet(fleet)

Broadcasts working fleet to all subscribed threads.

Parameters:

Name | Type | Description
--- | --- | ---
`fleet` | Array.<string> |

Source
  - models/redis.state.manager.js, line 114

### (async) getNetworkSnapshot(supervisor) → {Promise.<Object>}

Returns the network information as received from the supervisors.

Parameters:

Name | Type | Description
--- | --- | ---
`supervisor` | string |

Source
  - models/redis.state.manager.js, line 331

Returns:

Type:
  Promise.<Object>

### (async) getNetworkSupervisors() → {Promise.<Array.<string>>}

Get the list of observed network supervisors.

Source
  - models/redis.state.manager.js, line 313

Returns:

Type:
  Promise.<Array.<string>>

### (async) getNodeInfo(node) → {Promise.<Object>}

Returns the processed heartbeat cached for a specific `node`.

Parameters:

Name | Type | Description
--- | --- | ---
`node` | string |

Source
  - models/redis.state.manager.js, line 272

Returns:

Type:
  Promise.<Object>

### (async) getUniverse() → {Promise.<ObservedNodes>}

Returns the list of all observed network nodes. An observed node is any of the nodes that published a payload, notification or heartbeat, which was intercepted by the worker threads, even if that message was discarded because it was not from the controlled working fleet.

Source
  - models/redis.state.manager.js, line 217

Returns:

Type:
  Promise.<ObservedNodes>

### (async) markNodeAsSeen(node, timestamp) → {Promise.<boolean>}

Will mark a specific node as seen in the dictionary of nodes.

Parameters:

Name | Type | Description
--- | --- | ---
`node` |  |
`timestamp` |  |

Source
  - models/redis.state.manager.js, line 236

Returns:

Type:
  Promise.<boolean>

### (async) markSupervisor(supervisor) → {Promise.<boolean>}

Store information about an observed supervisor in the cache.

Parameters:

Name | Type | Description
--- | --- | ---
`supervisor` | string |

Source
  - models/redis.state.manager.js, line 349

Returns:

Type:
  Promise.<boolean>

### nodeInfoUpdate(info) → {RedisStateManager}

Stores the processed heartbeat data into the Redis cache.

Parameters:

Name | Type | Description
--- | --- | ---
`info` | Object |

Source
  - models/redis.state.manager.js, line 184

Returns:

Type:
  RedisStateManager

### (async) updateNetworkSnapshot(supervisor, update) → {Promise.<boolean>}

Will store the network snapshot as seen from a specific supervisor node.

Parameters:

Name | Type | Description
--- | --- | ---
`supervisor` | string |
`update` | Object |

Source
  - models/redis.state.manager.js, line 289

Returns:

Type:
  Promise.<boolean>

### (private, static) getObservedSupervisorsKeyAndLock() → {Array.<string>}

Returns the cache key and lock name for the list of observed network supervisors.

Source
  - models/redis.state.manager.js, line 446

Returns:

Type:
  Array.<string>

### (private, static) getRedisHeartbeatKey(node) → {string}

Returns the cache key based on the provided `node` name.

Parameters:

Name | Type | Description
--- | --- | ---
`node` | string |

Source
  - models/redis.state.manager.js, line 426

Returns:

Type:
  string

### (private, static) getRedisUniverseKeyAndLock() → {Array.<string>}

Returns the cache key name and lock name for the observed universe storage.

Source
  - models/redis.state.manager.js, line 436

Returns:

Type:
  Array.<string>

### (private, static) getSupervisorKeyAndLock(supervisor) → {Array.<string>}

Returns the cache key and lock name for reading and updating information received from a specific `supervisor`.

Parameters:

Name | Type | Description
--- | --- | ---
`supervisor` | string |

Source
  - models/redis.state.manager.js, line 457

Returns:

Type:
  Array.<string>

Type anything to view search result