https://github.com/tidwall/redcon.rs
Redis compatible server framework for Rust
https://github.com/tidwall/redcon.rs
Last synced: 3 months ago
JSON representation
Redis compatible server framework for Rust
- Host: GitHub
- URL: https://github.com/tidwall/redcon.rs
- Owner: tidwall
- License: mit
- Created: 2022-05-14T14:42:30.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-29T23:33:42.000Z (almost 3 years ago)
- Last Synced: 2025-09-17T07:50:02.504Z (4 months ago)
- Language: Rust
- Size: 40 KB
- Stars: 90
- Watchers: 2
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Redis compatible server framework for Rust
## Features
- Create a fast custom Redis compatible server in Rust
- Simple API.
- Support for pipelining and telnet commands.
- Works with Redis clients such as [redis-rs](https://github.com/redis-rs/redis-rs), [redigo](https://github.com/garyburd/redigo), [redis-py](https://github.com/andymccurdy/redis-py), [node_redis](https://github.com/NodeRedis/node_redis), and [jedis](https://github.com/xetorthio/jedis)
- Multithreaded
*This library is also avaliable for [Go](https://github.com/tidwall/redcon) and [C](https://github.com/tidwall/redcon.c).*
## Example
Here's a full [example](examples/kvstore) of a Redis clone that accepts:
- SET key value
- GET key
- DEL key
- PING
- QUIT
```rust
use std::collections::HashMap;
use std::sync::Mutex;
fn main() {
let db: Mutex, Vec>> = Mutex::new(HashMap::new());
let mut s = redcon::listen("127.0.0.1:6380", db).unwrap();
s.command = Some(|conn, db, args|{
let name = String::from_utf8_lossy(&args[0]).to_lowercase();
match name.as_str() {
"ping" => conn.write_string("PONG"),
"set" => {
if args.len() < 3 {
conn.write_error("ERR wrong number of arguments");
return;
}
let mut db = db.lock().unwrap();
db.insert(args[1].to_owned(), args[2].to_owned());
conn.write_string("OK");
}
"get" => {
if args.len() < 2 {
conn.write_error("ERR wrong number of arguments");
return;
}
let db = db.lock().unwrap();
match db.get(&args[1]) {
Some(val) => conn.write_bulk(val),
None => conn.write_null(),
}
}
_ => conn.write_error("ERR unknown command"),
}
});
println!("Serving at {}", s.local_addr());
s.serve().unwrap();
}
```