Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
65afcf24
Commit
65afcf24
authored
Jun 27, 2018
by
antirez
Browse files
Take clients in a ID -> Client handle dictionary.
parent
5103bb00
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
65afcf24
...
@@ -75,6 +75,8 @@ void linkClient(client *c) {
...
@@ -75,6 +75,8 @@ void linkClient(client *c) {
* this way removing the client in unlinkClient() will not require
* this way removing the client in unlinkClient() will not require
* a linear scan, but just a constant time operation. */
* a linear scan, but just a constant time operation. */
c
->
client_list_node
=
listLast
(
server
.
clients
);
c
->
client_list_node
=
listLast
(
server
.
clients
);
uint64_t
id
=
htonu64
(
c
->
id
);
raxInsert
(
server
.
clients_index
,(
unsigned
char
*
)
&
id
,
sizeof
(
id
),
c
,
NULL
);
}
}
client
*
createClient
(
int
fd
)
{
client
*
createClient
(
int
fd
)
{
...
@@ -720,6 +722,8 @@ void unlinkClient(client *c) {
...
@@ -720,6 +722,8 @@ void unlinkClient(client *c) {
if
(
c
->
fd
!=
-
1
)
{
if
(
c
->
fd
!=
-
1
)
{
/* Remove from the list of active clients. */
/* Remove from the list of active clients. */
if
(
c
->
client_list_node
)
{
if
(
c
->
client_list_node
)
{
uint64_t
id
=
htonu64
(
c
->
id
);
raxRemove
(
server
.
clients_index
,(
unsigned
char
*
)
&
id
,
sizeof
(
id
),
NULL
);
listDelNode
(
server
.
clients
,
c
->
client_list_node
);
listDelNode
(
server
.
clients
,
c
->
client_list_node
);
c
->
client_list_node
=
NULL
;
c
->
client_list_node
=
NULL
;
}
}
...
...
src/server.c
View file @
65afcf24
...
@@ -1890,6 +1890,7 @@ void initServer(void) {
...
@@ -1890,6 +1890,7 @@ void initServer(void) {
server
.
pid
=
getpid
();
server
.
pid
=
getpid
();
server
.
current_client
=
NULL
;
server
.
current_client
=
NULL
;
server
.
clients
=
listCreate
();
server
.
clients
=
listCreate
();
server
.
clients_index
=
raxNew
();
server
.
clients_to_close
=
listCreate
();
server
.
clients_to_close
=
listCreate
();
server
.
slaves
=
listCreate
();
server
.
slaves
=
listCreate
();
server
.
monitors
=
listCreate
();
server
.
monitors
=
listCreate
();
...
...
src/server.h
View file @
65afcf24
...
@@ -952,6 +952,7 @@ struct redisServer {
...
@@ -952,6 +952,7 @@ struct redisServer {
list
*
clients_pending_write
;
/* There is to write or install handler. */
list
*
clients_pending_write
;
/* There is to write or install handler. */
list
*
slaves
,
*
monitors
;
/* List of slaves and MONITORs */
list
*
slaves
,
*
monitors
;
/* List of slaves and MONITORs */
client
*
current_client
;
/* Current client, only used on crash report */
client
*
current_client
;
/* Current client, only used on crash report */
rax
*
clients_index
;
/* Active clients dictionary by client ID. */
int
clients_paused
;
/* True if clients are currently paused */
int
clients_paused
;
/* True if clients are currently paused */
mstime_t
clients_pause_end_time
;
/* Time when we undo clients_paused */
mstime_t
clients_pause_end_time
;
/* Time when we undo clients_paused */
char
neterr
[
ANET_ERR_LEN
];
/* Error buffer for anet.c */
char
neterr
[
ANET_ERR_LEN
];
/* Error buffer for anet.c */
...
...
Write
Preview
Markdown
is supported
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