MCPcopy Create free account
hub / github.com/apache/kvrocks / FunctionListLib

Function FunctionListLib

src/storage/scripting.cc:551–586  ·  view source on GitHub ↗

extension to Redis Function list detailed informantion of a specific library NOTE: it is required to load the library to lua runtime before listing (calling this function) i.e. it will output nothing if the library is only in storage but not loaded

Source from the content-addressed store, hash-verified

549// NOTE: it is required to load the library to lua runtime before listing (calling this function)
550// i.e. it will output nothing if the library is only in storage but not loaded
551Status FunctionListLib(redis::Connection *conn, const std::string &libname, std::string *output) {
552 auto lua = conn->Owner()->Lua();
553
554 lua_getglobal(lua, REDIS_FUNCTION_LIBRARIES);
555 if (lua_isnil(lua, -1)) {
556 lua_pop(lua, 1);
557 lua_newtable(lua);
558 }
559
560 lua_getfield(lua, -1, libname.c_str());
561 if (lua_isnil(lua, -1)) {
562 lua_pop(lua, 2);
563
564 return {Status::NotOK, "The library is not found or not loaded from storage"};
565 }
566
567 output->append(conn->HeaderOfMap(3));
568 output->append(redis::BulkString("library_name"));
569 output->append(redis::BulkString(libname));
570 output->append(redis::BulkString("engine"));
571 output->append(redis::BulkString("lua"));
572
573 auto count = lua_objlen(lua, -1);
574 output->append(redis::SimpleString("functions"));
575 output->append(redis::MultiLen(count));
576
577 for (size_t i = 1; i <= count; ++i) {
578 lua_rawgeti(lua, -1, static_cast<int>(i));
579 auto func = lua_tostring(lua, -1);
580 output->append(redis::BulkString(func));
581 lua_pop(lua, 1);
582 }
583
584 lua_pop(lua, 2);
585 return Status::OK();
586}
587
588Status FunctionDelete(engine::Context &ctx, redis::Connection *conn, const std::string &name) {
589 auto lua = conn->Owner()->Lua();

Callers 1

ExecuteMethod · 0.85

Calls 6

BulkStringFunction · 0.85
SimpleStringFunction · 0.85
MultiLenFunction · 0.85
LuaMethod · 0.80
OwnerMethod · 0.80
HeaderOfMapMethod · 0.80

Tested by

no test coverage detected