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

Function handle_incrbyfloat

nodedb/src/control/server/resp/handler_kv.rs:347–386  ·  view source on GitHub ↗

INCRBYFLOAT key delta

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

Source from the content-addressed store, hash-verified

345
346/// INCRBYFLOAT key delta
347pub(super) async fn handle_incrbyfloat(
348 cmd: &RespCommand,
349 session: &RespSession,
350 state: &SharedState,
351) -> RespValue {
352 if cmd.argc() < 2 {
353 return RespValue::err("ERR wrong number of arguments for 'incrbyfloat' command");
354 }
355
356 let key = cmd.args[0].clone();
357 let delta_str = match cmd.arg_str(1) {
358 Some(s) => s,
359 None => return RespValue::err("ERR value is not a valid float"),
360 };
361 let delta: f64 = match delta_str.parse() {
362 Ok(v) => v,
363 Err(_) => return RespValue::err("ERR value is not a valid float"),
364 };
365
366 let plan = PhysicalPlan::Kv(KvOp::IncrFloat {
367 collection: session.collection.clone(),
368 key,
369 delta,
370 });
371
372 match dispatch_kv_write(state, session, plan).await {
373 Ok(resp) => {
374 // Return the new value as a bulk string (Redis convention).
375 let payload_text =
376 crate::data::executor::response_codec::decode_payload_to_json(&resp.payload);
377 if let Ok(json) = sonic_rs::from_str::<serde_json::Value>(&payload_text)
378 && let Some(v) = json.get("value")
379 {
380 return RespValue::bulk(v.to_string().into_bytes());
381 }
382 RespValue::bulk(payload_text.into_bytes())
383 }
384 Err(e) => RespValue::err(format!("ERR {e}")),
385 }
386}
387
388/// GETSET key value — atomically set new value and return old.
389pub(super) async fn handle_getset(

Callers 1

executeFunction · 0.85

Calls 9

dispatch_kv_writeFunction · 0.85
argcMethod · 0.80
arg_strMethod · 0.80
to_stringMethod · 0.80
errFunction · 0.50
decode_payload_to_jsonFunction · 0.50
cloneMethod · 0.45
parseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected