A very simple url shortener redis based
- run
make docker
- run
docker-compose up
- run
make build
- run
make test
A very synthetic APIs usage can be found at the address /api/usage
provided directly by the app
SERVER_PORT: Where the server will listen for incoming requests (default: 5000)
REDIS_HOST: The host were the redis server is listing (default: localhost)
REDIS_PORT: The port were the redis server is listing (default: 6379)
REDIS_PASSWORD: The password for the redis connection (default: "")
IN_MEMORY_PERSISTENCE: The flag to switch from redis memory to in-memory persistence (actually non used) (default: false)
We have few cases to care about:
- The user suggests a key
- No collision: The key doesn't exist yet, so we can simply add it
- There is collision with another key and, the URL content is the same: Nothing to do here, we can safely return the suggested key
- There is collision with another key and, the URL content is not the same: Here we need to reject the newer suggested key because is already taken
- The user doesn't suggest a key, so we calculate an hash code from the URL text:
- No collision: The key doesn't exist yet, so we can simply add it
- There is collision with another key, the URL content is the same: Nothing to do here, we can safely return the calculated key
- There is collision with another key and, the URL content is not the same: Here we need to generate a non-existing yet random key and persist the URL with that
The tests cover only the part where there is more logic, the other part should be tested but out of scope of the experiment.