A simple, light-weight version of Redis, an in-memory data structure store. Built with Vue 3. Check out the app here: https://ledis-quanphan.netlify.app/.
The black box at the end of the page is the command line. Type a command, press enter, and the result is displayed in the console (the upper white part).
Here are the list of commands that can be used:
- SET
- GET
- SADD
- SREM
- SMEMBERS
- SINTER
- KEYS
- DEL
- EXPIRE
- TTL
- SAVE
- RESTORE
- RESET
The arguments of these commands are exactly the same as those of Redis. Hence, the Redis website is a the go-to source of reference of syntax: https://redis.io/commands/
Ledis runs entirely on a single web page, and requires no back-end server or database. This means the state of the app does not persist between page reloads.
Design of Ledis is broken down into 2 parts:
- User interface (UI)
- Mock server
The UI was built with Vue 3. The component structure is simple:
App
CommandLine
Line
CommandLine
is the component that wraps around the (black) console area. Each Line
contains a previous command or the result of a previous command.
In the mock-server
folder, I create a database
variable to act as the database of the app (this "database" is not preserved between page reloads of course). Along with this constant is multiple functions that modify the mock database.
There are two reasons why I save the state of the app into a JS variable instead of a reactive object in the App
component:
- I want the mock server to resemble a real server as much as possible, and an app with a back-end server will not save its database live in the front-end.
- I have already had a reactive object (
result
) in theApp
component to determine what should be rendered in theLine
component(s) and whenApp
should re-render, so declaring another reactive object to serve as a database is redundant.
The structure of the mock database is as followed:
database {
key1: {
timeOut: Number,
value: String | Set,
},
key2: {
timeOut: Number,
value: String | Set,
},
...
}
Step 1: Build user interface with Vue
Step 2: Build mock-server
Step 3: Testing with vue-test-utils
and jest
Step 4: Final UI touch up
This is my first time writing tests for a Vue application. I used vue-test-utils
and jest
. I learnt how to conduct unit testing with each component in the Vue application, and with each function in the mock server.
-
If the user passes more arguments than required a command, the program will ignore the redundant arguments. For example,
DEL
requires 1 argument. If the user passes 2 arguments (e.gDEL hello name
), the program will ignore the second argument. -
The command line is case-sensitive.
- When a timeout is set, the key will be expired. If the user sets the timeout for
key1
as5
,key1
will be deleted after 5 seconds.