| 2311 | *--------------------------------------------------------------------------- */ |
| 2312 | |
| 2313 | static 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 |
no test coverage detected