Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@beforeyoubid/redis-client

Package Overview
Dependencies
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@beforeyoubid/redis-client

A Redis client for connecting to Redis caching server

  • 0.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

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.

FAQs

Package last updated on 03 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc