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

Function cliFormatReplyCSV

src/redis-cli.c:1016–1060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1014}
1015
1016static sds cliFormatReplyCSV(redisReply *r) {
1017 unsigned int i;
1018
1019 sds out = sdsempty();
1020 switch (r->type) {
1021 case REDIS_REPLY_ERROR:
1022 out = sdscat(out,"ERROR,");
1023 out = sdscatrepr(out,r->str,strlen(r->str));
1024 break;
1025 case REDIS_REPLY_STATUS:
1026 out = sdscatrepr(out,r->str,r->len);
1027 break;
1028 case REDIS_REPLY_INTEGER:
1029 out = sdscatprintf(out,"%lld",r->integer);
1030 break;
1031 case REDIS_REPLY_DOUBLE:
1032 out = sdscatprintf(out,"%s",r->str);
1033 break;
1034 case REDIS_REPLY_STRING:
1035 case REDIS_REPLY_VERB:
1036 out = sdscatrepr(out,r->str,r->len);
1037 break;
1038 case REDIS_REPLY_NIL:
1039 out = sdscat(out,"NULL");
1040 break;
1041 case REDIS_REPLY_BOOL:
1042 out = sdscat(out,r->integer ? "true" : "false");
1043 break;
1044 case REDIS_REPLY_ARRAY:
1045 case REDIS_REPLY_SET:
1046 case REDIS_REPLY_PUSH:
1047 case REDIS_REPLY_MAP: /* CSV has no map type, just output flat list. */
1048 for (i = 0; i < r->elements; i++) {
1049 sds tmp = cliFormatReplyCSV(r->element[i]);
1050 out = sdscatlen(out,tmp,sdslen(tmp));
1051 if (i != r->elements-1) out = sdscat(out,",");
1052 sdsfree(tmp);
1053 }
1054 break;
1055 default:
1056 fprintf(stderr,"Unknown reply type: %d\n", r->type);
1057 exit(1);
1058 }
1059 return out;
1060}
1061
1062/* Generate reply strings in various output modes */
1063static 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