MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / evalMode

Function evalMode

src/redis-cli.c:2125–2206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2123 *--------------------------------------------------------------------------- */
2124
2125static int evalMode(int argc, char **argv) {
2126 sds script = NULL;
2127 FILE *fp;
2128 char buf[1024];
2129 size_t nread;
2130 char **argv2;
2131 int j, got_comma, keys;
2132 int retval = REDIS_OK;
2133
2134 while(1) {
2135 if (config.eval_ldb) {
2136 printf(
2137 "Lua debugging session started, please use:\n"
2138 "quit -- End the session.\n"
2139 "restart -- Restart the script in debug mode again.\n"
2140 "help -- Show Lua script debugging commands.\n\n"
2141 );
2142 }
2143
2144 sdsfree(script);
2145 script = sdsempty();
2146 got_comma = 0;
2147 keys = 0;
2148
2149 /* Load the script from the file, as an sds string. */
2150 fp = fopen(config.eval,"r");
2151 if (!fp) {
2152 fprintf(stderr,
2153 "Can't open file '%s': %s\n", config.eval, strerror(errno));
2154 exit(1);
2155 }
2156 while((nread = fread(buf,1,sizeof(buf),fp)) != 0) {
2157 script = sdscatlen(script,buf,nread);
2158 }
2159 fclose(fp);
2160
2161 /* If we are debugging a script, enable the Lua debugger. */
2162 if (config.eval_ldb) {
2163 redisReply *reply = redisCommand(context,
2164 config.eval_ldb_sync ?
2165 "SCRIPT DEBUG sync": "SCRIPT DEBUG yes");
2166 if (reply) freeReplyObject(reply);
2167 }
2168
2169 /* Create our argument vector */
2170 argv2 = zmalloc(sizeof(sds)*(argc+3), MALLOC_LOCAL);
2171 argv2[0] = sdsnew("EVAL");
2172 argv2[1] = script;
2173 for (j = 0; j < argc; j++) {
2174 if (!got_comma && argv[j][0] == ',' && argv[j][1] == 0) {
2175 got_comma = 1;
2176 continue;
2177 }
2178 argv2[j+3-got_comma] = sdsnew(argv[j]);
2179 if (!got_comma) keys++;
2180 }
2181 argv2[2] = sdscatprintf(sdsempty(),"%d",keys);
2182

Callers 1

mainFunction · 0.85

Calls 12

sdsfreeFunction · 0.85
sdsemptyFunction · 0.85
sdscatlenFunction · 0.85
freeReplyObjectFunction · 0.85
zmallocFunction · 0.85
sdsnewFunction · 0.85
sdscatprintfFunction · 0.85
issueCommandFunction · 0.85
cliReadReplyFunction · 0.85
replFunction · 0.85
cliConnectFunction · 0.85
redisCommandClass · 0.70

Tested by

no test coverage detected