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. */
| 2613 | * implementation, with ldb.step enabled, so as a side effect the Redis command |
| 2614 | * and its reply are logged. */ |
| 2615 | void ldbRedis(lua_State *lua, sds *argv, int argc) { |
| 2616 | int j, saved_rc = g_pserver->lua_replicate_commands; |
| 2617 | |
| 2618 | if (!lua_checkstack(lua, argc + 1)) { |
| 2619 | /* Increase the Lua stack if needed to make sure there is enough room |
| 2620 | * to push 'argc + 1' elements to the stack. On failure, return error. |
| 2621 | * Notice that we need, in worst case, 'argc + 1' elements because we push all the arguments |
| 2622 | * given by the user (without the first argument) and we also push the 'redis' global table and |
| 2623 | * 'redis.call' function so: |
| 2624 | * (1 (redis table)) + (1 (redis.call function)) + (argc - 1 (all arguments without the first)) = argc + 1*/ |
| 2625 | sds reply = sdsnew("max lua stack reached"); |
| 2626 | ldbLogRedisReply(reply); |
| 2627 | sdsfree(reply); |
| 2628 | return; |
| 2629 | } |
| 2630 | |
| 2631 | lua_getglobal(lua,"redis"); |
| 2632 | lua_pushstring(lua,"call"); |
| 2633 | lua_gettable(lua,-2); /* Stack: redis, redis.call */ |
| 2634 | for (j = 1; j < argc; j++) |
| 2635 | lua_pushlstring(lua,argv[j],sdslen(argv[j])); |
| 2636 | ldb.step = 1; /* Force redis.call() to log. */ |
| 2637 | g_pserver->lua_replicate_commands = 1; |
| 2638 | lua_pcall(lua,argc-1,1,0); /* Stack: redis, result */ |
| 2639 | ldb.step = 0; /* Disable logging. */ |
| 2640 | g_pserver->lua_replicate_commands = saved_rc; |
| 2641 | lua_pop(lua,2); /* Discard the result and clean the stack. */ |
| 2642 | } |
| 2643 | |
| 2644 | /* Implements "trace" command of the Lua debugger. It just prints a backtrace |
| 2645 | * querying Lua starting from the current callframe back to the outer one. */ |
no test coverage detected