npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-simple-client

v1.0.6

Published

A package to control Redis in a simple way

Downloads

28

Readme

Package

Simple Redis

This package is an abstraction layer on redis package to make functions more easy and with async/await usage in NodeJS. It's completelly written in TypeScript. It lets you use it for the Dictionary and also for the pub/sub system.

Installation

npm install redis-simple-client

Usage

const RedisSimpleClient = require('redis-simple-client');
const redis = new RedisSimpleClient();

Usage for dictionary

async function test(){
  // You can set the URL for the connection, if the third argument is FALSE you will NOT use it for pub/sub.
  // The prefix helps you using the same redis client for different apps in the same database.
  // You will have prefix_variable, prefix_variable2, etc. in the redis store. 
  await redis.connect('redis://localhost:6379', 'prefix_', false);
  
  // Set and get variables.
  await redis.set('variable','value');
  const variable = redis.get('variable');
  console.log(variable); // outputs: 'value'
  
  // Set and get many variables.
  const variables = {
    var1: 'Testing 1',
    var2: 'Testing 2',
    var10: 'Testing 3',
  };
  await redis.setMany(variables);
  let results = redis.getMany([var1,var2]);
  console.log(results); // Outputs: {var1: 'Testing 1', var2: 'Testing 2'}
  
  results = redis.getManyWithPattern('var1*');
  console.log(results); // Outpus: {var1: 'Testing 1', var10: 'Testing 3'}
  
  // Deleting values
  await redis.del(['var1']);
  await redis.delWithPattern('var1*'); // Will delete var1 and var10.
  
  // Counting and getting keys with patterns.
  await redis.keys('*'); //  Output: ['var2']
  await redis.count('*'); // Output: 1.
  
  // Get how many functions you realized.
  console.log(redis.getCounts()); / Output {get: 2, set: 5, count: 3...}.

  // Close the connection.
  await redis.close();
}

Usage for pub/sub system

async function test(){
  // You will still be able to use dictionary functions, but with TRUE you will also be able to use pub/sub.
  await redis.connect('redis://localhost:6379', 'prefix_', true);
  
  await redis.subscribe('CHANNEL', (message) => console.log(message));
  await redis.publish('CHANNEL', 'Hello!'); // Console will log "Hello!".
  await redis.unsubsribe('CHANNEL');
  await redis.close();
}

All methods

Method | Description ------------ | ------------- getRedis | Gets original Redis Client. getCounts | Gets an object with how many times each function was executed. setPrefix | Establishes the prefix for all variables in Redis. isConnected | Gets if redis is connected or not. resetCounters | Sets all counters to zero. connect | Connects to the specified url and sets the prefix. get | Gets the entry with the specified key. getMany | Gets many entries with the specified keys. getWithPattern | Gets all the entries that fit the specified pattern. count | Counts how many entries fit the specified pattern. set | Sets the entry with the specified key setMany | Sets many entries at the same time. incrBy | Increases a variable by a specified number. decrBy | Decreases a variable by a specified number. incr | Executes incrBy with 1. decr | Executes decrBy with 1. del | Deletes all the specified entries. delWithPattern | Deletes all the entries that fit the specified pattern. empty | Deletes all entries. publish | Sends a message to the specified channel. subscribe | Listens to a specified channel. unsubscribe | Stops listening to a specified channel. close | Closes the connection.

License

MIT © Matías Puig