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

@nazarkulyk/pta-kyma-cache

v1.0.3

Published

## Deploy redis to kyma

Downloads

3

Readme

redis-example

Deploy redis to kyma

cd deploy
kubectl apply -f redis.yaml
kubectl apply -f redis-commander.yaml

Redis Commander

Create API Rule for redis commander, than you will have GUI Access to your redis storage

Create function

{
  "name": "redis-example",
  "version": "1.0.0",
  "dependencies": {
      "redis": "^3.0.2",
      "nanoid": "^3.1.12",
      "lodash": "^4.17.20"
  }
}
const redis = require('redis');
const { nanoid } = require('nanoid');
const { pick, omit } = require('lodash');
const { promisify } = require("util");

/**
 * Use it like that:
 *
 *  get Redis Service Info:
 *  https://redis-demo.c-9a36b66.kyma.shoot.live.k8s-hana.ondemand.com/info
 *
 *  protocol some data from request:
 *
 */


const REQUEST_DATA_LIST = ['path', 'query', 'url', 'body'];

class RedisStorage {
  storage = undefined;
  asyncGet = void 0;
  asyncKeys = void 0;
  asyncSet = void 0;
  asyncInfo = void 0;

  constructor(options) {
    this.storage = redis.createClient(options);
    this.asyncGet = promisify(this.storage.get).bind(this.storage);
    this.asyncKeys = promisify(this.storage.keys).bind(this.storage);
    this.asyncSet = promisify(this.storage.set).bind(this.storage);
    this.asyncInfo= promisify(this.storage.info).bind(this.storage);
  }

  async getAll() {
    let values = [];
    const keys = await this.asyncKeys("*");
    for (const key of keys) {
      const value = await this.asyncGet(key);
      values.push(JSON.parse(value));
    }
    return values;
  }

  async info() {
    return this.asyncInfo();
  }

  async set(data = {}) {
    if (!data.id) {
      data.id = nanoid();
    }
    const value = await this.asyncGet(data.id);
    if (value) {
      throw new Error('Object already exists');
    }
    await this.asyncSet(data.id, JSON.stringify(omit(data, 'id')));
    return data.id;
  }
}


module.exports = {
  main: async (event, context) => {
    const path = event.extensions.request.path;

    let storage;

    try {
      storage = new RedisStorage({host: process.env.REDIS_HOST, port: process.env.REDIS_PORT});
    } catch(e) {
      console.error(e);
      throw new Error(e);
    }

    if(path === "/info") {
      return storage.info()
    } else if(path === "/set") {
      return storage.set({ path, date: new Date(), request: pick(event.extensions.request, REQUEST_DATA_LIST)});
    } else if(path === "/get") {
      return storage.getAll();
    } else {
      return "provide some operator";
    }
  }
}