MCPcopy Create free account
hub / github.com/F-Stack/f-stack / evalMode

Function evalMode

app/redis-6.2.6/src/redis-cli.c:2313–2394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2311 *--------------------------------------------------------------------------- */
2312
2313static int evalMode(int argc, char **argv) {
2314 sds script = NULL;
2315 FILE *fp;
2316 char buf[1024];
2317 size_t nread;
2318 char **argv2;
2319 int j, got_comma, keys;
2320 int retval = REDIS_OK;
2321
2322 while(1) {
2323 if (config.eval_ldb) {
2324 printf(
2325 "Lua debugging session started, please use:\n"
2326 "quit -- End the session.\n"
2327 "restart -- Restart the script in debug mode again.\n"
2328 "help -- Show Lua script debugging commands.\n\n"
2329 );
2330 }
2331
2332 sdsfree(script);
2333 script = sdsempty();
2334 got_comma = 0;
2335 keys = 0;
2336
2337 /* Load the script from the file, as an sds string. */
2338 fp = fopen(config.eval,"r");
2339 if (!fp) {
2340 fprintf(stderr,
2341 "Can't open file '%s': %s\n", config.eval, strerror(errno));
2342 exit(1);
2343 }
2344 while((nread = fread(buf,1,sizeof(buf),fp)) != 0) {
2345 script = sdscatlen(script,buf,nread);
2346 }
2347 fclose(fp);
2348
2349 /* If we are debugging a script, enable the Lua debugger. */
2350 if (config.eval_ldb) {
2351 redisReply *reply = redisCommand(context,
2352 config.eval_ldb_sync ?
2353 "SCRIPT DEBUG sync": "SCRIPT DEBUG yes");
2354 if (reply) freeReplyObject(reply);
2355 }
2356
2357 /* Create our argument vector */
2358 argv2 = zmalloc(sizeof(sds)*(argc+3));
2359 argv2[0] = sdsnew("EVAL");
2360 argv2[1] = script;
2361 for (j = 0; j < argc; j++) {
2362 if (!got_comma && argv[j][0] == ',' && argv[j][1] == 0) {
2363 got_comma = 1;
2364 continue;
2365 }
2366 argv2[j+3-got_comma] = sdsnew(argv[j]);
2367 if (!got_comma) keys++;
2368 }
2369 argv2[2] = sdscatprintf(sdsempty(),"%d",keys);
2370

Callers 1

mainFunction · 0.85

Calls 14

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
strncpyFunction · 0.85
replFunction · 0.85
cliConnectFunction · 0.85

Tested by

no test coverage detected