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
91867a5e
Commit
91867a5e
authored
Apr 21, 2011
by
antirez
Browse files
CLIENT LIST implemented
parent
1c30cad1
Changes
6
Show whitespace changes
Inline
Side-by-side
src/anet.c
View file @
91867a5e
...
@@ -345,3 +345,13 @@ int anetUnixAccept(char *err, int s) {
...
@@ -345,3 +345,13 @@ int anetUnixAccept(char *err, int s) {
return
fd
;
return
fd
;
}
}
int
anetPeerToString
(
int
fd
,
char
*
ip
,
int
*
port
)
{
struct
sockaddr_in
sa
;
socklen_t
salen
=
sizeof
(
sa
);
if
(
getpeername
(
fd
,(
struct
sockaddr
*
)
&
sa
,
&
salen
)
==
-
1
)
return
-
1
;
if
(
ip
)
strcpy
(
ip
,
inet_ntoa
(
sa
.
sin_addr
));
if
(
port
)
*
port
=
ntohs
(
sa
.
sin_port
);
return
0
;
}
src/anet.h
View file @
91867a5e
...
@@ -53,5 +53,6 @@ int anetWrite(int fd, char *buf, int count);
...
@@ -53,5 +53,6 @@ int anetWrite(int fd, char *buf, int count);
int
anetNonBlock
(
char
*
err
,
int
fd
);
int
anetNonBlock
(
char
*
err
,
int
fd
);
int
anetTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetTcpKeepAlive
(
char
*
err
,
int
fd
);
int
anetTcpKeepAlive
(
char
*
err
,
int
fd
);
int
anetPeerToString
(
int
fd
,
char
*
ip
,
int
*
port
);
#endif
#endif
src/networking.c
View file @
91867a5e
...
@@ -865,3 +865,49 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
...
@@ -865,3 +865,49 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
*
biggest_input_buffer
=
bib
;
*
biggest_input_buffer
=
bib
;
}
}
void
clientCommand
(
redisClient
*
c
)
{
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"list"
)
&&
c
->
argc
==
2
)
{
listNode
*
ln
;
listIter
li
;
sds
o
=
sdsempty
();
time_t
now
=
time
(
NULL
);
listRewind
(
server
.
clients
,
&
li
);
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
redisClient
*
client
;
char
ip
[
32
],
flags
[
16
],
*
p
;
int
port
;
client
=
listNodeValue
(
ln
);
if
(
anetPeerToString
(
client
->
fd
,
ip
,
&
port
)
==
-
1
)
continue
;
p
=
flags
;
if
(
client
->
flags
&
REDIS_SLAVE
)
{
if
(
client
->
flags
&
REDIS_MONITOR
)
*
p
++
=
'O'
;
else
*
p
++
=
'S'
;
}
if
(
client
->
flags
&
REDIS_MASTER
)
*
p
++
=
'M'
;
if
(
p
==
flags
)
*
p
++
=
'N'
;
if
(
client
->
flags
&
REDIS_MULTI
)
*
p
++
=
'x'
;
if
(
client
->
flags
&
REDIS_BLOCKED
)
*
p
++
=
'b'
;
if
(
client
->
flags
&
REDIS_IO_WAIT
)
*
p
++
=
'i'
;
if
(
client
->
flags
&
REDIS_DIRTY_CAS
)
*
p
++
=
'd'
;
if
(
client
->
flags
&
REDIS_CLOSE_AFTER_REPLY
)
*
p
++
=
'c'
;
if
(
client
->
flags
&
REDIS_UNBLOCKED
)
*
p
++
=
'u'
;
*
p
++
=
'\0'
;
o
=
sdscatprintf
(
o
,
"addr=%s:%d fd=%d idle=%ld flags=%s db=%d sub=%d psub=%d
\n
"
,
ip
,
port
,
client
->
fd
,
(
long
)(
now
-
client
->
lastinteraction
),
flags
,
client
->
db
->
id
,
(
int
)
dictSize
(
client
->
pubsub_channels
),
(
int
)
listLength
(
client
->
pubsub_patterns
));
}
addReplyBulkCBuffer
(
c
,
o
,
sdslen
(
o
));
sdsfree
(
o
);
}
else
{
addReplyError
(
c
,
"Syntax error, try CLIENT (LIST | KILL ip:port)"
);
}
}
src/redis-cli.c
View file @
91867a5e
...
@@ -465,7 +465,15 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -465,7 +465,15 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
return
REDIS_OK
;
return
REDIS_OK
;
}
}
output_raw
=
!
strcasecmp
(
command
,
"info"
);
output_raw
=
0
;
if
(
!
strcasecmp
(
command
,
"info"
)
||
(
argc
==
2
&&
!
strcasecmp
(
command
,
"client"
)
&&
!
strcasecmp
(
argv
[
1
],
"list"
)))
{
output_raw
=
1
;
}
if
(
!
strcasecmp
(
command
,
"help"
)
||
!
strcasecmp
(
command
,
"?"
))
{
if
(
!
strcasecmp
(
command
,
"help"
)
||
!
strcasecmp
(
command
,
"?"
))
{
cliOutputHelp
(
--
argc
,
++
argv
);
cliOutputHelp
(
--
argc
,
++
argv
);
return
REDIS_OK
;
return
REDIS_OK
;
...
...
src/redis.c
View file @
91867a5e
...
@@ -188,7 +188,8 @@ struct redisCommand readonlyCommandTable[] = {
...
@@ -188,7 +188,8 @@ struct redisCommand readonlyCommandTable[] = {
{"publish",publishCommand,3,REDIS_CMD_FORCE_REPLICATION,NULL,0,0,0},
{"publish",publishCommand,3,REDIS_CMD_FORCE_REPLICATION,NULL,0,0,0},
{"watch",watchCommand,-2,0,NULL,0,0,0},
{"watch",watchCommand,-2,0,NULL,0,0,0},
{"unwatch",unwatchCommand,1,0,NULL,0,0,0},
{"unwatch",unwatchCommand,1,0,NULL,0,0,0},
{"object",objectCommand,-2,0,NULL,0,0,0}
{"object",objectCommand,-2,0,NULL,0,0,0},
{"client",clientCommand,-2,0,NULL,0,0,0}
};
};
/*============================ Utility functions ============================ */
/*============================ Utility functions ============================ */
...
...
src/redis.h
View file @
91867a5e
...
@@ -1031,6 +1031,7 @@ void publishCommand(redisClient *c);
...
@@ -1031,6 +1031,7 @@ void publishCommand(redisClient *c);
void
watchCommand
(
redisClient
*
c
);
void
watchCommand
(
redisClient
*
c
);
void
unwatchCommand
(
redisClient
*
c
);
void
unwatchCommand
(
redisClient
*
c
);
void
objectCommand
(
redisClient
*
c
);
void
objectCommand
(
redisClient
*
c
);
void
clientCommand
(
redisClient
*
c
);
#if defined(__GNUC__)
#if defined(__GNUC__)
void
*
calloc
(
size_t
count
,
size_t
size
)
__attribute__
((
deprecated
));
void
*
calloc
(
size_t
count
,
size_t
size
)
__attribute__
((
deprecated
));
...
...
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