https://github.com/shortishly/mcd
memcached API compatible server (meta, text and binary) and client
https://github.com/shortishly/mcd
erlang-otp memcached server
Last synced: 25 days ago
JSON representation
memcached API compatible server (meta, text and binary) and client
- Host: GitHub
- URL: https://github.com/shortishly/mcd
- Owner: shortishly
- License: apache-2.0
- Created: 2022-11-09T08:45:54.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-19T21:44:00.000Z (over 2 years ago)
- Last Synced: 2025-12-19T19:17:10.645Z (6 months ago)
- Topics: erlang-otp, memcached, server
- Language: Erlang
- Homepage: https://shortishly.com/blog/mcd-emulating-memcached-with-statem-and-socket/
- Size: 296 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## What is MCD?
[mcd][mcd-github] is a [memcached][memcached-org] compatible API
server written in [Erlang/OTP 25][erlang-org] using
[ETS][ets-erlang-org] to maintain the cache of data.
It has a TCP [memcached][memcached-org] compatible API on port 11211
offering:
- the original text based [standard
protocol][memcached-protocol-text];
- the [binary protocol][memcached-protocol-binary];
- the text based [meta protocol][memcached-protocol-meta] (which
also deprecates the binary protocol).

## Build
[mcd][mcd-github] uses [erlang.mk][erlang-mk] with [Erlang/OTP
25][erlang-org] to build:
```shell
make
```
## Run
To run [mcd][mcd-github] with an [Erlang Shell][erlang-shell]
listening on port 11211:
```shell
make shell
```
## Docker
To run [mcd][mcd-github] as a docker container:
```shell
docker run \
--pull always \
--detach \
--publish 11211:11211 \
--rm \
ghcr.io/shortishly/mcd:latest
```
## API Example
The text based API is the easiest to try out from the command line
with a simple set and get:
```shell
telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
set foo 0 0 6
fooval
STORED
get foo
VALUE foo 0 6
fooval
END
```
The implementation uses some recently introduced features of
[Erlang/OTP][erlang-org]:
- [socket][erlang-org-socket] for all communication
- [send_request][erlang-org-send-request-4] for asynchronous request
and response.
- the [timeout][erlang-org-statem-timeout] feature of
[statem][erlang-org-statem] to expire items from the cache.
[erlang-mk]: https://erlang.mk
[erlang-org-send-request-4]: https://www.erlang.org/doc/man/gen_statem.html#send_request-4
[erlang-org-socket]: https://www.erlang.org/doc/man/socket.html
[erlang-org-statem-timeout]: https://www.erlang.org/doc/man/gen_statem.html#type-timeout_event_type
[erlang-org-statem]: https://www.erlang.org/doc/man/gen_statem.html
[erlang-org]: https://www.erlang.org
[erlang-shell]: https://www.erlang.org/doc/man/shell.html
[ets-erlang-org]: https://www.erlang.org/doc/man/ets.html
[mcd-github]: https://github.com/shortishly/mcd
[memcached-org]: https://memcached.org/
[memcached-protocol-binary]: https://github.com/memcached/memcached/wiki/BinaryProtocolRevamped
[memcached-protocol-meta]: https://github.com/memcached/memcached/wiki/MetaCommands
[memcached-protocol-text]: https://github.com/memcached/memcached/wiki/Commands