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

Function handle_getset

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

GETSET key value — atomically set new value and return old.

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

Source from the content-addressed store, hash-verified

387
388/// GETSET key value — atomically set new value and return old.
389pub(super) async fn handle_getset(
390 cmd: &RespCommand,
391 session: &RespSession,
392 state: &SharedState,
393) -> RespValue {
394 if cmd.argc() < 2 {
395 return RespValue::err("ERR wrong number of arguments for 'getset' command");
396 }
397
398 let key = cmd.args[0].clone();
399 let new_value = cmd.args[1].clone();
400
401 let plan = PhysicalPlan::Kv(KvOp::GetSet {
402 collection: session.collection.clone(),
403 key,
404 new_value,
405 });
406
407 match dispatch_kv_write(state, session, plan).await {
408 Ok(resp) => {
409 let payload_text =
410 crate::data::executor::response_codec::decode_payload_to_json(&resp.payload);
411 if let Ok(json) = sonic_rs::from_str::<serde_json::Value>(&payload_text)
412 && let Some(serde_json::Value::String(b64)) = json.get("old_value")
413 && let Ok(data) =
414 base64::Engine::decode(&base64::engine::general_purpose::STANDARD, b64)
415 {
416 return RespValue::bulk(data);
417 }
418 RespValue::nil()
419 }
420 Err(e) => RespValue::err(format!("ERR {e}")),
421 }
422}

Callers 1

executeFunction · 0.85

Calls 7

dispatch_kv_writeFunction · 0.85
argcMethod · 0.80
errFunction · 0.50
decode_payload_to_jsonFunction · 0.50
decodeFunction · 0.50
cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected