0.0.9 • Published 3 years ago

@beforeyoubid/redis-client v0.0.9

Weekly downloads
60
License
ISC
Repository
github
Last release
3 years ago

Redis-client

An npm package for connecting to Redis caching server. Support both writer and reader clients.

Instance creation

Creating a writer

Simply call RedisClient.getWriter() which will perform multiple steps:

  • Pull a Redis connection string directly from process.env through a key REDIS_CONN_STR_WRITER.
  • You can pass optional redis params as the second
  • The getWriter() will create a new instance everytime so it will try to return the connection within 2000ms to avoid some latency issue or network issue. It will ignore the conneciton if it takes too long. This is to avoid having a network issue
    const [writerErr, writerClient] = await to(RedisClient.getWriter());
    if (writerErr) {
      logger.error(`Unable to get the Redis writer, Err: ${writerErr.message}`);
      throw writerErr;
    }

Writing cache

Redis 3.x doesn't support Promise (v4 does). Therefore, most common get, set are wrapped using a promisify module. To write, simply call

    const [storingErr] = await to(
      writerClient.set(cacheKey, JSON.stringify(propertySearchResponse), 'EX', expiryTimeInSeconds)
    );

Creating a reader

Simply call RedisClient.getReader() which will create a reader instance and connect to it.

    const [readerErr, readerClient] = await to(RedisClient.getReader());

Reading cache

    const [err, cache] = await to(readerClient.get(cacheKey));

Depending on the value stored on the Redis, if you store a serialised json object you may need to parse it first.

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago