Class: RedisMetrics

RedisMetrics(configopt)

A simple metrics utility for Redis. Creates a connection to Redis using the given options or an already-connected Redis client.

The client does not set up a catch-all error handler. If you rely on handling uncaught exceptions, it's a good idea to create an error handler (see the example).

Constructor

new RedisMetrics(configopt)

Parameters:
Name Type Attributes Description
config Object <optional>

configuration options

Properties
Name Type Attributes Description
client Object <optional>

An existing redis client. The only fully-supported client is node_redis

host String <optional>

The Redis host to use.

port String <optional>

The Redis port to use.

redisOptions Object <optional>

The Redis options to use.

counterOptions Object <optional>

Default counter options to use if none are provided when creating a counter. See RedisMetrics#counter

Source:
Example
const metrics = new RedisMetrics();
metrics.client.on('error', console.error);
metrics.counter('coolCounter').incr(1);

Members

client :Object

The client connection

Type:
  • Object
Source:

Methods

counter(eventName, optionsopt) → {TimestampedCounter}

Returns a timestamped counter for the given event.

If the counter is initialized without options, it works like a normal event counter that tracks a total count for the given event key. If a time granularity option is specified, the counter will be able to report aggregated counters based on time intervals down to the level of granularity that is chosen.

Parameters:
Name Type Attributes Description
eventName string

The event that we want to count for.

options Object <optional>

The options to use for the counter

Properties
Name Type Attributes Default Description
timeGranularity number <optional>
'none'

Makes the counter use timestamps which means that it can be used to measure event metrics based on time intervals. The default is to not use time granularities.

expireKeys boolean <optional>
true

Automatically expire keys. Useful for high time granularity levels to preserve memory.

Since:
  • 0.1.0
Source:
Returns:
Type
TimestampedCounter