Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
123a10f7
R
redis
项目概览
hanoi2005
/
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,发现更多精彩内容 >>
提交
123a10f7
编写于
8月 04, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Let the output mode depend on having a tty or not
上级
07242c0c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
12 deletion
+26
-12
src/redis-cli.c
src/redis-cli.c
+4
-1
tests/integration/redis-cli.tcl
tests/integration/redis-cli.tcl
+22
-11
未找到文件。
src/redis-cli.c
浏览文件 @
123a10f7
...
@@ -60,6 +60,7 @@ static struct config {
...
@@ -60,6 +60,7 @@ static struct config {
int
monitor_mode
;
int
monitor_mode
;
int
pubsub_mode
;
int
pubsub_mode
;
int
raw_output
;
/* output mode per command */
int
raw_output
;
/* output mode per command */
int
tty
;
/* flag for default output format */
char
*
auth
;
char
*
auth
;
char
*
historyfile
;
char
*
historyfile
;
}
config
;
}
config
;
...
@@ -152,7 +153,7 @@ static int cliReadBulkReply(int fd) {
...
@@ -152,7 +153,7 @@ static int cliReadBulkReply(int fd) {
reply
=
zmalloc
(
bulklen
);
reply
=
zmalloc
(
bulklen
);
anetRead
(
fd
,
reply
,
bulklen
);
anetRead
(
fd
,
reply
,
bulklen
);
anetRead
(
fd
,
crlf
,
2
);
anetRead
(
fd
,
crlf
,
2
);
if
(
config
.
raw_output
)
{
if
(
config
.
raw_output
||
!
config
.
tty
)
{
if
(
bulklen
&&
fwrite
(
reply
,
bulklen
,
1
,
stdout
)
==
0
)
{
if
(
bulklen
&&
fwrite
(
reply
,
bulklen
,
1
,
stdout
)
==
0
)
{
zfree
(
reply
);
zfree
(
reply
);
return
1
;
return
1
;
...
@@ -491,6 +492,7 @@ int main(int argc, char **argv) {
...
@@ -491,6 +492,7 @@ int main(int argc, char **argv) {
config
.
raw_output
=
0
;
config
.
raw_output
=
0
;
config
.
auth
=
NULL
;
config
.
auth
=
NULL
;
config
.
historyfile
=
NULL
;
config
.
historyfile
=
NULL
;
config
.
tty
=
1
;
if
(
getenv
(
"HOME"
)
!=
NULL
)
{
if
(
getenv
(
"HOME"
)
!=
NULL
)
{
config
.
historyfile
=
malloc
(
256
);
config
.
historyfile
=
malloc
(
256
);
...
@@ -515,6 +517,7 @@ int main(int argc, char **argv) {
...
@@ -515,6 +517,7 @@ int main(int argc, char **argv) {
repl
();
repl
();
}
}
config
.
tty
=
isatty
(
stdout
)
||
(
getenv
(
"FAKETTY"
)
!=
NULL
);
argvcopy
=
convertToSds
(
argc
+
1
,
argv
);
argvcopy
=
convertToSds
(
argc
+
1
,
argv
);
if
(
config
.
argn_from_stdin
)
{
if
(
config
.
argn_from_stdin
)
{
sds
lastarg
=
readArgFromStdin
();
sds
lastarg
=
readArgFromStdin
();
...
...
tests/integration/redis-cli.tcl
浏览文件 @
123a10f7
...
@@ -41,7 +41,7 @@ start_server {tags {"cli"}} {
...
@@ -41,7 +41,7 @@ start_server {tags {"cli"}} {
close_cli $fd
close_cli $fd
}
}
proc run_cli
{
args
}
{
proc run_
nontty_
cli
{
args
}
{
set fd
[
open
[
format
"|src/redis-cli -p %d -n 9
$args
"
[
srv port
]]
"r"
]
set fd
[
open
[
format
"|src/redis-cli -p %d -n 9
$args
"
[
srv port
]]
"r"
]
fconfigure $fd -buffering none
fconfigure $fd -buffering none
fconfigure $fd -translation binary
fconfigure $fd -translation binary
...
@@ -50,8 +50,19 @@ start_server {tags {"cli"}} {
...
@@ -50,8 +50,19 @@ start_server {tags {"cli"}} {
set _ $resp
set _ $resp
}
}
proc test_noninteractive_cli
{
name code
}
{
proc test_nontty_cli
{
name code
}
{
test
"Non-interactive CLI:
$name
"
$code
test
"Non-interactive non-TTY CLI:
$name
"
$code
}
proc run_tty_cli
{
args
}
{
set ::env
(
FAKETTY
)
1
set resp
[
run_nontty_cli
{*}
$args
]
unset ::env
(
FAKETTY
)
set _ $resp
}
proc test_tty_cli
{
name code
}
{
test
"Non-interactive TTY CLI:
$name
"
$code
}
}
test_interactive_cli
"INFO response should be printed raw"
{
test_interactive_cli
"INFO response should be printed raw"
{
...
@@ -99,25 +110,25 @@ start_server {tags {"cli"}} {
...
@@ -99,25 +110,25 @@ start_server {tags {"cli"}} {
assert_equal
"bar"
[
r get key
]
assert_equal
"bar"
[
r get key
]
}
}
test_
noninteractive
_cli
"Status reply"
{
test_
tty
_cli
"Status reply"
{
assert_equal
"OK
\n
"
[
run_cli set key bar
]
assert_equal
"OK
\n
"
[
run_
tty_
cli set key bar
]
assert_equal
"bar"
[
r get key
]
assert_equal
"bar"
[
r get key
]
}
}
test_
noninteractive
_cli
"Integer reply"
{
test_
tty
_cli
"Integer reply"
{
r del counter
r del counter
assert_equal
"(integer) 1
\n
"
[
run_cli incr counter
]
assert_equal
"(integer) 1
\n
"
[
run_
tty_
cli incr counter
]
}
}
test_
noninteractive
_cli
"Bulk reply"
{
test_
tty
_cli
"Bulk reply"
{
r set key
"tab
\t
newline
\n
"
r set key
"tab
\t
newline
\n
"
assert_equal
"
\"
tab
\\
tnewline
\\
n
\"\n
"
[
run_cli get key
]
assert_equal
"
\"
tab
\\
tnewline
\\
n
\"\n
"
[
run_
tty_
cli get key
]
}
}
test_
noninteractive
_cli
"Multi-bulk reply"
{
test_
tty
_cli
"Multi-bulk reply"
{
r del list
r del list
r rpush list foo
r rpush list foo
r rpush list bar
r rpush list bar
assert_equal
"1.
\"
foo
\"\n
2.
\"
bar
\"\n
"
[
run_cli lrange list 0 -1
]
assert_equal
"1.
\"
foo
\"\n
2.
\"
bar
\"\n
"
[
run_
tty_
cli lrange list 0 -1
]
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录