DB2: Tokio Mini Redis — Commands (Part 4)

Arjun Sunil Kumar
Distributed Systems Engineering
3 min readMay 6, 2022

Hopefully, this will conclude the exploration into mini-redis. The topic would mainly focus on the command folder.

cmd/mod.rs

  • convert the frame to Command object
  • apply() the command
  • get_name() returns the command name

cmd/get.rs

  • new
  • key (GET specific function)
  • parse_frames (called in from_frame inside mod.rs)
  • apply (command pattern apply)
  • into_frame ( complemented byfrom )

cmd/ping.rs

dst here is destination connection

cmd/publish.rs

cmd/set.rs

cmd/unknown.rs

cmd/subscribe.rs

This is the ugliest frog in the commands. May revisit this class later, to understand more.

Contains

  • subscribe : Subscribes the client to one or more channels.
  • unsubscribe : Unsubscribes the client from one or more channels.

Lets understand some of the terms in subscribe.

Pin:

Send + Sync in rust.

https://stackoverflow.com/questions/59428096/understanding-the-send-trait

Stream trait

Drain:

StreamMap:

extend:

https://doc.rust-lang.org/std/iter/trait.Extend.html

Select!:

async_stream::stream!

Conclusion:

We have kind of visited mini-redis on a high level. The content was just an introduction to a mini-project in rust. It gave a brief overview of a lot of concepts in rust, tokio, and async programming. Hopefully, the next sessions would go a little deeper into the code.

Found it Interesting?

Please show your support by 👏

--

--

Arjun Sunil Kumar
Distributed Systems Engineering

Writes on Database Kernel, Distributed Systems, Cloud Technology, Data Engineering & SDE Paradigm. github.com/arjunsk