Crates.io | rudis-http |
lib.rs | rudis-http |
version | 0.2.0 |
source | src |
created_at | 2023-05-12 21:32:30.294755 |
updated_at | 2023-05-16 20:21:34.54129 |
description | A minial Redis server with HTTP interface |
homepage | |
repository | https://github.com/lorenzoc25/rudis |
max_upload_size | |
id | 863312 |
size | 38,006 |
A mini version of redis server that provides http interface implemented in Rust. The in-memorry kv-storage is sharded and concurrent safe. Inspired by Tokio's tutorial and Webdis
This is a still work-in-progress project and is not meant to be used in production(yet). Only basic commands like GET and SET are supported. More commands will be added in the future.
There is also the Experimental Version which adapatively uses io_uring
on supported kernels. If kernel does not support io_uring
, it will fall back to using epoll/kqueue
. This version is not published to the crates and therefore needs to be cloned and built locally. It requires nightly rust compiler to be built.
cargo install rudis-http
To run the server, simply run
$ rudis-http
or you can optionally specify the address, num shards (more to be added later)
$ rudis-http -n <num_shards> -a <address_to_listen_on>
# to view all commands, do
$ rudis-http --help
And the server will be listening on the port you specified or 127.0.0.1:6379
by default.
Once the server is up and running, its service can be accessed via http GET request. The following are the supported requests:
GET: <your-url>/GET/<key>
SET: <your-url>/SET/<key>/<value>
The response will be in json format. For a SET, you will be getting the status of this command like
$ curl 'localhost:6379/set/hello/world'
{"SET": "OK"}
# or if SET's arguments are not correct
$ curl 'localhost:6379/set/hello'
{"SET": "Invalid"}
You can also send a POST request with json as key value pair to support a SET command.
$ curl -X POST 'localhost:6379/set' -d '{"hello":"world"}'
{"SET": "OK"}
$ curl -X POST 'localhost:6379/set' -d '{}'
{"SET": "Invalid"}
# for multiple kv pairs
$ curl -X POST 'localhost:6379/set' -d '{"hello":"world", "foo":"bar"}'
{"SET": "OK}
and for get, you will be getting the key value pair if there's a match, or an empty json object if there's no match
$ curl 'localhost:6379/get/hello'
{"hello":"world"}
# if key does not exist
$ curl 'localhost:6379/GET/123'
{}
# if GET's arguments are not correct
$ curl 'localhost:6379/GET'
{"GET": "Invalid"}
Any other types of commands will be responded with an empty json object