Skip to content

A distributed in-memory store that implements the Redis Protocol

Notifications You must be signed in to change notification settings

SidakM-zz/ElRedis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElRedis

ElRedis is a distributed and parallel in-memory key value store built with Elixir. ElRedis uses the Redis Serialization Protocol for communications over TCP to ensure compatibility with existing Redis client libraries.

Installation

To compile and run this project install elixir and then:

git clone [email protected]:SidakM/ElRedis.git
cd ElRedis
mix run --no-halt

Note that the above runs only a single ElRedis node.

To run multiple ElRedis nodes in a cluster edit hosts.exs. By default the cluster is configured to run with two nodes and each can be started with:

cd ElRedis
elixir --name [email protected] --cookie cookie -S mix run --no-halt

and in another terminal on the same network or computer

cd ElRedis
elixir --name [email protected] --cookie cookie -S mix run --no-halt

Here [email protected] is the unique identifier of the first node and cookie is the shared secret each node utilizes for authentication to join the cluster.

Overview and Design

I built this project as I was learning Elixir and wanted to create a distributed application. This project was inspired by CurioDb a similar but more developed project which uses Scala and Akka.

Every key/value pair in the cluster is an actor. Thus,the state of any key/value pair is stored in its actor and manipulated when it receives a message from another process. These key/value actors are distributed (sharded) across multiple ElRedis Nodes so that they can be manipulated concurrently.

LifeCycle of a Connection
  • A client connects to the tcp_server actor (tcp_server.ex). There must be atleast one node in the cluster which runs this actor (By default all nodes run a tcp_server)
  • The tcp_server creates a handler actor(handler.ex) for the client connection. The handler manages the client connection while also decoding incoming messages and encoding outgoing messages with the Redis Serialization Protocol.
  • When a client sends a valid command the handler forwards the command to the appropriate node_manager (node_manager.ex). There is a node-manager running on every ElRedis Node and is responsible for managing a portion of the entire cluster's keyspace.
  • The node-manager CRUDs keys by messaging the individual key/value actor.
  • The Key/Value actor (key_value.ex) manipulates its own state andresponds to the node-manager. This response propagates to the connection handler and is encoded before being sent to the client

Note: Keys are allocated to ElRedis Nodes using consistent hashing. The ring_manager actor(ring_manager.ex) runs on each ElRedis Node and decides the ElRedis Node on which the key should be allocated. The ring_manager uses libring to form the hash ring for key distribution across ElRedis Nodes.

Usage and Testing

Note: This project is very alpha so use with much needed caution.

Clients can connect to the tcp_server and send commands encoded in the Redis Serialization Protocol. The tcp_server can be configured in tcp_server.exs. The list of currently supported Redis commands can be found in command.ex. A command is queued to a ElRedis Node based on the key associated with the command and the chosen Node's position on the hash_ring. Since ElRedis Nodes process commands in parallel, introducing more nodes(across different machines) allows for keys (which are sharded across different ElRedis Nodes) to be manipulated simultaneously.

Testing

To run the project tests:

cd ElRedis
mix test

Next Steps

  • supporting additional Redis datatypes
  • data persistence
  • automatic cluster resizing
  • benchmarking

About

A distributed in-memory store that implements the Redis Protocol

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages