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

cache-grpc-server

v0.0.8

Published

Cache server with grpc and redis

Downloads

6

Readme

Overall

Server for fast save and read data from cache. Use GRPC stream for connection and Redis as storage. Ready for TLS and mTLS.

Features:

  • GRPC connection
  • GET and SET method as stream
  • Reflection
  • HealthProbe
  • Redis as storage
  • NestJs framework

Client create one connection via stream, and send get or set command via grpc stream. This is very quick solution Server has implemented grpc.health.v1 for readinessprobe too

Run server

Via docker

docker run -it --rm -e REDIS_HOST=redis://redis:6379 -p 3000:3000 gawsoft/cache-grpc-server
# Or via docker-compose 
docker-compose up

For check health

If you want to run this in kubernetes run

grpc_health_probe --addr localhost:3000

Via nodejs/typescript

yarn build
yarn start

Env

HOST=0.0.0.0:3000
REDIS_HOST=127.0.0.1:6379

# Setup TLS
#TLS_INSECURE=false
#TLS_KEY_PATH=/etc/ssl/key.pem
#TLS_CERT_PATH=/etc/ssl/cert.pem

# For mutual tls
#TLS_CA_CERT_PATH=/etc/ssl/ca.cert
#TLS_VERIFY_CLIENT_CERT=true

ProtoBuf

rpc Get (stream GetRequest) returns (stream GetResponse);
rpc Exists (stream GetRequest) returns (stream ExistsResponse);
rpc Set (stream SetRequest) returns (stream SetResponse);

Use as a library (Custom storage strategy)

If you dont want to use Redis as a storage you can write custom storage class with Interface StorageStrategyInterface

npm install cache-grpc-server
import { NestFactory } from '@nestjs/core';
import { AppModule, GrpcClientOptions, SetRequestInterface, StorageStrategyInterface } from 'cache-grpc-server'
import { MicroserviceOptions } from '@nestjs/microservices';
import { Injectable } from '@nestjs/common';

@Injectable()
class CustomStorageStrategy implements StorageStrategyInterface
{
  async existsMulti(keys: string[]): Promise<boolean[]> {
    return [true, false];
  }
  async getMulti(keys: string[]): Promise<string[]> {
    return ['a','b'];
  }
  async save(data: SetRequestInterface): Promise<string> {
    return "test"
  }
}

export async function bootstrap() {
  // Here inject custom storage strategy
  const app = await NestFactory.create(AppModule.register(CustomStorageStrategy));
  const grpcClientOptions = app.get(GrpcClientOptions);
  app.connectMicroservice<MicroserviceOptions>(grpcClientOptions.getOptions());

  await app.startAllMicroservices();
  await app.init();
  return app;
}

bootstrap();

Tests

E2E tests

yarn test:e2e

Example client

ts-node examples/client-set.ts
ts-node examples/client-get.ts