{"id":17130125,"url":"https://github.com/akshaykmr/redex","last_synced_at":"2025-04-13T07:23:51.729Z","repository":{"id":86065645,"uuid":"165494389","full_name":"akshaykmr/redex","owner":"akshaykmr","description":"A redis-server implemented in Elixir. You can connect to this server using redis-cli and execute few implemented commands like get, set, setx","archived":false,"fork":false,"pushed_at":"2020-07-04T07:59:50.000Z","size":20,"stargazers_count":19,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T05:42:41.835Z","etag":null,"topics":["elixir","redis"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akshaykmr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-13T10:54:54.000Z","updated_at":"2024-07-03T02:11:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"315366cd-500f-4118-9c1a-4731a6c2dbd8","html_url":"https://github.com/akshaykmr/redex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshaykmr%2Fredex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshaykmr%2Fredex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshaykmr%2Fredex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshaykmr%2Fredex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akshaykmr","download_url":"https://codeload.github.com/akshaykmr/redex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248676689,"owners_count":21143950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","redis"],"created_at":"2024-10-14T19:11:31.356Z","updated_at":"2025-04-13T07:23:51.133Z","avatar_url":"https://github.com/akshaykmr.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Redex\n\n###  A naive redis-server implemented in Elixir\n\nYou can connect to this server using `redis-cli` and execute a few implemented commands like `get, set, setx`!\nIt talks in the Redis's [`RESP`](https://redis.io/topics/protocol) protocol and serves clients over TCP just like the real thing.\n\n### How to run it?\n\n- You must have [elixir installed](https://elixir-lang.org/install.html)\n- In project root:\n  1. `mix deps.get`\n  2. `iex -S mix`\n  3. `Redex.Server.start_link port: 6379`\n\n- run tests with: mix test\n\n\n### Code overview:\n\nHere's the breakdown in brief:\n- `redex_server.ex` -\u003e TCP server. For each accepted socket, we start a `Task` to serve the client.\n- `resp_decoder.ex` -\u003e streaming resp parser. coverts bytes from the client to elixir data structures, in this case, command and args.\n- `command.ex` -\u003e execute the parsed redis command.\n- `resp_encoder.ex` -\u003e encode to resp duh, then send it to the client.\n- `kv.ex` -\u003e Simple kv state provided by Agent.\n\nI think this is a cool place to play with Elixir, I come back to it when I need a refresher.\nThis project has a TCP server, binaries, parsing, state, and tests! You can follow the git history commit by commit.\nLet me know if things can be done in a better way.\n\n### Credits:\n\n[Paul](https://rohitpaulk.com) - for hosting [Build your own Redis challenge!](https://rohitpaulk.com/articles/redis-challenge)\nHe has also written posts on how - [over here](https://rohitpaulk.com/articles/redis-0)\n\nWe did this challenge in Python. But I so-wanted to build this in Elixir, along with test-suite, so here it is. \n\n\n### Misc: Some benchmarks for fun!\n\nSpoiler alert - it's not faster than the C server, duh. But I wanted to play around.\n\nWe only test for `GET` and `SET` commands, since those are the ones we've implemented (essentials that is, since we don't involve disk at all for things like persistence logs).\n\nTools used:\nRedis version: 4\n`redis-benchmark` comes installed with Redis. [Know more about redis-benchmark](https://redis.io/topics/benchmarks).\n\n```\nsystem specs:\nRyzen 3700x - 8 cores, 16 thread. liquid cooled 🧐\n32GB ram\nubuntu 18.04\nulimit -n 65535 for the server processes. (the maximum number of open file descriptors)\n```\n\n\n\n```\n- Simple test: 50 clients, 100000 requests\n\n# Redis\n➜  ~ redis-benchmark -t GET,SET -p 7000\n====== SET ======\n  100000 requests completed in 0.79 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n100.00% \u003c= 0 milliseconds\n126903.55 requests per second\n\n====== GET ======\n  100000 requests completed in 0.74 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n100.00% \u003c= 1 milliseconds\n100.00% \u003c= 1 milliseconds\n135501.36 requests per second\n\n# Redex\n➜  ~ redis-benchmark -t GET,SET -p 6000\n====== SET ======\n  100000 requests completed in 0.82 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.92% \u003c= 1 milliseconds\n99.97% \u003c= 2 milliseconds\n100.00% \u003c= 3 milliseconds\n100.00% \u003c= 4 milliseconds\n121802.68 requests per second\n\n====== GET ======\n  100000 requests completed in 0.81 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.97% \u003c= 1 milliseconds\n99.99% \u003c= 2 milliseconds\n100.00% \u003c= 2 milliseconds\n122850.12 requests per second\n\n** about similar performance?\n```\n\n```\nLet's increase requests by x10\n\n# Redis \n➜  ~ redis-benchmark -t GET,SET -p 7000 -n 1000000\n====== SET ======\n  1000000 requests completed in 7.36 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n100.00% \u003c= 1 milliseconds\n100.00% \u003c= 1 milliseconds\n135888.03 requests per second\n\n====== GET ======\n  1000000 requests completed in 7.34 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n100.00% \u003c= 1 milliseconds\n100.00% \u003c= 1 milliseconds\n136147.05 requests per second\n\n\n# Redex\n➜  ~ redis-benchmark -t GET,SET -p 6000 -n 1000000\n====== SET ======\n  1000000 requests completed in 8.35 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.74% \u003c= 1 milliseconds\n99.91% \u003c= 2 milliseconds\n99.96% \u003c= 3 milliseconds\n99.98% \u003c= 4 milliseconds\n99.99% \u003c= 5 milliseconds\n99.99% \u003c= 6 milliseconds\n99.99% \u003c= 7 milliseconds\n100.00% \u003c= 8 milliseconds\n100.00% \u003c= 9 milliseconds\n100.00% \u003c= 10 milliseconds\n100.00% \u003c= 11 milliseconds\n100.00% \u003c= 13 milliseconds\n100.00% \u003c= 14 milliseconds\n100.00% \u003c= 15 milliseconds\n100.00% \u003c= 16 milliseconds\n100.00% \u003c= 203 milliseconds\n100.00% \u003c= 204 milliseconds\n100.00% \u003c= 408 milliseconds\n100.00% \u003c= 828 milliseconds\n100.00% \u003c= 828 milliseconds\n119703.13 requests per second\n\n====== GET ======\n  1000000 requests completed in 8.04 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.82% \u003c= 1 milliseconds\n99.96% \u003c= 2 milliseconds\n99.98% \u003c= 3 milliseconds\n99.99% \u003c= 4 milliseconds\n99.99% \u003c= 5 milliseconds\n100.00% \u003c= 6 milliseconds\n100.00% \u003c= 7 milliseconds\n100.00% \u003c= 10 milliseconds\n100.00% \u003c= 12 milliseconds\n100.00% \u003c= 203 milliseconds\n100.00% \u003c= 412 milliseconds\n100.00% \u003c= 831 milliseconds\n100.00% \u003c= 832 milliseconds\n100.00% \u003c= 1663 milliseconds\n100.00% \u003c= 1664 milliseconds\n100.00% \u003c= 1664 milliseconds\n124424.54 requests per second\n\n** not that far behind, but percentile distribution is all over the place for Redex.\n--------------------------------------------------------------------------------------\n```\n\n```\nLet's add pipelining - https://redis.io/topics/pipelining\n-P sets the pipeline param.\n\n# Redis\n➜  ~ redis-benchmark -t GET,SET -p 7000 -n 1000000 -P 10\n====== SET ======\n  1000000 requests completed in 0.90 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.80% \u003c= 1 milliseconds\n100.00% \u003c= 1 milliseconds\n1116071.38 requests per second\n\n====== GET ======\n  1000000 requests completed in 0.89 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.97% \u003c= 1 milliseconds\n100.00% \u003c= 1 milliseconds\n1119820.88 requests per second\n\n# Damn 7s -\u003e 0.9s, what if we pipeline more?\n# Redis\n➜  ~ redis-benchmark -t GET,SET -p 7000 -n 1000000 -P 50\n====== SET ======\n  1000000 requests completed in 0.61 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n6.63% \u003c= 1 milliseconds\n99.49% \u003c= 2 milliseconds\n99.74% \u003c= 3 milliseconds\n100.00% \u003c= 3 milliseconds\n1628664.38 requests per second\n\n====== GET ======\n  1000000 requests completed in 0.47 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n38.74% \u003c= 1 milliseconds\n99.49% \u003c= 2 milliseconds\n99.95% \u003c= 3 milliseconds\n100.00% \u003c= 3 milliseconds\n2136752.25 requests per second\n\n\n# Okay lets check Redex\n# Redex\n➜  ~ redis-benchmark -t GET,SET -p 6000 -n 1000000 -P 10\n====== SET ======\n  1000000 requests completed in 6.16 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.84% \u003c= 1 milliseconds\n99.93% \u003c= 2 milliseconds\n99.98% \u003c= 3 milliseconds\n99.99% \u003c= 4 milliseconds\n99.99% \u003c= 203 milliseconds\n99.99% \u003c= 204 milliseconds\n100.00% \u003c= 407 milliseconds\n100.00% \u003c= 408 milliseconds\n100.00% \u003c= 408 milliseconds\n162443.14 requests per second\n\n====== GET ======\n  1000000 requests completed in 6.61 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n99.81% \u003c= 1 milliseconds\n99.93% \u003c= 2 milliseconds\n99.95% \u003c= 3 milliseconds\n99.96% \u003c= 6 milliseconds\n99.97% \u003c= 203 milliseconds\n99.98% \u003c= 204 milliseconds\n99.98% \u003c= 411 milliseconds\n99.98% \u003c= 412 milliseconds\n99.98% \u003c= 835 milliseconds\n99.99% \u003c= 836 milliseconds\n99.99% \u003c= 1663 milliseconds\n99.99% \u003c= 1664 milliseconds\n100.00% \u003c= 3295 milliseconds\n100.00% \u003c= 3295 milliseconds\n151217.30 requests per second\n\n# more pipelining\n# Redex\n➜  ~ redis-benchmark -t GET,SET -p 6000 -n 1000000 -P 50\n====== SET ======\n  1000000 requests completed in 7.21 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n95.27% \u003c= 1 milliseconds\n99.14% \u003c= 2 milliseconds\n99.82% \u003c= 3 milliseconds\n99.90% \u003c= 4 milliseconds\n99.93% \u003c= 207 milliseconds\n99.94% \u003c= 208 milliseconds\n99.97% \u003c= 412 milliseconds\n100.00% \u003c= 412 milliseconds\n138657.80 requests per second\n\n====== GET ======\n  1000000 requests completed in 6.87 seconds\n  50 parallel clients\n  3 bytes payload\n  keep alive: 1\n\n96.30% \u003c= 1 milliseconds\n99.57% \u003c= 2 milliseconds\n99.80% \u003c= 3 milliseconds\n99.81% \u003c= 4 milliseconds\n99.85% \u003c= 5 milliseconds\n99.96% \u003c= 204 milliseconds\n99.98% \u003c= 207 milliseconds\n99.99% \u003c= 208 milliseconds\n100.00% \u003c= 208 milliseconds\n145581.59 requests per second\n\nit's slower with more pipelining. \n```\n\nWelp, I'll have to dig deep into the internals to properly comment on these, or maybe something is off in benchmarking?\nIf you can explain it, let us know :)\n\n#### License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshaykmr%2Fredex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakshaykmr%2Fredex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshaykmr%2Fredex/lists"}