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

Function cliFormatReplyCSV

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

Source from the content-addressed store, hash-verified

1207}
1208
1209static sds cliFormatReplyCSV(redisReply *r) {
1210 unsigned int i;
1211
1212 sds out = sdsempty();
1213 switch (r->type) {
1214 case REDIS_REPLY_ERROR:
1215 out = sdscat(out,"ERROR,");
1216 out = sdscatrepr(out,r->str,strlen(r->str));
1217 break;
1218 case REDIS_REPLY_STATUS:
1219 out = sdscatrepr(out,r->str,r->len);
1220 break;
1221 case REDIS_REPLY_INTEGER:
1222 out = sdscatprintf(out,"%lld",r->integer);
1223 break;
1224 case REDIS_REPLY_DOUBLE:
1225 out = sdscatprintf(out,"%s",r->str);
1226 break;
1227 case REDIS_REPLY_STRING:
1228 case REDIS_REPLY_VERB:
1229 out = sdscatrepr(out,r->str,r->len);
1230 break;
1231 case REDIS_REPLY_NIL:
1232 out = sdscat(out,"NULL");
1233 break;
1234 case REDIS_REPLY_BOOL:
1235 out = sdscat(out,r->integer ? "true" : "false");
1236 break;
1237 case REDIS_REPLY_ARRAY:
1238 case REDIS_REPLY_SET:
1239 case REDIS_REPLY_PUSH:
1240 case REDIS_REPLY_MAP: /* CSV has no map type, just output flat list. */
1241 for (i = 0; i < r->elements; i++) {
1242 sds tmp = cliFormatReplyCSV(r->element[i]);
1243 out = sdscatlen(out,tmp,sdslen(tmp));
1244 if (i != r->elements-1) out = sdscat(out,",");
1245 sdsfree(tmp);
1246 }
1247 break;
1248 default:
1249 fprintf(stderr,"Unknown reply type: %d\n", r->type);
1250 exit(1);
1251 }
1252 return out;
1253}
1254
1255/* Generate reply strings in various output modes */
1256static sds cliFormatReply(redisReply *reply, int mode, int verbatim) {

Callers 1

cliFormatReplyFunction · 0.85

Calls 7

sdsemptyFunction · 0.85
sdscatFunction · 0.85
sdscatreprFunction · 0.85
sdscatprintfFunction · 0.85
sdscatlenFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85

Tested by

no test coverage detected