Use the new unified protocol to send SELECT to slaves.

SELECT was still transmitted to slaves using the inline protocol, that
is conceived mostly for humans to type into telnet sessions, and is
notably not understood by redis-cli --slave.

Now the new protocol is used instead.
This commit is contained in:
antirez 2012-11-03 12:15:29 +01:00
parent 4b83ad4e1f
commit e34a35a511
2 changed files with 14 additions and 2 deletions

View File

@ -1091,8 +1091,14 @@ void createSharedObjects(void) {
shared.plus = createObject(REDIS_STRING,sdsnew("+")); shared.plus = createObject(REDIS_STRING,sdsnew("+"));
for (j = 0; j < REDIS_SHARED_SELECT_CMDS; j++) { for (j = 0; j < REDIS_SHARED_SELECT_CMDS; j++) {
char dictid_str[64];
int dictid_len;
dictid_len = ll2string(dictid_str,sizeof(dictid_str),j);
shared.select[j] = createObject(REDIS_STRING, shared.select[j] = createObject(REDIS_STRING,
sdscatprintf(sdsempty(),"select %d\r\n", j)); sdscatprintf(sdsempty(),
"*2\r\n$6\r\nSELECT\r\n$%d\r\n%s\r\n",
dictid_len, dictid_str));
} }
shared.messagebulk = createStringObject("$7\r\nmessage\r\n",13); shared.messagebulk = createStringObject("$7\r\nmessage\r\n",13);
shared.pmessagebulk = createStringObject("$8\r\npmessage\r\n",14); shared.pmessagebulk = createStringObject("$8\r\npmessage\r\n",14);

View File

@ -61,8 +61,14 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
selectcmd = shared.select[dictid]; selectcmd = shared.select[dictid];
incrRefCount(selectcmd); incrRefCount(selectcmd);
} else { } else {
char dictid_str[64];
int dictid_len;
dictid_len = ll2string(dictid_str,sizeof(dictid_str),dictid);
selectcmd = createObject(REDIS_STRING, selectcmd = createObject(REDIS_STRING,
sdscatprintf(sdsempty(),"select %d\r\n",dictid)); sdscatprintf(sdsempty(),
"*2\r\n$6\r\nSELECT\r\n$%d\r\n%s\r\n",
dictid_len, dictid_str));
} }
addReply(slave,selectcmd); addReply(slave,selectcmd);
decrRefCount(selectcmd); decrRefCount(selectcmd);