new EventTypeCache(event_type, chunkSize, redisClient)
Representation of specific event-type cache in Redis.
Handles all communication directly with Redis layer and contains the state of an individual cache.
Mostly used for internal purposes in this module to make EventStreamer & RedisEventCache classes easier to deal with.
Parameters:
| Name | Type | Description |
|---|---|---|
event_type |
String | |
chunkSize |
Number | |
redisClient |
redis.RedisClient |
- Source:
Methods
addRowToCache(insertId, row_json, callback)
Adds row to cache and performs all of the necessary operations to ensure integrity of the cache according to chunkSize parameters.
Most important function in terms of ensuring integrity of the cache, as it is responsible for publishing message to redis event type channel indicating what rows to push to EventStreamer
Implements a relatively simple algorithm to ensure that:
- No rows are removed from the cache before they can be streamed to datastore
- Messages are published only when equally-sized chunk of rows has been cached
- Caching process does not block the event loop
Full steps, each executed within callback: TODO: FILL IN
Parameters:
| Name | Type | Description |
|---|---|---|
insertId |
||
row_json |
||
callback |
- Source:
clearChunkFromCache(insertIds_str, callback)
Handles cleanup of cache elements -- chunk from chunkQueue and the cache itself.
Parameters:
| Name | Type | Description |
|---|---|---|
insertIds_str |
Array | array of insertIds in chunk to remove |
callback |
- Source:
getAllChunks()
Almost trivial wrapper to zrange, but added so users don't have to interact with cache directly.
- Source:
getAndClearActiveChunk(callback) → {*}
Gets this._activeChunk contents from memory and clears array.
Should be used with caution, and only on events like exit, SIGINT, etc.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
takes (err, chunk_str) |
- Source:
Returns:
- Type
- *
getRowsFromCache(insertIds_str, callback)
Retrieves and decodes event rows from cache by insertId
Parameters:
| Name | Type | Description |
|---|---|---|
insertIds_str |
String | encoded string of insertIds, which are keys in redis hash |
callback |
function | takes (err, parsed_rows_array) |
- Source: