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

Function handle_zscore

nodedb/src/control/server/resp/handler_sorted.rs:221–252  ·  view source on GitHub ↗

ZSCORE key member — returns score as bulk string.

(
    cmd: &RespCommand,
    session: &RespSession,
    state: &SharedState,
)

Source from the content-addressed store, hash-verified

219
220/// ZSCORE key member — returns score as bulk string.
221pub(super) async fn handle_zscore(
222 cmd: &RespCommand,
223 session: &RespSession,
224 state: &SharedState,
225) -> RespValue {
226 let Some(member) = cmd.arg(0) else {
227 return RespValue::err("ERR wrong number of arguments for 'zscore' command");
228 };
229
230 let plan = PhysicalPlan::Kv(KvOp::SortedIndexScore {
231 index_name: session.collection.clone(),
232 primary_key: member.to_vec(),
233 });
234
235 match dispatch_kv(state, session, plan).await {
236 Ok(resp) if resp.status == Status::Ok => {
237 let payload_text =
238 crate::data::executor::response_codec::decode_payload_to_json(&resp.payload);
239 if let Ok(json) = sonic_rs::from_str::<serde_json::Value>(&payload_text)
240 && let Some(serde_json::Value::String(score)) = json.get("score")
241 {
242 if score == "null" {
243 return RespValue::nil();
244 }
245 return RespValue::bulk(score.as_bytes().to_vec());
246 }
247 RespValue::nil()
248 }
249 Ok(_) => RespValue::nil(),
250 Err(e) => RespValue::err(format!("ERR {e}")),
251 }
252}

Callers 1

executeFunction · 0.85

Calls 8

dispatch_kvFunction · 0.85
argMethod · 0.80
errFunction · 0.50
decode_payload_to_jsonFunction · 0.50
cloneMethod · 0.45
to_vecMethod · 0.45
getMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected