Skip to main content

make_simple_redis

Function make_simple_redis 

Source
pub fn make_simple_redis(req: &Msg, pool: &MbufPool, payload: &[u8]) -> Msg
Expand description

Build a synthetic Redis-status response carrying payload as the on-the-wire reply bytes.

The constructed message inherits the request’s id (so the dispatcher can pair them), sets is_request to false, marks the type as MsgType::RspRedisStatus, and attaches a single mbuf containing payload (verbatim, no encoding). Use this for synthesized replies whose wire form is fixed (+OK\r\n, +PONG\r\n, …).

§Examples

use dynomite::io::mbuf::MbufPool;
use dynomite::msg::{response, Msg, MsgType};

let req = Msg::new(7, MsgType::ReqRedisQuit, true);
let pool = MbufPool::default();
let rsp = response::make_simple_redis(&req, &pool, b"+OK\r\n");
assert_eq!(rsp.id(), 7);
assert_eq!(rsp.ty(), MsgType::RspRedisStatus);
assert_eq!(rsp.mlen(), 5);