1.3.1 • Published 1 year ago

redis-config-manager v1.3.1

Weekly downloads
29
License
MIT
Repository
github
Last release
1 year ago

redis-config-manager Build Status

A thin nodejs API wrapper for redis used to store JSON serialized strings under hash subkeys.

Features:

  • Keeps your redis instance root namespace clean by storing everything under one hash key, with subkeys as your main identifier
  • Handles the JSON encode/decode cycle internally
  • Event emitters let you set listeners as needed for handling errors the way you want
  • Uses node-redis module under the hood for its redis client
  • Uses redis-mock for local testing without a redis instance

Requirements:

Tested on NodeJS 12.x and higher

Installation:

Go into your yarn add redis-config-manager or npm install redis-config-manager

Example

See test/unit/rcm.spec.js for more examples.

const RedisConfigManager = require('redis-config-manager');
const source = {
    label: 'rando-name',            // generic name for this instance used in testing
    hashKey: 'rando-key-suffix',   // Suffix used in the hash key storing the data
    client: {
        host: '127.0.0.1',
        port: 6379
        // any other redis client-specific parameters
    },
};
const RCM = new RedisConfigManager(source);
await RCM.init();
await RCM.setConfig('foo',{bar:'quux'});

Methods & Properties:

SignatureDescriptionReturnsasync/PromiseDeprecated
.init()Initialize the manager, redis connection, active keys, etcYes
.setConfig(key,value)JSON serializes js object of value and writes/overwrites the string hash subkey of keyBoolean trueYes
.getConfig(key)If the string of key is a valid subkey to the hash, will return the JSON.parse value of the string value storedObjectYes
.getConfigs(keys)Provided an array of strings via the keys argument, will return an array of results in matching order as the keys. When a non-null value exists for a key, JSON.parse is attemptedArrayYes
.delConfig(key)Attempts to delete string subkey of key from the hash. Missing keys produce no errorBooleanYes
.hasConfigKey(key)Checks the locally stored Set of .activeConfigKeys for a existence of a keyBooleanNo
.keyRefresh()Forces a refresh of .activeConfigKeys outside of the predefined refresh intervalsundefinedYes
.activeConfigKeysReturns a Set of most recently refereshed key namesSetNo

source object properties

All are optional unless otherwise noted

PropertyTypeRequiredDefaultDescriptionDeprecated
labelStringNO-LABEL RedisConfigManager InstanceReadable identifier for debugging.
hashKeyStringYupundefinedSuffix to prepended to hashKeyPrefix
hashKeyPrefixStringredis-config-manager:Prefix for the hash key managed by this instance -- typically left as-is unless you have a pre-existing hash you want to use
fixtureDataObjectundefinedA simple/json-serializable object to be preloaded upon instantiation. See below for more detail.
listenersObjectno-op & consoleA key/function object for event listeners ofdebug,ready,error`
clientObject{host:'127.0.0.1', port:6379}Parameters for the node-redis client
client.module_overrideFunctionundefinedreplaces built-in require('node_redis') (maybe a new branch, custom version you're using)
client.client_overrideFunctionundefinedRe-use an existing node_redis client instance rather than using its own. (used during testing with redis-mock)
scanCountString1000Number of subkeys scanned per HSCAN - see the count option for detailsDeprecated in v1.2.x
refreshIntervalInteger15000Number of milliseconds between key refreshes

Contributions & Development:

Install with dev packages and run yarn test or npm test

PRs are welcome.

###TODO: Write some todos.

1.3.1

1 year ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago