Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
phpredis
phpredis
Commits
ba73fbee
Commit
ba73fbee
authored
Jan 16, 2020
by
Michael Grunder
Committed by
Michael Grunder
Jan 31, 2020
Browse files
Initial commit of ASK redirection fix
See #1693
parent
9410a7db
Changes
2
Hide whitespace changes
Inline
Side-by-side
cluster_library.c
View file @
ba73fbee
...
...
@@ -1206,8 +1206,7 @@ static int cluster_set_redirection(redisCluster* c, char *msg, int moved)
*
* This function will return -1 on a critical error (e.g. parse/communication
* error, 0 if no redirection was encountered, and 1 if the data was moved. */
static
int
cluster_check_response
(
redisCluster
*
c
,
REDIS_REPLY_TYPE
*
reply_type
)
static
int
cluster_check_response
(
redisCluster
*
c
,
REDIS_REPLY_TYPE
*
reply_type
)
{
size_t
sz
;
...
...
@@ -1232,15 +1231,17 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type
}
// Check for MOVED or ASK redirection
if
((
moved
=
IS_MOVED
(
inbuf
))
||
IS_ASK
(
inbuf
))
{
// Set our redirection information
/* We'll want to invalidate slot cache if we're using one */
c
->
redirections
++
;
if
((
moved
=
IS_MOVED
(
inbuf
))
||
IS_ASK
(
inbuf
))
{
/* The Redis Cluster specification suggests clients do not update
* their slot mapping for an ASK redirection, only for MOVED */
if
(
moved
)
c
->
redirections
++
;
/* Make sure we can parse the redirection host and port */
if
(
cluster_set_redirection
(
c
,
inbuf
,
moved
)
<
0
)
{
return
-
1
;
}
/
/ Data moved
/
* We've been redirected */
return
1
;
}
else
{
// Capture the error string Redis returned
...
...
@@ -1380,8 +1381,7 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz,
/* If in ASK redirection, get/create the node for that host:port, otherwise
* just use the command socket. */
if
(
c
->
redir_type
==
REDIR_ASK
)
{
redis_sock
=
cluster_get_asking_sock
(
c
);
if
(
cluster_send_asking
(
redis_sock
)
<
0
)
{
if
(
cluster_send_asking
(
c
->
cmd_sock
)
<
0
)
{
return
-
1
;
}
}
...
...
@@ -1627,10 +1627,13 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
return
-
1
;
}
/* Update mapping if the data has MOVED */
if
(
c
->
redir_type
==
REDIR_MOVED
)
{
/* For MOVED redirection we want to update our cached mapping */
cluster_update_slot
(
c
);
c
->
cmd_sock
=
SLOT_SOCK
(
c
,
slot
);
}
else
if
(
c
->
redir_type
==
REDIR_ASK
)
{
/* For ASK redirection we want to redirect but not update slot mapping */
c
->
cmd_sock
=
cluster_get_asking_sock
(
c
);
}
}
...
...
cluster_library.h
View file @
ba73fbee
...
...
@@ -26,7 +26,7 @@
/* MOVED/ASK comparison macros */
#define IS_MOVED(p) (p[0]=='M' && p[1]=='O' && p[2]=='V' && p[3]=='E' && \
p[4]=='D' && p[5]==' ')
#define IS_ASK(p) (p[0]=='A' && p[1]=='S' && p[
3
]=='K' && p[
4
]==' ')
#define IS_ASK(p) (p[0]=='A' && p[1]=='S' && p[
2
]=='K' && p[
3
]==' ')
/* MOVED/ASK lengths */
#define MOVED_LEN (sizeof("MOVED ")-1)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment