[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5797":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":27,"readmeContent":28,"aiSummary":29,"trendingCount":16,"starSnapshotCount":16,"syncStatus":30,"lastSyncTime":31,"discoverSource":32},5797,"mini-redis","tokio-rs\u002Fmini-redis","tokio-rs","Incomplete Redis client and server implementation using Tokio - for learning purposes only","",null,"Rust",4704,574,47,24,0,3,11,45,14,30.28,"MIT License",false,"master",true,[],"2026-06-12 02:01:14","# mini-redis\n\n`mini-redis` is an incomplete, idiomatic implementation of a\n[Redis](https:\u002F\u002Fredis.io) client and server built with\n[Tokio](https:\u002F\u002Ftokio.rs).\n\nThe intent of this project is to provide a larger example of writing a Tokio\napplication.\n\n**Disclaimer** Please don't use mini-redis in production. This project is\nintended to be a learning resource, and omits various parts of the Redis\nprotocol because implementing them would not introduce any new concepts. We will\nnot add new features because you need them in your project — use one of the\nfully featured alternatives instead.\n\n## Why Redis\n\nThe primary goal of this project is teaching Tokio. Doing this requires a\nproject with a wide range of features with a focus on implementation simplicity.\nRedis, an in-memory database, provides a wide range of features and uses a\nsimple wire protocol. The wide range of features allows demonstrating many Tokio\npatterns in a \"real world\" context.\n\nThe Redis wire protocol documentation can be found [here](https:\u002F\u002Fredis.io\u002Ftopics\u002Fprotocol).\n\nThe set of commands Redis provides can be found\n[here](https:\u002F\u002Fredis.io\u002Fcommands).\n\n\n## Running\n\nThe repository provides a server, client library, and some client executables\nfor interacting with the server.\n\nStart the server:\n\n```\nRUST_LOG=debug cargo run --bin mini-redis-server\n```\n\nThe [`tracing`](https:\u002F\u002Fgithub.com\u002Ftokio-rs\u002Ftracing) crate is used to provide structured logs.\nYou can substitute `debug` with the desired [log level][level].\n\n[level]: https:\u002F\u002Fdocs.rs\u002Ftracing-subscriber\u002Flatest\u002Ftracing_subscriber\u002Ffilter\u002Fstruct.EnvFilter.html#directives\n\nThen, in a different terminal window, the various client [examples](examples)\ncan be executed. For example:\n\n```\ncargo run --example hello_world\n```\n\nAdditionally, a CLI client is provided to run arbitrary commands from the\nterminal. With the server running, the following works:\n\n```\ncargo run --bin mini-redis-cli set foo bar\n\ncargo run --bin mini-redis-cli get foo\n```\n\n## OpenTelemetry\n\nIf you are running many instances of your application (which is usually the case\nwhen you are developing a cloud service, for example), you need a way to get all\nof your trace data out of your host and into a centralized place. There are many\noptions here, such as Prometheus, Jaeger, DataDog, Honeycomb, AWS X-Ray etc.\n\nWe leverage OpenTelemetry, because it's an open standard that allows for a\nsingle data format to be used for all the options mentioned above (and more).\nThis eliminates the risk of vendor lock-in, since you can switch between\nproviders if needed.\n\n### AWS X-Ray example\n\nTo enable sending traces to X-Ray, use the `otel` feature:\n```\nRUST_LOG=debug cargo run --bin mini-redis-server --features otel\n```\n\nThis will switch `tracing` to use `tracing-opentelemetry`. You will need to\nhave a copy of AWSOtelCollector running on the same host.\n\nFor demo purposes, you can follow the setup documented at\nhttps:\u002F\u002Fgithub.com\u002Faws-observability\u002Faws-otel-collector\u002Fblob\u002Fmain\u002Fdocs\u002Fdevelopers\u002Fdocker-demo.md#run-a-single-aws-otel-collector-instance-in-docker\n\n## Supported commands\n\n`mini-redis` currently supports the following commands.\n\n* [PING](https:\u002F\u002Fredis.io\u002Fcommands\u002Fping)\n* [GET](https:\u002F\u002Fredis.io\u002Fcommands\u002Fget)\n* [SET](https:\u002F\u002Fredis.io\u002Fcommands\u002Fset)\n* [PUBLISH](https:\u002F\u002Fredis.io\u002Fcommands\u002Fpublish)\n* [SUBSCRIBE](https:\u002F\u002Fredis.io\u002Fcommands\u002Fsubscribe)\n\nThe Redis wire protocol specification can be found\n[here](https:\u002F\u002Fredis.io\u002Ftopics\u002Fprotocol).\n\nThere is no support for persistence yet.\n\n## Tokio patterns\n\nThe project demonstrates a number of useful patterns, including:\n\n### TCP server\n\n[`server.rs`](src\u002Fserver.rs) starts a TCP server that accepts connections,\nand spawns a new task per connection. It gracefully handles `accept` errors.\n\n### Client library\n\n[`client.rs`](src\u002Fclients\u002Fclient.rs) shows how to model an asynchronous client. The\nvarious capabilities are exposed as `async` methods.\n\n### State shared across sockets\n\nThe server maintains a [`Db`] instance that is accessible from all connected\nconnections. The [`Db`] instance manages the key-value state as well as pub\u002Fsub\ncapabilities.\n\n[`Db`]: src\u002Fdb.rs\n\n### Framing\n\n[`connection.rs`](src\u002Fconnection.rs) and [`frame.rs`](src\u002Fframe.rs) show how to\nidiomatically implement a wire protocol. The protocol is modeled using an\nintermediate representation, the `Frame` structure. `Connection` takes a\n`TcpStream` and exposes an API that sends and receives `Frame` values.\n\n### Graceful shutdown\n\nThe server implements graceful shutdown. [`tokio::signal`] is used to listen for\na SIGINT. Once the signal is received, shutdown begins. The server stops\naccepting new connections. Existing connections are notified to shutdown\ngracefully. In-flight work is completed, and the connection is closed.\n\n[`tokio::signal`]: https:\u002F\u002Fdocs.rs\u002Ftokio\u002F*\u002Ftokio\u002Fsignal\u002F\n\n### Concurrent connection limiting\n\nThe server uses a [`Semaphore`] limits the maximum number of concurrent\nconnections. Once the limit is reached, the server stops accepting new\nconnections until an existing one terminates.\n\n[`Semaphore`]: https:\u002F\u002Fdocs.rs\u002Ftokio\u002F*\u002Ftokio\u002Fsync\u002Fstruct.Semaphore.html\n\n### Pub\u002FSub\n\nThe server implements non-trivial pub\u002Fsub capability. The client may subscribe\nto multiple channels and update its subscription at any time. The server\nimplements this using one [broadcast channel][broadcast] per channel and a\n[`StreamMap`] per connection. Clients are able to send subscription commands to\nthe server to update the active subscriptions.\n\n[broadcast]: https:\u002F\u002Fdocs.rs\u002Ftokio\u002F*\u002Ftokio\u002Fsync\u002Fbroadcast\u002Findex.html\n[`StreamMap`]: https:\u002F\u002Fdocs.rs\u002Ftokio-stream\u002F*\u002Ftokio_stream\u002Fstruct.StreamMap.html\n\n### Using a `std::sync::Mutex` in an async application\n\nThe server uses a `std::sync::Mutex` and **not** a Tokio mutex to synchronize\naccess to shared state. See [`db.rs`](src\u002Fdb.rs) for more details.\n\n### Testing asynchronous code that relies on time\n\nIn [`tests\u002Fserver.rs`](tests\u002Fserver.rs), there are tests for key expiration.\nThese tests depend on time passing. In order to make the tests deterministic,\ntime is mocked out using Tokio's testing utilities.\n\n## Contributing\n\nContributions to `mini-redis` are welcome. Keep in mind, the goal of the project\nis **not** to reach feature parity with real Redis, but to demonstrate\nasynchronous Rust patterns with Tokio.\n\nCommands or other features should only be added if doing so is useful to\ndemonstrate a new pattern.\n\nContributions should come with extensive comments targeted to new Tokio users.\n\nContributions that only focus on clarifying and improving comments are very\nwelcome.\n\n## License\n\nThis project is licensed under the [MIT license](LICENSE).\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in `mini-redis` by you, shall be licensed as MIT, without any\nadditional terms or conditions.\n","`mini-redis` 是一个使用 Tokio 构建的不完整的 Redis 客户端和服务端实现，旨在作为学习资源。该项目的核心功能包括提供了一个简化的Redis协议实现，并展示了如何用Rust和Tokio构建网络应用。它适合用于教育场景，帮助开发者理解异步编程、网络通信等概念。值得注意的是，由于其设计初衷并非为生产环境使用，因此对于需要完整特性的项目，建议选择其他成熟的替代方案。此外，`mini-redis` 还支持通过OpenTelemetry进行分布式追踪，方便在开发云服务时收集和分析跨多个实例的跟踪数据。",2,"2026-06-11 03:05:03","top_language"]