Implement the debugger "redis" command. We use a trick in order to make * the implementation very simple: we just call the Lua redis.call() command * implementation, with ldb.step enabled, so as a side effect the Redis command * and its reply are logged. */
| 2590 | * implementation, with ldb.step enabled, so as a side effect the Redis command |
| 2591 | * and its reply are logged. */ |
| 2592 | void ldbRedis(lua_State *lua, sds *argv, int argc) { |
| 2593 | int j, saved_rc = server.lua_replicate_commands; |
| 2594 | |
| 2595 | if (!lua_checkstack(lua, argc + 1)) { |
| 2596 | /* Increase the Lua stack if needed to make sure there is enough room |
| 2597 | * to push 'argc + 1' elements to the stack. On failure, return error. |
| 2598 | * Notice that we need, in worst case, 'argc + 1' elements because we push all the arguments |
| 2599 | * given by the user (without the first argument) and we also push the 'redis' global table and |
| 2600 | * 'redis.call' function so: |
| 2601 | * (1 (redis table)) + (1 (redis.call function)) + (argc - 1 (all arguments without the first)) = argc + 1*/ |
| 2602 | ldbLogRedisReply("max lua stack reached"); |
| 2603 | return; |
| 2604 | } |
| 2605 | |
| 2606 | lua_getglobal(lua,"redis"); |
| 2607 | lua_pushstring(lua,"call"); |
| 2608 | lua_gettable(lua,-2); /* Stack: redis, redis.call */ |
| 2609 | for (j = 1; j < argc; j++) |
| 2610 | lua_pushlstring(lua,argv[j],sdslen(argv[j])); |
| 2611 | ldb.step = 1; /* Force redis.call() to log. */ |
| 2612 | server.lua_replicate_commands = 1; |
| 2613 | lua_pcall(lua,argc-1,1,0); /* Stack: redis, result */ |
| 2614 | ldb.step = 0; /* Disable logging. */ |
| 2615 | server.lua_replicate_commands = saved_rc; |
| 2616 | lua_pop(lua,2); /* Discard the result and clean the stack. */ |
| 2617 | } |
| 2618 | |
| 2619 | /* Implements "trace" command of the Lua debugger. It just prints a backtrace |
| 2620 | * querying Lua starting from the current callframe back to the outer one. */ |
no test coverage detected