SHSE / redis-proxy

Caching Redis proxy.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redis Proxy

Caching Redis proxy with HTTP and Redis API.

Tryout HTTP API:

docker-compose up -d redis app
docker-compose exec redis redis-cli SET hello world
curl $(docker-compose port app 80)/values/hello

Tryout Redis API:

docker-compose up -d redis app
docker-compose exec redis redis-cli SET hello world
redis-cli -p $(docker-compose port app 6379 | cut -d : -f 2) GET hello

The solution is written in Python 3.6.

Features

  • Restful HTTP API
  • Limited Redis API (only GET and PING)
  • Asynchronous I/O
  • Redis backend connection pooling
  • Supports both string and binary keys
  • Health check

Configuration

The proxy is configured via environment variables:

Name Description
LISTEN_PORT Port the HTTP API listens on (default: 80).
WORKERS Number of worker processes (default: 1).
REDIS_CONNECT Redis connection string (e.g.: redis://localhost:6379).
REDIS_DB Redis database index to connect (default: 0).
MAX_CONCURRENCY Maximum concurrent connections to the Redis backend (default: 1).
CACHE_CAPACITY Cache capacity.
CACHE_TTL Cache global ttl.
REDIS_SERVER_LISTEN_PORT Port the Redis API listens on (default: 6379). Set 0 to disable.
REDIS_SERVER_TIMEOUT Redis API command timeout (default: 1s).

HTTP API

The proxy exposes HTTP Restful API for getting values.

It supports both string keys:

GET /values/<string_key>;

and binary keys as base64 encoded strings (b=1 query parameter must be set):

GET /values/<base64_encoded_binary_key>?b=1

Cache

LRU cache with global expiration.

Read and write complexity is O(1).

Tests

Prerequisites:

  • docker 17.09.0+
  • docker-compose 3.4+

Use this command to run tests:

make test

The command runs tests using docker-compose.

It takes about a minute to build everything and run all the tests.

The test suite has both integration and unit tests.

Integration tests are relying on docker-compose to spin up Redis instance.

TODO

  • Prometheus metrics endpoint
  • Structured logging in JSON format
  • Cache control headers

About

Caching Redis proxy.


Languages

Language:Python 99.0%Language:Makefile 1.0%