Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
a5639e7d
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5639e7d
编写于
8月 03, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change initialization to allow listening on both a port and socket
上级
7e91f971
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
20 deletion
+49
-20
redis.conf
redis.conf
+7
-1
src/aof.c
src/aof.c
+2
-1
src/config.c
src/config.c
+5
-1
src/rdb.c
src/rdb.c
+2
-1
src/redis.c
src/redis.c
+29
-14
src/redis.h
src/redis.h
+4
-2
未找到文件。
redis.conf
浏览文件 @
a5639e7d
...
...
@@ -20,7 +20,8 @@ daemonize no
# default. You can specify a custom pid file location here.
pidfile
/
var
/
run
/
redis
.
pid
# Accept connections on the specified port, default is 6379
# Accept connections on the specified port, default is 6379.
# Use port -1 to disable listening on a network interface.
port
6379
# If you want you can bind a single interface, if the bind option is not
...
...
@@ -28,6 +29,11 @@ port 6379
#
# bind 127.0.0.1
# Specify the path for the domain socket that will be used to listen for
# incoming connections. If not specified, Redis will not use a domain socket.
#
# socket /tmp/redis.sock
# Close the connection after a client is idle for N seconds (0 to disable)
timeout
300
...
...
src/aof.c
浏览文件 @
a5639e7d
...
...
@@ -588,7 +588,8 @@ int rewriteAppendOnlyFileBackground(void) {
char
tmpfile
[
256
];
if
(
server
.
vm_enabled
)
vmReopenSwapFile
();
close
(
server
.
fd
);
if
(
server
.
ipfd
>
0
)
close
(
server
.
ipfd
);
if
(
server
.
sofd
>
0
)
close
(
server
.
sofd
);
snprintf
(
tmpfile
,
256
,
"temp-rewriteaof-bg-%d.aof"
,
(
int
)
getpid
());
if
(
rewriteAppendOnlyFile
(
tmpfile
)
==
REDIS_OK
)
{
_exit
(
0
);
...
...
src/config.c
浏览文件 @
a5639e7d
...
...
@@ -66,11 +66,15 @@ void loadServerConfig(char *filename) {
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"port"
)
&&
argc
==
2
)
{
server
.
port
=
atoi
(
argv
[
1
]);
if
(
server
.
port
<
1
||
server
.
port
>
65535
)
{
if
(
server
.
port
!=
-
1
&&
(
server
.
port
<
1
||
server
.
port
>
65535
))
{
err
=
"Invalid port"
;
goto
loaderr
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"bind"
)
&&
argc
==
2
)
{
server
.
bindaddr
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"socket"
)
&&
argc
==
2
)
{
server
.
sockpath
=
zstrdup
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"save"
)
&&
argc
==
3
)
{
int
seconds
=
atoi
(
argv
[
1
]);
int
changes
=
atoi
(
argv
[
2
]);
...
...
src/rdb.c
浏览文件 @
a5639e7d
...
...
@@ -448,7 +448,8 @@ int rdbSaveBackground(char *filename) {
if
((
childpid
=
fork
())
==
0
)
{
/* Child */
if
(
server
.
vm_enabled
)
vmReopenSwapFile
();
close
(
server
.
fd
);
if
(
server
.
ipfd
>
0
)
close
(
server
.
ipfd
);
if
(
server
.
sofd
>
0
)
close
(
server
.
sofd
);
if
(
rdbSave
(
filename
)
==
REDIS_OK
)
{
_exit
(
0
);
}
else
{
...
...
src/redis.c
浏览文件 @
a5639e7d
...
...
@@ -696,13 +696,16 @@ void createSharedObjects(void) {
}
void
initServerConfig
()
{
server
.
dbnum
=
REDIS_DEFAULT_DBNUM
;
server
.
port
=
REDIS_SERVERPORT
;
server
.
bindaddr
=
NULL
;
server
.
sockpath
=
NULL
;
server
.
ipfd
=
-
1
;
server
.
sofd
=
-
1
;
server
.
dbnum
=
REDIS_DEFAULT_DBNUM
;
server
.
verbosity
=
REDIS_VERBOSE
;
server
.
maxidletime
=
REDIS_MAXIDLETIME
;
server
.
saveparams
=
NULL
;
server
.
logfile
=
NULL
;
/* NULL = log on standard output */
server
.
bindaddr
=
NULL
;
server
.
glueoutputbuf
=
1
;
server
.
daemonize
=
0
;
server
.
appendonly
=
0
;
...
...
@@ -773,16 +776,23 @@ void initServer() {
createSharedObjects
();
server
.
el
=
aeCreateEventLoop
();
server
.
db
=
zmalloc
(
sizeof
(
redisDb
)
*
server
.
dbnum
);
if
(
server
.
bindaddr
==
NULL
||
inet_aton
(
server
.
bindaddr
,
NULL
))
{
/* Either no address given, or it can be correctly parsed. */
server
.
fd
=
anetTcpServer
(
server
.
neterr
,
server
.
port
,
server
.
bindaddr
);
}
else
{
/* Bind to a socket */
unlink
(
server
.
bindaddr
);
/* don't care if this fails */
server
.
fd
=
anetUnixServer
(
server
.
neterr
,
server
.
bindaddr
);
if
(
server
.
port
>
0
)
{
server
.
ipfd
=
anetTcpServer
(
server
.
neterr
,
server
.
port
,
server
.
bindaddr
);
if
(
server
.
ipfd
==
ANET_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Opening port: %s"
,
server
.
neterr
);
exit
(
1
);
}
}
if
(
server
.
sockpath
!=
NULL
)
{
unlink
(
server
.
sockpath
);
/* don't care if this fails */
server
.
sofd
=
anetUnixServer
(
server
.
neterr
,
server
.
sockpath
);
if
(
server
.
sofd
==
ANET_ERR
)
{
redisLog
(
REDIS_WARNING
,
"Opening socket: %s"
,
server
.
neterr
);
exit
(
1
);
}
}
if
(
server
.
fd
==
-
1
)
{
redisLog
(
REDIS_WARNING
,
"
Opening port/socket: %s"
,
server
.
neterr
);
if
(
server
.
ipfd
<
0
&&
server
.
sofd
<
0
)
{
redisLog
(
REDIS_WARNING
,
"
Configured to not listen anywhere, exiting."
);
exit
(
1
);
}
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
...
...
@@ -811,8 +821,10 @@ void initServer() {
server
.
stat_starttime
=
time
(
NULL
);
server
.
unixtime
=
time
(
NULL
);
aeCreateTimeEvent
(
server
.
el
,
1
,
serverCron
,
NULL
,
NULL
);
if
(
aeCreateFileEvent
(
server
.
el
,
server
.
fd
,
AE_READABLE
,
acceptHandler
,
NULL
)
==
AE_ERR
)
oom
(
"creating file event"
);
if
(
server
.
ipfd
>
0
&&
aeCreateFileEvent
(
server
.
el
,
server
.
ipfd
,
AE_READABLE
,
acceptHandler
,
NULL
)
==
AE_ERR
)
oom
(
"creating file event"
);
if
(
server
.
sofd
>
0
&&
aeCreateFileEvent
(
server
.
el
,
server
.
sofd
,
AE_READABLE
,
acceptHandler
,
NULL
)
==
AE_ERR
)
oom
(
"creating file event"
);
if
(
server
.
appendonly
)
{
server
.
appendfd
=
open
(
server
.
appendfilename
,
O_WRONLY
|
O_APPEND
|
O_CREAT
,
0644
);
...
...
@@ -1423,7 +1435,10 @@ int main(int argc, char **argv) {
if
(
rdbLoad
(
server
.
dbfilename
)
==
REDIS_OK
)
redisLog
(
REDIS_NOTICE
,
"DB loaded from disk: %ld seconds"
,
time
(
NULL
)
-
start
);
}
redisLog
(
REDIS_NOTICE
,
"The server is now ready to accept connections on port %d"
,
server
.
port
);
if
(
server
.
ipfd
>
0
)
redisLog
(
REDIS_NOTICE
,
"The server is now ready to accept connections on port %d"
,
server
.
port
);
if
(
server
.
sofd
>
0
)
redisLog
(
REDIS_NOTICE
,
"The server is now ready to accept connections at %s"
,
server
.
sockpath
);
aeSetBeforeSleepProc
(
server
.
el
,
beforeSleep
);
aeMain
(
server
.
el
);
aeDeleteEventLoop
(
server
.
el
);
...
...
src/redis.h
浏览文件 @
a5639e7d
...
...
@@ -329,7 +329,10 @@ struct sharedObjectsStruct {
struct
redisServer
{
pthread_t
mainthread
;
int
port
;
int
fd
;
char
*
bindaddr
;
char
*
sockpath
;
int
ipfd
;
int
sofd
;
redisDb
*
db
;
long
long
dirty
;
/* changes to DB from the last save */
list
*
clients
;
...
...
@@ -365,7 +368,6 @@ struct redisServer {
struct
saveparam
*
saveparams
;
int
saveparamslen
;
char
*
logfile
;
char
*
bindaddr
;
char
*
dbfilename
;
char
*
appendfilename
;
char
*
requirepass
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录