Skip to content

Commit 54449e7

Browse files
committed
Initial Commit
0 parents  commit 54449e7

File tree

12 files changed

+867
-0
lines changed

12 files changed

+867
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage.html
2+
coverage.txt
3+
redis_lru_cache

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sudo: required
2+
services:
3+
- docker
4+
5+
script:
6+
- docker-compose up -d redis
7+
- docker-compose up golang
8+
- docker-compose run golang go build -o redis_lru_cache .
9+
- docker-compose down
10+
11+
notifications:
12+
email: false
13+
14+
after_success:
15+
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MAIN := redis_lru_cache
2+
3+
all: $(MAIN)
4+
@echo '$(MAIN)' has been compiled
5+
6+
$(MAIN): build
7+
8+
test:
9+
docker-compose up -d redis
10+
docker-compose up golang
11+
docker-compose down
12+
13+
run:
14+
docker-compose up
15+
docker-compose down
16+
17+
build:
18+
docker-compose run golang go build -o $(MAIN) .
19+
20+
clean:
21+
docker-compose run golang rm ./$(MAIN)
22+
docker-compose down

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# redis-cache
2+
3+
[![Build status](https://travis-ci.org/mramshaw/redis-cache.svg?branch=master)](https://travis-ci.org/mramshaw/redis-cache)
4+
[![Coverage Status](http://codecov.io/github/mramshaw/redis-cache/coverage.svg?branch=master)](http://codecov.io/github/mramshaw/redis-cache?branch=master)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/mramshaw/redis-cache?style=flat-square)](https://goreportcard.com/report/github.com/mramshaw/redis-cache)
6+
[![GoDoc](https://godoc.org/github.com/mramshaw/redis-cache?status.svg)](https://godoc.org/github.com/mramshaw/redis-cache)
7+
[![GitHub release](https://img.shields.io/github/release/mramshaw/redis-cache.svg?style=flat-square)](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+
![Deployment](images/deployment.png)
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

docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '2'
2+
3+
networks:
4+
redis-caching:
5+
6+
services:
7+
8+
golang:
9+
image: golang:1.10.1-alpine
10+
networks:
11+
redis-caching:
12+
depends_on:
13+
- redis
14+
ports:
15+
- "80:5000"
16+
volumes:
17+
- ./vendor/src/github.com:/usr/local/go/src/github.com
18+
- .:/go/src/redis-cache
19+
working_dir: /go/src/redis-cache
20+
command: sh ./run-cache-tests.sh
21+
links:
22+
- redis
23+
environment:
24+
REDIS: 'redis-backend:6379'
25+
EXPIRY_TIME: 5000
26+
CACHE_SIZE: 50
27+
PORT: '5000'
28+
29+
redis:
30+
image: redis:4.0.9-alpine
31+
networks:
32+
redis-caching:
33+
aliases:
34+
- redis-backend
35+
restart: unless-stopped
36+
ports:
37+
- "6379:6379"

images/deployment.png

18.6 KB
Loading

0 commit comments

Comments
 (0)