"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/redis-cli.c" between
redis-6.2.4.tar.gz and redis-6.2.5.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

redis-cli.c  (redis-6.2.4):redis-cli.c  (redis-6.2.5)
skipping to change at line 1130 skipping to change at line 1130
break; break;
case REDIS_REPLY_BOOL: case REDIS_REPLY_BOOL:
out = sdscat(out,r->integer ? "(true)" : "(false)"); out = sdscat(out,r->integer ? "(true)" : "(false)");
break; break;
case REDIS_REPLY_INTEGER: case REDIS_REPLY_INTEGER:
out = sdscatprintf(out,"%lld",r->integer); out = sdscatprintf(out,"%lld",r->integer);
break; break;
case REDIS_REPLY_DOUBLE: case REDIS_REPLY_DOUBLE:
out = sdscatprintf(out,"%s",r->str); out = sdscatprintf(out,"%s",r->str);
break; break;
case REDIS_REPLY_SET:
case REDIS_REPLY_ARRAY: case REDIS_REPLY_ARRAY:
case REDIS_REPLY_PUSH: case REDIS_REPLY_PUSH:
for (i = 0; i < r->elements; i++) { for (i = 0; i < r->elements; i++) {
if (i > 0) out = sdscat(out,config.mb_delim); if (i > 0) out = sdscat(out,config.mb_delim);
tmp = cliFormatReplyRaw(r->element[i]); tmp = cliFormatReplyRaw(r->element[i]);
out = sdscatlen(out,tmp,sdslen(tmp)); out = sdscatlen(out,tmp,sdslen(tmp));
sdsfree(tmp); sdsfree(tmp);
} }
break; break;
case REDIS_REPLY_MAP: case REDIS_REPLY_MAP:
skipping to change at line 1188 skipping to change at line 1189
case REDIS_REPLY_VERB: case REDIS_REPLY_VERB:
out = sdscatrepr(out,r->str,r->len); out = sdscatrepr(out,r->str,r->len);
break; break;
case REDIS_REPLY_NIL: case REDIS_REPLY_NIL:
out = sdscat(out,"NULL"); out = sdscat(out,"NULL");
break; break;
case REDIS_REPLY_BOOL: case REDIS_REPLY_BOOL:
out = sdscat(out,r->integer ? "true" : "false"); out = sdscat(out,r->integer ? "true" : "false");
break; break;
case REDIS_REPLY_ARRAY: case REDIS_REPLY_ARRAY:
case REDIS_REPLY_SET:
case REDIS_REPLY_PUSH: case REDIS_REPLY_PUSH:
case REDIS_REPLY_MAP: /* CSV has no map type, just output flat list. */ case REDIS_REPLY_MAP: /* CSV has no map type, just output flat list. */
for (i = 0; i < r->elements; i++) { for (i = 0; i < r->elements; i++) {
sds tmp = cliFormatReplyCSV(r->element[i]); sds tmp = cliFormatReplyCSV(r->element[i]);
out = sdscatlen(out,tmp,sdslen(tmp)); out = sdscatlen(out,tmp,sdslen(tmp));
if (i != r->elements-1) out = sdscat(out,","); if (i != r->elements-1) out = sdscat(out,",");
sdsfree(tmp); sdsfree(tmp);
} }
break; break;
default: default:
skipping to change at line 1311 skipping to change at line 1313
reply->type == REDIS_REPLY_ERROR) reply->type == REDIS_REPLY_ERROR)
{ {
fprintf(stderr,"%s\n",reply->str); fprintf(stderr,"%s\n",reply->str);
exit(1); exit(1);
return REDIS_ERR; /* avoid compiler warning */ return REDIS_ERR; /* avoid compiler warning */
} }
if (output) { if (output) {
out = cliFormatReply(reply, config.output, output_raw_strings); out = cliFormatReply(reply, config.output, output_raw_strings);
fwrite(out,sdslen(out),1,stdout); fwrite(out,sdslen(out),1,stdout);
fflush(stdout);
sdsfree(out); sdsfree(out);
} }
freeReplyObject(reply); freeReplyObject(reply);
return REDIS_OK; return REDIS_OK;
} }
static int cliSendCommand(int argc, char **argv, long repeat) { static int cliSendCommand(int argc, char **argv, long repeat) {
char *command = argv[0]; char *command = argv[0];
size_t *argvlen; size_t *argvlen;
int j, output_raw; int j, output_raw;
skipping to change at line 1895 skipping to change at line 1898
" and exits.\n",version); " and exits.\n",version);
fprintf(stderr, fprintf(stderr,
" --latency-history Like --latency but tracking latency changes over time.\n" " --latency-history Like --latency but tracking latency changes over time.\n"
" Default time interval is 15 sec. Change it using -i.\n" " Default time interval is 15 sec. Change it using -i.\n"
" --latency-dist Shows latency as a spectrum, requires xterm 256 colors.\n" " --latency-dist Shows latency as a spectrum, requires xterm 256 colors.\n"
" Default time interval is 1 sec. Change it using -i.\n" " Default time interval is 1 sec. Change it using -i.\n"
" --lru-test <keys> Simulate a cache workload with an 80-20 distribution.\n" " --lru-test <keys> Simulate a cache workload with an 80-20 distribution.\n"
" --replica Simulate a replica showing commands received from the mast er.\n" " --replica Simulate a replica showing commands received from the mast er.\n"
" --rdb <filename> Transfer an RDB dump from remote server to local file.\n" " --rdb <filename> Transfer an RDB dump from remote server to local file.\n"
" Use filename of \"-\" to write to stdout.\n"
" --pipe Transfer raw Redis protocol from stdin to server.\n" " --pipe Transfer raw Redis protocol from stdin to server.\n"
" --pipe-timeout <n> In --pipe mode, abort with error if after sending all data .\n" " --pipe-timeout <n> In --pipe mode, abort with error if after sending all data .\n"
" no reply is received within <n> seconds.\n" " no reply is received within <n> seconds.\n"
" Default timeout: %d. Use 0 to wait forever.\n", " Default timeout: %d. Use 0 to wait forever.\n",
REDIS_CLI_DEFAULT_PIPE_TIMEOUT); REDIS_CLI_DEFAULT_PIPE_TIMEOUT);
fprintf(stderr, fprintf(stderr,
" --bigkeys Sample Redis keys looking for keys with many elements (com plexity).\n" " --bigkeys Sample Redis keys looking for keys with many elements (com plexity).\n"
" --memkeys Sample Redis keys looking for keys consuming a lot of memo ry.\n" " --memkeys Sample Redis keys looking for keys consuming a lot of memo ry.\n"
" --memkeys-samples <n> Sample Redis keys looking for keys consuming a lot of m emory.\n" " --memkeys-samples <n> Sample Redis keys looking for keys consuming a lot of m emory.\n"
" And define number of key elements to sample\n" " And define number of key elements to sample\n"
skipping to change at line 6535 skipping to change at line 6539
cmdfmt = sdsnew("MIGRATE %s %d %s %d %d"); cmdfmt = sdsnew("MIGRATE %s %d %s %d %d");
if (config.auth) { if (config.auth) {
if (config.user) { if (config.user) {
cmdfmt = sdscatfmt(cmdfmt," AUTH2 %s %s", config.user, config.auth); cmdfmt = sdscatfmt(cmdfmt," AUTH2 %s %s", config.user, config.auth);
} else { } else {
cmdfmt = sdscatfmt(cmdfmt," AUTH %s", config.auth); cmdfmt = sdscatfmt(cmdfmt," AUTH %s", config.auth);
} }
} }
if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_COPY) if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_COPY)
strcat(cmdfmt, " %s"); cmdfmt = sdscat(cmdfmt," COPY");
if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_REPLACE) if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_REPLACE)
strcat(cmdfmt, " %s"); cmdfmt = sdscat(cmdfmt," REPLACE");
/* Use SCAN to iterate over the keys, migrating to the /* Use SCAN to iterate over the keys, migrating to the
* right node as needed. */ * right node as needed. */
int cursor = -999, timeout = config.cluster_manager_command.timeout; int cursor = -999, timeout = config.cluster_manager_command.timeout;
while (cursor != 0) { while (cursor != 0) {
if (cursor < 0) cursor = 0; if (cursor < 0) cursor = 0;
freeReplyObject(src_reply); freeReplyObject(src_reply);
src_reply = reconnectingRedisCommand(src_ctx, "SCAN %d COUNT %d", src_reply = reconnectingRedisCommand(src_ctx, "SCAN %d COUNT %d",
cursor, 1000); cursor, 1000);
if (!src_reply || src_reply->type == REDIS_REPLY_ERROR) { if (!src_reply || src_reply->type == REDIS_REPLY_ERROR) {
skipping to change at line 6569 skipping to change at line 6573
int keycount = src_reply->element[1]->elements; int keycount = src_reply->element[1]->elements;
for (i = 0; i < keycount; i++) { for (i = 0; i < keycount; i++) {
redisReply *kr = src_reply->element[1]->element[i]; redisReply *kr = src_reply->element[1]->element[i];
assert(kr->type == REDIS_REPLY_STRING); assert(kr->type == REDIS_REPLY_STRING);
char *key = kr->str; char *key = kr->str;
uint16_t slot = clusterManagerKeyHashSlot(key, kr->len); uint16_t slot = clusterManagerKeyHashSlot(key, kr->len);
clusterManagerNode *target = slots_map[slot]; clusterManagerNode *target = slots_map[slot];
printf("Migrating %s to %s:%d: ", key, target->ip, target->port); printf("Migrating %s to %s:%d: ", key, target->ip, target->port);
redisReply *r = reconnectingRedisCommand(src_ctx, cmdfmt, redisReply *r = reconnectingRedisCommand(src_ctx, cmdfmt,
target->ip, target->port, target->ip, target->port,
key, 0, timeout, key, 0, timeout);
"COPY", "REPLACE");
if (!r || r->type == REDIS_REPLY_ERROR) { if (!r || r->type == REDIS_REPLY_ERROR) {
if (r && r->str) { if (r && r->str) {
clusterManagerLogErr("Source %s:%d replied with " clusterManagerLogErr("Source %s:%d replied with "
"error:\n%s\n", src_ip, src_port, "error:\n%s\n", src_ip, src_port,
r->str); r->str);
} }
success = 0; success = 0;
} }
freeReplyObject(r); freeReplyObject(r);
if (!success) goto cleanup; if (!success) goto cleanup;
skipping to change at line 6986 skipping to change at line 6989
} }
} }
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Slave mode * Slave mode
*--------------------------------------------------------------------------- */ *--------------------------------------------------------------------------- */
#define RDB_EOF_MARK_SIZE 40 #define RDB_EOF_MARK_SIZE 40
void sendReplconf(const char* arg1, const char* arg2) { void sendReplconf(const char* arg1, const char* arg2) {
printf("sending REPLCONF %s %s\n", arg1, arg2); fprintf(stderr, "sending REPLCONF %s %s\n", arg1, arg2);
redisReply *reply = redisCommand(context, "REPLCONF %s %s", arg1, arg2); redisReply *reply = redisCommand(context, "REPLCONF %s %s", arg1, arg2);
/* Handle any error conditions */ /* Handle any error conditions */
if(reply == NULL) { if(reply == NULL) {
fprintf(stderr, "\nI/O error\n"); fprintf(stderr, "\nI/O error\n");
exit(1); exit(1);
} else if(reply->type == REDIS_REPLY_ERROR) { } else if(reply->type == REDIS_REPLY_ERROR) {
fprintf(stderr, "REPLCONF %s error: %s\n", arg1, reply->str); fprintf(stderr, "REPLCONF %s error: %s\n", arg1, reply->str);
/* non fatal, old versions may not support it */ /* non fatal, old versions may not support it */
} }
skipping to change at line 7046 skipping to change at line 7049
nread = readConn(c,p,1); nread = readConn(c,p,1);
if (nread <= 0) { if (nread <= 0) {
fprintf(stderr,"Error reading bulk length while SYNCing\n"); fprintf(stderr,"Error reading bulk length while SYNCing\n");
exit(1); exit(1);
} }
if (*p == '\n' && p != buf) break; if (*p == '\n' && p != buf) break;
if (*p != '\n') p++; if (*p != '\n') p++;
} }
*p = '\0'; *p = '\0';
if (buf[0] == '-') { if (buf[0] == '-') {
printf("SYNC with master failed: %s\n", buf); fprintf(stderr, "SYNC with master failed: %s\n", buf);
exit(1); exit(1);
} }
if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= RDB_EOF_MARK_SIZE) { if (strncmp(buf+1,"EOF:",4) == 0 && strlen(buf+5) >= RDB_EOF_MARK_SIZE) {
memcpy(out_eof, buf+5, RDB_EOF_MARK_SIZE); memcpy(out_eof, buf+5, RDB_EOF_MARK_SIZE);
return 0; return 0;
} }
return strtoull(buf+1,NULL,10); return strtoull(buf+1,NULL,10);
} }
static void slaveMode(void) { static void slaveMode(void) {
skipping to change at line 7150 skipping to change at line 7153
payload = ULLONG_MAX; payload = ULLONG_MAX;
memset(lastbytes,0,RDB_EOF_MARK_SIZE); memset(lastbytes,0,RDB_EOF_MARK_SIZE);
usemark = 1; usemark = 1;
fprintf(stderr,"SYNC sent to master, writing bytes of bulk transfer " fprintf(stderr,"SYNC sent to master, writing bytes of bulk transfer "
"until EOF marker to '%s'\n", filename); "until EOF marker to '%s'\n", filename);
} else { } else {
fprintf(stderr,"SYNC sent to master, writing %llu bytes to '%s'\n", fprintf(stderr,"SYNC sent to master, writing %llu bytes to '%s'\n",
payload, filename); payload, filename);
} }
int write_to_stdout = !strcmp(filename,"-");
/* Write to file. */ /* Write to file. */
if (!strcmp(filename,"-")) { if (write_to_stdout) {
fd = STDOUT_FILENO; fd = STDOUT_FILENO;
} else { } else {
fd = open(filename, O_CREAT|O_WRONLY, 0644); fd = open(filename, O_CREAT|O_WRONLY, 0644);
if (fd == -1) { if (fd == -1) {
fprintf(stderr, "Error opening '%s': %s\n", filename, fprintf(stderr, "Error opening '%s': %s\n", filename,
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
} }
skipping to change at line 7193 skipping to change at line 7197
int rem = RDB_EOF_MARK_SIZE-nread; int rem = RDB_EOF_MARK_SIZE-nread;
memmove(lastbytes,lastbytes+nread,rem); memmove(lastbytes,lastbytes+nread,rem);
memcpy(lastbytes+rem,buf,nread); memcpy(lastbytes+rem,buf,nread);
} }
if (memcmp(lastbytes,eofmark,RDB_EOF_MARK_SIZE) == 0) if (memcmp(lastbytes,eofmark,RDB_EOF_MARK_SIZE) == 0)
break; break;
} }
} }
if (usemark) { if (usemark) {
payload = ULLONG_MAX - payload - RDB_EOF_MARK_SIZE; payload = ULLONG_MAX - payload - RDB_EOF_MARK_SIZE;
if (ftruncate(fd, payload) == -1) if (!write_to_stdout && ftruncate(fd, payload) == -1)
fprintf(stderr,"ftruncate failed: %s.\n", strerror(errno)); fprintf(stderr,"ftruncate failed: %s.\n", strerror(errno));
fprintf(stderr,"Transfer finished with success after %llu bytes\n", payl oad); fprintf(stderr,"Transfer finished with success after %llu bytes\n", payl oad);
} else { } else {
fprintf(stderr,"Transfer finished with success.\n"); fprintf(stderr,"Transfer finished with success.\n");
} }
redisFree(s); /* Close the connection ASAP as fsync() may take time. */ redisFree(s); /* Close the connection ASAP as fsync() may take time. */
if (node) if (node)
node->context = NULL; node->context = NULL;
if (fsync(fd) == -1) { if (!write_to_stdout && fsync(fd) == -1) {
fprintf(stderr,"Fail to fsync '%s': %s\n", filename, strerror(errno)); fprintf(stderr,"Fail to fsync '%s': %s\n", filename, strerror(errno));
exit(1); exit(1);
} }
close(fd); close(fd);
if (node) { if (node) {
sdsfree(filename); sdsfree(filename);
return; return;
} }
exit(0); exit(0);
} }
 End of changes. 13 change blocks. 
9 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)