As part of learning elixir and OTP, I decided to implement the functionality of redis in elixir.
start the server:
mix run --no-halt
I haven't written a cli client yet but you can use telnet
to connect to rediex
telnet <ip> <port>
default ip: 127.0.0.1
default port: 6380
I'll update the README as and when i add more commands
The Application consists of:
- tcp connection supervisor
- database supervisor
- snapshot worker
- rediex uses
:gen_tcp
to spin up a tcp server - tcp connection supervisor creates a new
Task
for every new connection from a client - the code used in this module is reference from the official mix otp guide
- the database supervisor spins up N databases(genservers) to execute incoming commands
- Each genserver stores a certain range of keys depending the
cluster_size
inconfig.exs
- This uses
Registry
from elixir to register the required databases (genservers)
- This is a genserver that calls itself every
snapshot_interval
, collects state from currently running genservers and saves the merged state insnapshot_path
There are lots of commands to be implemented . You can start with the simple ones and create a PR
- You need to register the command in
dispatcher.ex
in the@available_commands
attribute - Each command belongs to a Module eg. Strings, Lists
- Each Module is just an API to interact with a particular
db
(genserver). So you need to add a function that wraps a GenServer call for your command - Each Command is implemented in
ModuleName.Impl
. This is where you actually write some logic for the command - Write a corresponding test for the command you implemented
mix test
mix credo --strict
Please run tests and credo and make sure everything is fine before submitting a PR since they are part of the build process.
- Add persistance (AOF
and snapshot) tcp server to accept multiple clients- sample cli client to interact with rediex