kevincui1993 / RedisProxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RedisProxy

Architecture

The redis proxy is implemented with python flask. There are three major compoents: Proxy, Cache, and RedisFence. Their relationships are illustrated by this chart. image

How The Code Works

When a request get to the proxy, it first tries to fetch from the cache. If it does not exists in the cache or the cache entry has expired, then it will incur a redis operation to fetch from the backing redis server. Once the record is succesfully fetched from redis, it stores that record to the cache. If the cache reaches the capacity, it removes the least recent used cache entry implemented using double linked link.

Cache Runtime Complexity

This is implemented using a double linked list. get -> O(1) set -> O(1)

How To Run The Proxy Service

All the configuration is in config.py. Once you are happy with the config, you can start the proxy service by running:

make run

How To Run Unit Tests and System Tests

This requires valid backing redis server host and port specified in config.py

make test

How To Send HTTP Request to Proxy Service With Curl

Assuming the proxy service listens on localhost and port 8000

curl http://127.0.0.1:8000/get?key="test"

Time Spent

Create python flask framework - 1 hour.
Implement LRU cache - 1 hour.
Implement proxy logic - 1 hour.
Implement Redis get with retry - 2 hours.
Unit tests and integration tests - 2 hours.

Unsatisfied Requirement

Bonus Redis Client Protocol - cannot find more time

About

License:MIT License


Languages

Language:Python 95.9%Language:Makefile 4.1%