Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
285add55
Commit
285add55
authored
May 25, 2009
by
antirez
Browse files
maxclients implemented, see redis.conf for details
parent
a0f643ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
285add55
...
@@ -245,6 +245,7 @@ struct redisServer {
...
@@ -245,6 +245,7 @@ struct redisServer {
int
masterport
;
int
masterport
;
redisClient
*
master
;
/* client that is master for this slave */
redisClient
*
master
;
/* client that is master for this slave */
int
replstate
;
int
replstate
;
unsigned
int
maxclients
;
/* Sort parameters - qsort_r() is only available under BSD so we
/* Sort parameters - qsort_r() is only available under BSD so we
* have to take this state global, in order to pass it to sortCompare() */
* have to take this state global, in order to pass it to sortCompare() */
int
sort_desc
;
int
sort_desc
;
...
@@ -862,6 +863,7 @@ static void initServerConfig() {
...
@@ -862,6 +863,7 @@ static void initServerConfig() {
server
.
dbfilename
=
"dump.rdb"
;
server
.
dbfilename
=
"dump.rdb"
;
server
.
requirepass
=
NULL
;
server
.
requirepass
=
NULL
;
server
.
shareobjects
=
0
;
server
.
shareobjects
=
0
;
server
.
maxclients
=
0
;
ResetServerSaveParams
();
ResetServerSaveParams
();
appendServerSaveParams
(
60
*
60
,
1
);
/* save after 1 hour and 1 change */
appendServerSaveParams
(
60
*
60
,
1
);
/* save after 1 hour and 1 change */
...
@@ -1020,6 +1022,8 @@ static void loadServerConfig(char *filename) {
...
@@ -1020,6 +1022,8 @@ static void loadServerConfig(char *filename) {
if
(
server
.
dbnum
<
1
)
{
if
(
server
.
dbnum
<
1
)
{
err
=
"Invalid number of databases"
;
goto
loaderr
;
err
=
"Invalid number of databases"
;
goto
loaderr
;
}
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"maxclients"
)
&&
argc
==
2
)
{
server
.
maxclients
=
atoi
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slaveof"
)
&&
argc
==
3
)
{
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"slaveof"
)
&&
argc
==
3
)
{
server
.
masterhost
=
sdsnew
(
argv
[
1
]);
server
.
masterhost
=
sdsnew
(
argv
[
1
]);
server
.
masterport
=
atoi
(
argv
[
2
]);
server
.
masterport
=
atoi
(
argv
[
2
]);
...
@@ -1500,6 +1504,7 @@ static void addReplySds(redisClient *c, sds s) {
...
@@ -1500,6 +1504,7 @@ static void addReplySds(redisClient *c, sds s) {
static
void
acceptHandler
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
static
void
acceptHandler
(
aeEventLoop
*
el
,
int
fd
,
void
*
privdata
,
int
mask
)
{
int
cport
,
cfd
;
int
cport
,
cfd
;
char
cip
[
128
];
char
cip
[
128
];
redisClient
*
c
;
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
el
);
REDIS_NOTUSED
(
mask
);
REDIS_NOTUSED
(
mask
);
REDIS_NOTUSED
(
privdata
);
REDIS_NOTUSED
(
privdata
);
...
@@ -1510,11 +1515,23 @@ static void acceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -1510,11 +1515,23 @@ static void acceptHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
return
;
return
;
}
}
redisLog
(
REDIS_DEBUG
,
"Accepted %s:%d"
,
cip
,
cport
);
redisLog
(
REDIS_DEBUG
,
"Accepted %s:%d"
,
cip
,
cport
);
if (createClient(cfd) == NULL) {
if
(
(
c
=
createClient
(
cfd
)
)
==
NULL
)
{
redisLog
(
REDIS_WARNING
,
"Error allocating resoures for the client"
);
redisLog
(
REDIS_WARNING
,
"Error allocating resoures for the client"
);
close
(
cfd
);
/* May be already closed, just ingore errors */
close
(
cfd
);
/* May be already closed, just ingore errors */
return
;
return
;
}
}
/* If maxclient directive is set and this is one client more... close the
* connection. Note that we create the client instead to check before
* for this condition, since now the socket is already set in nonblocking
* mode and we can send an error for free using the Kernel I/O */
if
(
server
.
maxclients
&&
listLength
(
server
.
clients
)
>
server
.
maxclients
)
{
char
*
err
=
"-ERR max number of clients reached
\r\n
"
;
/* That's a best effort error message, don't check write errors */
write
(
c
->
fd
,
err
,
strlen
(
err
));
freeClient
(
c
);
return
;
}
server
.
stat_numconnections
++
;
server
.
stat_numconnections
++
;
}
}
...
...
redis.conf
View file @
285add55
...
@@ -78,6 +78,16 @@ databases 16
...
@@ -78,6 +78,16 @@ databases 16
# requirepass foobared
# requirepass foobared
################################### LIMITS ####################################
# Set the max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value '0' means no limts.
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
# maxclients 128
############################### ADVANCED CONFIG ###############################
############################### ADVANCED CONFIG ###############################
# Glue small output buffers together in order to send small replies in a
# Glue small output buffers together in order to send small replies in a
...
...
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