|
| 1 | +# redis-cache |
| 2 | + |
| 3 | +[](https://travis-ci.org/mramshaw/redis-cache) |
| 4 | +[](http://codecov.io/github/mramshaw/redis-cache?branch=master) |
| 5 | +[](https://goreportcard.com/report/github.com/mramshaw/redis-cache) |
| 6 | +[](https://godoc.org/github.com/mramshaw/redis-cache) |
| 7 | +[](https://github.com/mramshaw/redis-cache/releases) |
| 8 | + |
| 9 | +A redis proxy service |
| 10 | + |
| 11 | +## Deployment |
| 12 | + |
| 13 | +The application will be deployed as follows: |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +## What the code does |
| 18 | + |
| 19 | +The application launches a web server which responds to HTTP requests. |
| 20 | + |
| 21 | +When a request for a specific key is received, the application checks |
| 22 | +its cache for the specified key. If found, the value associated with |
| 23 | +the key is returned via HTTP. If not found, the request is forwarded |
| 24 | +to Redis - if the key is found then the value is stored in the cache |
| 25 | +and the value is returned via HTTP. If not found a 404 is returned. |
| 26 | + |
| 27 | +At application startup a daemon process is launched, which runs from |
| 28 | +time to time and expires any cache entries older than a configurable |
| 29 | +time limit. |
| 30 | + |
| 31 | +The size of the cache may also be specified; only this number of |
| 32 | +entries may be stored in the cache, with older entries being evicted |
| 33 | +to make space for newer entries. |
| 34 | + |
| 35 | +## How to run |
| 36 | + |
| 37 | +1. Download the repo. |
| 38 | + |
| 39 | +2. Unzip it somewhere. |
| 40 | + |
| 41 | +3. Change directory into the repo: |
| 42 | + |
| 43 | + $ cd assignment |
| 44 | + |
| 45 | +4. Type the following to run the tests: |
| 46 | + |
| 47 | + $ make tests |
| 48 | + |
| 49 | +[It may take a few minutes for the docker images to download.] |
| 50 | + |
| 51 | +The results should look as follows (times are GMT): |
| 52 | + |
| 53 | +``` |
| 54 | +$ make test |
| 55 | +docker-compose up -d redis |
| 56 | +Creating network "rediscache_redis-caching" with the default driver |
| 57 | +Creating rediscache_redis_1 ... |
| 58 | +Creating rediscache_redis_1 ... done |
| 59 | +docker-compose up golang |
| 60 | +rediscache_redis_1 is up-to-date |
| 61 | +Creating rediscache_golang_1 ... |
| 62 | +Creating rediscache_golang_1 ... done |
| 63 | +Attaching to rediscache_golang_1 |
| 64 | +golang_1 | Reformatting source code ... |
| 65 | +golang_1 | Vetting source code ... |
| 66 | +golang_1 | Testing source code ... |
| 67 | +golang_1 | 2018/04/14 20:57:57 Running setUpTestData |
| 68 | +golang_1 | === RUN TestHealthCheck |
| 69 | +golang_1 | --- PASS: TestHealthCheck (0.00s) |
| 70 | +golang_1 | === RUN TestCacheHit |
| 71 | +golang_1 | --- PASS: TestCacheHit (0.00s) |
| 72 | +golang_1 | === RUN TestCacheMiss |
| 73 | +golang_1 | --- PASS: TestCacheMiss (0.00s) |
| 74 | +golang_1 | === RUN TestGetExistingRedisKey |
| 75 | +golang_1 | --- PASS: TestGetExistingRedisKey (0.00s) |
| 76 | +golang_1 | === RUN TestGetNonexistentRedisKey |
| 77 | +golang_1 | --- PASS: TestGetNonexistentRedisKey (0.00s) |
| 78 | +golang_1 | === RUN TestGetExpiredCacheKey |
| 79 | +golang_1 | --- PASS: TestGetExpiredCacheKey (5.40s) |
| 80 | +golang_1 | === RUN TestGetExpiredRedisKey |
| 81 | +golang_1 | --- PASS: TestGetExpiredRedisKey (6.00s) |
| 82 | +golang_1 | === RUN TestGetTouchedCacheKey |
| 83 | +golang_1 | --- PASS: TestGetTouchedCacheKey (11.41s) |
| 84 | +golang_1 | PASS |
| 85 | +golang_1 | 2018/04/14 20:58:19 Running tearDownTestData |
| 86 | +golang_1 | ok redis-cache 22.828s |
| 87 | +rediscache_golang_1 exited with code 0 |
| 88 | +docker-compose down |
| 89 | +Stopping rediscache_redis_1 ... done |
| 90 | +Removing rediscache_golang_1 ... done |
| 91 | +Removing rediscache_redis_1 ... done |
| 92 | +Removing network rediscache_redis-caching |
| 93 | +$ |
| 94 | +``` |
| 95 | + |
| 96 | +## Dependencies |
| 97 | + |
| 98 | +The various libraries are bundled in a __vendor__ directory. |
| 99 | + |
| 100 | +This is perhaps not ideal but they would need to be downloaded |
| 101 | +in any case, and it is always nice to have all dependencies |
| 102 | +bundled with source code. |
| 103 | + |
| 104 | +The dependencies are sourced as follows: |
| 105 | + |
| 106 | +``` Bash |
| 107 | +$ GOPATH=`pwd`/vendor/ go get -d -v . |
| 108 | +``` |
| 109 | + |
| 110 | +## To Do |
| 111 | + |
| 112 | +- [ ] Refactor to avoid duplicate mutexes |
| 113 | +- [ ] Refactor to include 12-Factor initialization in code coverage |
| 114 | +- [ ] Add goroutines for multiple clients ([pool](https://godoc.org/github.com/mediocregopher/radix.v2/pool) looks useful) |
| 115 | +- [ ] Add RESP ([respgo](https://github.com/teambition/respgo) looks useful |
| 116 | +- [ ] Add pipelining |
0 commit comments