| 183 | } |
| 184 | |
| 185 | pub(super) async fn handle_mget( |
| 186 | cmd: &RespCommand, |
| 187 | session: &RespSession, |
| 188 | state: &SharedState, |
| 189 | ) -> RespValue { |
| 190 | if cmd.argc() < 1 { |
| 191 | return RespValue::err("ERR wrong number of arguments for 'mget' command"); |
| 192 | } |
| 193 | |
| 194 | let plan = PhysicalPlan::Kv(KvOp::BatchGet { |
| 195 | collection: session.collection.clone(), |
| 196 | keys: cmd.args.clone(), |
| 197 | }); |
| 198 | |
| 199 | match dispatch_kv(state, session, plan).await { |
| 200 | Ok(resp) if resp.status == Status::Ok => { |
| 201 | let values: Vec<serde_json::Value> = |
| 202 | sonic_rs::from_slice(&resp.payload).unwrap_or_default(); |
| 203 | let items: Vec<RespValue> = values |
| 204 | .into_iter() |
| 205 | .map(|v| match v { |
| 206 | serde_json::Value::String(b64) => { |
| 207 | match base64::Engine::decode( |
| 208 | &base64::engine::general_purpose::STANDARD, |
| 209 | &b64, |
| 210 | ) { |
| 211 | Ok(data) => RespValue::bulk(data), |
| 212 | Err(_) => RespValue::nil(), |
| 213 | } |
| 214 | } |
| 215 | _ => RespValue::nil(), |
| 216 | }) |
| 217 | .collect(); |
| 218 | RespValue::array(items) |
| 219 | } |
| 220 | Ok(_) => RespValue::nil_array(), |
| 221 | Err(e) => RespValue::err(format!("ERR {e}")), |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | pub(super) async fn handle_mset( |
| 226 | cmd: &RespCommand, |