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
3f4eef21
Commit
3f4eef21
authored
Mar 06, 2011
by
Pieter Noordhuis
Browse files
Show database number in cli prompt when non-zero
parent
96e34b3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
3f4eef21
...
@@ -64,6 +64,7 @@ static struct config {
...
@@ -64,6 +64,7 @@ static struct config {
char
*
auth
;
char
*
auth
;
int
raw_output
;
/* output mode per command */
int
raw_output
;
/* output mode per command */
sds
mb_delim
;
sds
mb_delim
;
char
prompt
[
32
];
}
config
;
}
config
;
static
void
usage
();
static
void
usage
();
...
@@ -84,6 +85,13 @@ static long long mstime(void) {
...
@@ -84,6 +85,13 @@ static long long mstime(void) {
return
mst
;
return
mst
;
}
}
static
void
cliRefreshPrompt
(
void
)
{
if
(
config
.
dbnum
==
0
)
snprintf
(
config
.
prompt
,
sizeof
(
config
.
prompt
),
"redis> "
);
else
snprintf
(
config
.
prompt
,
sizeof
(
config
.
prompt
),
"redis:%d> "
,
config
.
dbnum
);
}
/*------------------------------------------------------------------------------
/*------------------------------------------------------------------------------
* Help functions
* Help functions
*--------------------------------------------------------------------------- */
*--------------------------------------------------------------------------- */
...
@@ -491,8 +499,10 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -491,8 +499,10 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
return
REDIS_ERR
;
return
REDIS_ERR
;
}
else
{
}
else
{
/* Store database number when SELECT was successfully executed. */
/* Store database number when SELECT was successfully executed. */
if
(
!
strcasecmp
(
command
,
"select"
)
&&
argc
==
2
)
if
(
!
strcasecmp
(
command
,
"select"
)
&&
argc
==
2
)
{
config
.
dbnum
=
atoi
(
argv
[
1
]);
config
.
dbnum
=
atoi
(
argv
[
1
]);
cliRefreshPrompt
();
}
}
}
}
}
...
@@ -633,7 +643,8 @@ static void repl() {
...
@@ -633,7 +643,8 @@ static void repl() {
}
}
}
}
while
((
line
=
linenoise
(
context
?
"redis> "
:
"not connected> "
))
!=
NULL
)
{
cliRefreshPrompt
();
while
((
line
=
linenoise
(
context
?
config
.
prompt
:
"not connected> "
))
!=
NULL
)
{
if
(
line
[
0
]
!=
'\0'
)
{
if
(
line
[
0
]
!=
'\0'
)
{
argv
=
sdssplitargs
(
line
,
&
argc
);
argv
=
sdssplitargs
(
line
,
&
argc
);
if
(
history
)
linenoiseHistoryAdd
(
line
);
if
(
history
)
linenoiseHistoryAdd
(
line
);
...
...
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