MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / handle_hget

Function handle_hget

nodedb/src/control/server/resp/handler_hash.rs:16–46  ·  view source on GitHub ↗
(
    cmd: &RespCommand,
    session: &RespSession,
    state: &SharedState,
)

Source from the content-addressed store, hash-verified

14use super::session::RespSession;
15
16pub(super) async fn handle_hget(
17 cmd: &RespCommand,
18 session: &RespSession,
19 state: &SharedState,
20) -> RespValue {
21 if cmd.argc() < 2 {
22 return RespValue::err("ERR wrong number of arguments for 'hget' command");
23 }
24
25 let key = cmd.args[0].clone();
26 let field = cmd.arg_str(1).unwrap_or("").to_string();
27
28 let plan = PhysicalPlan::Kv(KvOp::FieldGet {
29 collection: session.collection.clone(),
30 key,
31 fields: vec![field.clone()],
32 });
33
34 match dispatch_kv(state, session, plan).await {
35 Ok(resp) if resp.status == Status::Ok => {
36 let json: serde_json::Value = sonic_rs::from_slice(&resp.payload).unwrap_or_default();
37 match json.get(&field) {
38 Some(serde_json::Value::Null) | None => RespValue::nil(),
39 Some(serde_json::Value::String(s)) => RespValue::bulk_str(s),
40 Some(v) => RespValue::bulk(v.to_string().into_bytes()),
41 }
42 }
43 Ok(_) => RespValue::nil(),
44 Err(e) => RespValue::err(format!("ERR {e}")),
45 }
46}
47
48pub(super) async fn handle_hmget(
49 cmd: &RespCommand,

Callers 1

executeFunction · 0.85

Calls 7

dispatch_kvFunction · 0.85
argcMethod · 0.80
to_stringMethod · 0.80
arg_strMethod · 0.80
errFunction · 0.50
cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected