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

blackpink

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blackpink

Simple redis utility function

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

🦄 BLACKPINK

A Simple Redis Utility Function

npm install blackpink
npm install redis

Check is newest list item

This function allows you to use Redis to check that the data is up to date. It also allows you to check the maximum number.

import * as redis from "redis";
import blackpink from "blackpink";

const client = redis.createClient({});
const pink = blackpink(client);

void (async () => {
  const list = ["a1.png", "a2.png", "a3.png"];
  let isFirstLoop = true;

  for (const item of list) {
    const isNewest = await pink.checkIsNewest({
      list: "community-meme",
      item,
      isFirstLoop,
      limit: 300,
    });

    if (isFirstLoop) isFirstLoop = false;

    if (isNewest) {
      console.log("new meme", item);
      break;
    } else {
      console.log("old meme", item);
    }
  }
})();

Cache single item

import * as redis from "redis";
import blackpink from ".blackpink";

const client = redis.createClient({});
const pink = blackpink(client);

void (async () => {
  // Set cache
  await pink.setCache({
    key: "test",
    value: "test",
    // 7days
    ttl: 60 * 60 * 24 * 7,
  });

  // Get cache
  const data = await pink.getCache("test");
  console.log(data);

   // Check cache hit
  const isHit = await pink.isCacheHit("test")
  console.log(isHit);

  // Invalidate cache
  await pink.invalidateCache("test");
})();

Cache map item

import * as redis from "redis";
import blackpink from ".blackpink";

const client = redis.createClient({});
const pink = blackpink(client);

void (async () => {
  // Set hash cache
  await pink.setHashCache({
    key: "test",
    field: "test",
    value: "test",
  });

  // Get hash cache
  const data = await pink.getHashCache({
    key: "test",
    field: "test",
  });

  // Check hash cache hit
  await pink.isHashCacheHit({
    key: "test",
    field: "test",
  });

  // Invalidate hash cache
  await pink.invalidateHashCache({
    key: "test",
    field: "test",
  });

  // Invalidate all hash cache
  await pink.invalidateAllHashCache("test");
})();

License

MIT Licensed

Keywords

FAQs

Package last updated on 11 Sep 2022

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