| 1134 | } |
| 1135 | |
| 1136 | static sds cliFormatReplyRaw(redisReply *r) { |
| 1137 | sds out = sdsempty(), tmp; |
| 1138 | size_t i; |
| 1139 | |
| 1140 | switch (r->type) { |
| 1141 | case REDIS_REPLY_NIL: |
| 1142 | /* Nothing... */ |
| 1143 | break; |
| 1144 | case REDIS_REPLY_ERROR: |
| 1145 | out = sdscatlen(out,r->str,r->len); |
| 1146 | out = sdscatlen(out,"\n",1); |
| 1147 | break; |
| 1148 | case REDIS_REPLY_STATUS: |
| 1149 | case REDIS_REPLY_STRING: |
| 1150 | case REDIS_REPLY_VERB: |
| 1151 | if (r->type == REDIS_REPLY_STATUS && config.eval_ldb) { |
| 1152 | /* The Lua debugger replies with arrays of simple (status) |
| 1153 | * strings. We colorize the output for more fun if this |
| 1154 | * is a debugging session. */ |
| 1155 | |
| 1156 | /* Detect the end of a debugging session. */ |
| 1157 | if (strstr(r->str,"<endsession>") == r->str) { |
| 1158 | config.enable_ldb_on_eval = 0; |
| 1159 | config.eval_ldb = 0; |
| 1160 | config.eval_ldb_end = 1; /* Signal the caller session ended. */ |
| 1161 | config.output = OUTPUT_STANDARD; |
| 1162 | cliRefreshPrompt(); |
| 1163 | } else { |
| 1164 | out = sdsCatColorizedLdbReply(out,r->str,r->len); |
| 1165 | } |
| 1166 | } else { |
| 1167 | out = sdscatlen(out,r->str,r->len); |
| 1168 | } |
| 1169 | break; |
| 1170 | case REDIS_REPLY_BOOL: |
| 1171 | out = sdscat(out,r->integer ? "(true)" : "(false)"); |
| 1172 | break; |
| 1173 | case REDIS_REPLY_INTEGER: |
| 1174 | out = sdscatprintf(out,"%lld",r->integer); |
| 1175 | break; |
| 1176 | case REDIS_REPLY_DOUBLE: |
| 1177 | out = sdscatprintf(out,"%s",r->str); |
| 1178 | break; |
| 1179 | case REDIS_REPLY_SET: |
| 1180 | case REDIS_REPLY_ARRAY: |
| 1181 | case REDIS_REPLY_PUSH: |
| 1182 | for (i = 0; i < r->elements; i++) { |
| 1183 | if (i > 0) out = sdscat(out,config.mb_delim); |
| 1184 | tmp = cliFormatReplyRaw(r->element[i]); |
| 1185 | out = sdscatlen(out,tmp,sdslen(tmp)); |
| 1186 | sdsfree(tmp); |
| 1187 | } |
| 1188 | break; |
| 1189 | case REDIS_REPLY_MAP: |
| 1190 | for (i = 0; i < r->elements; i += 2) { |
| 1191 | if (i > 0) out = sdscat(out,config.mb_delim); |
| 1192 | tmp = cliFormatReplyRaw(r->element[i]); |
| 1193 | out = sdscatlen(out,tmp,sdslen(tmp)); |
no test coverage detected