caffeinum / redis-nodejs-proxy

Caching NodeJS proxy over Redis instance. Plus Docker!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redis-nodejs-proxy

Intro

Sometimes even Redis is too slow. So we cache his requests in NodeJS.

Run

Project uses Docker and has Makefile. You can run plain JS, if you prefer, or run out-of-the-box Dockerized setup.

Running with NodeJS

  1. Configure settings in .env file.
# default values:
PORT=3000
REDIS_ADDR=127.0.0.1
REDIS_PORT=6379
CACHE_EXPIRY_TIME=3600
CACHE_CAPACITY=10000
  1. Install Node packages and build app.
npm i
npm run start # in dev mode
  1. Run built version
npm run build
node dist
  1. Test:
curl localhost:3000/test1
curl localhost:3000/test1
curl localhost:3000/test2

Running with Docker

  1. Setup environment variables for Docker compose:
# docker-compose.yml
...
  environment:
    - PORT=3000
    - REDIS_ADDR=host.docker.internal
    - REDIS_PORT=6379
    - CACHE_EXPIRY_TIME=3600
    - CACHE_CAPACITY=10000
    - NODE_ENV=production
...
  1. Run Docker containers:
make
  1. Run tests
make test

Contribution

Feel free to comment

LICENSE

[LICENSE]

MIT

About

Caching NodeJS proxy over Redis instance. Plus Docker!


Languages

Language:TypeScript 83.4%Language:Shell 10.9%Language:Makefile 5.3%Language:Dockerfile 0.4%