extension to Redis Function list all function names and their corresponding library names
| 510 | // extension to Redis Function |
| 511 | // list all function names and their corresponding library names |
| 512 | Status FunctionListFunc(Server *srv, const redis::Connection *conn, engine::Context &ctx, const std::string &funcname, |
| 513 | std::string *output) { |
| 514 | std::string start_key = engine::kLuaFuncLibPrefix + funcname; |
| 515 | std::string end_key = start_key; |
| 516 | end_key.back()++; |
| 517 | |
| 518 | rocksdb::ReadOptions read_options = ctx.DefaultScanOptions(); |
| 519 | rocksdb::Slice upper_bound(end_key); |
| 520 | read_options.iterate_upper_bound = &upper_bound; |
| 521 | |
| 522 | auto *cf = srv->storage->GetCFHandle(ColumnFamilyID::Propagate); |
| 523 | auto iter = util::UniqueIterator(ctx, read_options, cf); |
| 524 | std::vector<std::pair<std::string, std::string>> result; |
| 525 | for (iter->Seek(start_key); iter->Valid(); iter->Next()) { |
| 526 | Slice func = iter->key(); |
| 527 | func.remove_prefix(strlen(engine::kLuaLibCodePrefix)); |
| 528 | result.emplace_back(func.ToString(), iter->value().ToString()); |
| 529 | } |
| 530 | |
| 531 | if (auto s = iter->status(); !s.ok()) { |
| 532 | return {Status::NotOK, s.ToString()}; |
| 533 | } |
| 534 | |
| 535 | output->append(redis::MultiLen(result.size())); |
| 536 | for (const auto &[func, lib] : result) { |
| 537 | output->append(conn->HeaderOfMap(2)); |
| 538 | output->append(redis::BulkString("function_name")); |
| 539 | output->append(redis::BulkString(func)); |
| 540 | output->append(redis::BulkString("from_library")); |
| 541 | output->append(redis::BulkString(lib)); |
| 542 | } |
| 543 | |
| 544 | return Status::OK(); |
| 545 | } |
| 546 | |
| 547 | // extension to Redis Function |
| 548 | // list detailed informantion of a specific library |
no test coverage detected