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
1222b608
Unverified
Commit
1222b608
authored
Apr 16, 2023
by
judeng
Committed by
GitHub
Apr 16, 2023
Browse files
improve performance of keys command by using static objects (#12036)
Improve performance by avoiding redundancy memory malloc/free
parent
d5d56d0d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
1222b608
...
...
@@ -774,17 +774,16 @@ void keysCommand(client *c) {
di
=
dictGetSafeIterator
(
c
->
db
->
dict
);
allkeys
=
(
pattern
[
0
]
==
'*'
&&
plen
==
1
);
robj
keyobj
;
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
sds
key
=
dictGetKey
(
de
);
robj
*
keyobj
;
if
(
allkeys
||
stringmatchlen
(
pattern
,
plen
,
key
,
sdslen
(
key
),
0
))
{
keyobj
=
create
StringObject
(
key
,
sdslen
(
key
)
)
;
if
(
!
keyIsExpired
(
c
->
db
,
keyobj
))
{
addReplyBulk
(
c
,
key
obj
);
initStatic
StringObject
(
key
obj
,
key
);
if
(
!
keyIsExpired
(
c
->
db
,
&
keyobj
))
{
addReplyBulk
CBuffer
(
c
,
key
,
sdslen
(
key
)
);
numkeys
++
;
}
decrRefCount
(
keyobj
);
}
if
(
c
->
flags
&
CLIENT_CLOSE_ASAP
)
break
;
...
...
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