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
482b672d
Commit
482b672d
authored
May 16, 2010
by
antirez
Browse files
random refactoring and speedups
parent
d6f4c262
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
482b672d
...
@@ -2760,21 +2760,6 @@ static void addReplyDouble(redisClient *c, double d) {
...
@@ -2760,21 +2760,6 @@ static void addReplyDouble(redisClient *c, double d) {
(
unsigned
long
)
strlen
(
buf
),
buf
));
(
unsigned
long
)
strlen
(
buf
),
buf
));
}
}
static void addReplyLong(redisClient *c, long l) {
char buf[128];
size_t len;
if (l == 0) {
addReply(c,shared.czero);
return;
} else if (l == 1) {
addReply(c,shared.cone);
return;
}
len = snprintf(buf,sizeof(buf),":%ld\r\n",l);
addReplySds(c,sdsnewlen(buf,len));
}
static
void
addReplyLongLong
(
redisClient
*
c
,
long
long
ll
)
{
static
void
addReplyLongLong
(
redisClient
*
c
,
long
long
ll
)
{
char
buf
[
128
];
char
buf
[
128
];
size_t
len
;
size_t
len
;
...
@@ -2786,8 +2771,11 @@ static void addReplyLongLong(redisClient *c, long long ll) {
...
@@ -2786,8 +2771,11 @@ static void addReplyLongLong(redisClient *c, long long ll) {
addReply
(
c
,
shared
.
cone
);
addReply
(
c
,
shared
.
cone
);
return
;
return
;
}
}
len = snprintf(buf,sizeof(buf),":%lld\r\n",ll);
buf
[
0
]
=
':'
;
addReplySds(c,sdsnewlen(buf,len));
len
=
ll2string
(
buf
+
1
,
sizeof
(
buf
)
-
1
,
ll
);
buf
[
len
+
1
]
=
'\r'
;
buf
[
len
+
2
]
=
'\n'
;
addReplySds
(
c
,
sdsnewlen
(
buf
,
len
+
3
));
}
}
static
void
addReplyUlong
(
redisClient
*
c
,
unsigned
long
ul
)
{
static
void
addReplyUlong
(
redisClient
*
c
,
unsigned
long
ul
)
{
...
@@ -2806,7 +2794,8 @@ static void addReplyUlong(redisClient *c, unsigned long ul) {
...
@@ -2806,7 +2794,8 @@ static void addReplyUlong(redisClient *c, unsigned long ul) {
}
}
static
void
addReplyBulkLen
(
redisClient
*
c
,
robj
*
obj
)
{
static
void
addReplyBulkLen
(
redisClient
*
c
,
robj
*
obj
)
{
size_t len;
size_t
len
,
intlen
;
char
buf
[
128
];
if
(
obj
->
encoding
==
REDIS_ENCODING_RAW
)
{
if
(
obj
->
encoding
==
REDIS_ENCODING_RAW
)
{
len
=
sdslen
(
obj
->
ptr
);
len
=
sdslen
(
obj
->
ptr
);
...
@@ -2823,7 +2812,11 @@ static void addReplyBulkLen(redisClient *c, robj *obj) {
...
@@ -2823,7 +2812,11 @@ static void addReplyBulkLen(redisClient *c, robj *obj) {
len
++
;
len
++
;
}
}
}
}
addReplySds(c,sdscatprintf(sdsempty(),"$%lu\r\n",(unsigned long)len));
buf
[
0
]
=
'$'
;
intlen
=
ll2string
(
buf
+
1
,
sizeof
(
buf
)
-
1
,(
long
long
)
len
);
buf
[
intlen
+
1
]
=
'\r'
;
buf
[
intlen
+
2
]
=
'\n'
;
addReplySds
(
c
,
sdsnewlen
(
buf
,
intlen
+
3
));
}
}
static
void
addReplyBulk
(
redisClient
*
c
,
robj
*
obj
)
{
static
void
addReplyBulk
(
redisClient
*
c
,
robj
*
obj
)
{
...
@@ -4464,7 +4457,7 @@ static void delCommand(redisClient *c) {
...
@@ -4464,7 +4457,7 @@ static void delCommand(redisClient *c) {
deleted
++
;
deleted
++
;
}
}
}
}
addReplyLong(c,deleted);
addReplyLong
Long
(
c
,
deleted
);
}
}
static
void
existsCommand
(
redisClient
*
c
)
{
static
void
existsCommand
(
redisClient
*
c
)
{
...
@@ -4749,7 +4742,7 @@ static void pushGenericCommand(redisClient *c, int where) {
...
@@ -4749,7 +4742,7 @@ static void pushGenericCommand(redisClient *c, int where) {
incrRefCount
(
c
->
argv
[
2
]);
incrRefCount
(
c
->
argv
[
2
]);
}
}
server
.
dirty
++
;
server
.
dirty
++
;
addReply
Sds(c,sdscatprintf(sdsempty(),":%d\r\n"
,listLength(list))
)
;
addReply
LongLong
(
c
,
listLength
(
list
));
}
}
static
void
lpushCommand
(
redisClient
*
c
)
{
static
void
lpushCommand
(
redisClient
*
c
)
{
...
@@ -5251,7 +5244,7 @@ static void sinterGenericCommand(redisClient *c, robj **setskeys, unsigned long
...
@@ -5251,7 +5244,7 @@ static void sinterGenericCommand(redisClient *c, robj **setskeys, unsigned long
if
(
dictSize
((
dict
*
)
dstset
->
ptr
)
>
0
)
{
if
(
dictSize
((
dict
*
)
dstset
->
ptr
)
>
0
)
{
dictAdd
(
c
->
db
->
dict
,
dstkey
,
dstset
);
dictAdd
(
c
->
db
->
dict
,
dstkey
,
dstset
);
incrRefCount
(
dstkey
);
incrRefCount
(
dstkey
);
addReplyLong(c,dictSize((dict*)dstset->ptr));
addReplyLong
Long
(
c
,
dictSize
((
dict
*
)
dstset
->
ptr
));
}
else
{
}
else
{
decrRefCount
(
dstset
);
decrRefCount
(
dstset
);
addReply
(
c
,
shared
.
czero
);
addReply
(
c
,
shared
.
czero
);
...
@@ -5354,7 +5347,7 @@ static void sunionDiffGenericCommand(redisClient *c, robj **setskeys, int setsnu
...
@@ -5354,7 +5347,7 @@ static void sunionDiffGenericCommand(redisClient *c, robj **setskeys, int setsnu
if
(
dictSize
((
dict
*
)
dstset
->
ptr
)
>
0
)
{
if
(
dictSize
((
dict
*
)
dstset
->
ptr
)
>
0
)
{
dictAdd
(
c
->
db
->
dict
,
dstkey
,
dstset
);
dictAdd
(
c
->
db
->
dict
,
dstkey
,
dstset
);
incrRefCount
(
dstkey
);
incrRefCount
(
dstkey
);
addReplyLong(c,dictSize((dict*)dstset->ptr));
addReplyLong
Long
(
c
,
dictSize
((
dict
*
)
dstset
->
ptr
));
}
else
{
}
else
{
decrRefCount
(
dstset
);
decrRefCount
(
dstset
);
addReply
(
c
,
shared
.
czero
);
addReply
(
c
,
shared
.
czero
);
...
@@ -5833,7 +5826,7 @@ static void zremrangebyscoreCommand(redisClient *c) {
...
@@ -5833,7 +5826,7 @@ static void zremrangebyscoreCommand(redisClient *c) {
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
deleteKey
(
c
->
db
,
c
->
argv
[
1
]);
if
(
dictSize
(
zs
->
dict
)
==
0
)
deleteKey
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
+=
deleted
;
server
.
dirty
+=
deleted
;
addReplyLong(c,deleted);
addReplyLong
Long
(
c
,
deleted
);
}
}
static
void
zremrangebyrankCommand
(
redisClient
*
c
)
{
static
void
zremrangebyrankCommand
(
redisClient
*
c
)
{
...
@@ -5871,7 +5864,7 @@ static void zremrangebyrankCommand(redisClient *c) {
...
@@ -5871,7 +5864,7 @@ static void zremrangebyrankCommand(redisClient *c) {
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
deleteKey
(
c
->
db
,
c
->
argv
[
1
]);
if
(
dictSize
(
zs
->
dict
)
==
0
)
deleteKey
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
+=
deleted
;
server
.
dirty
+=
deleted
;
addReplyLong(c, deleted);
addReplyLong
Long
(
c
,
deleted
);
}
}
typedef
struct
{
typedef
struct
{
...
@@ -6057,7 +6050,7 @@ static void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
...
@@ -6057,7 +6050,7 @@ static void zunionInterGenericCommand(redisClient *c, robj *dstkey, int op) {
if
(
dstzset
->
zsl
->
length
)
{
if
(
dstzset
->
zsl
->
length
)
{
dictAdd
(
c
->
db
->
dict
,
dstkey
,
dstobj
);
dictAdd
(
c
->
db
->
dict
,
dstkey
,
dstobj
);
incrRefCount
(
dstkey
);
incrRefCount
(
dstkey
);
addReplyLong(c, dstzset->zsl->length);
addReplyLong
Long
(
c
,
dstzset
->
zsl
->
length
);
server
.
dirty
++
;
server
.
dirty
++
;
}
else
{
}
else
{
decrRefCount
(
dstobj
);
decrRefCount
(
dstobj
);
...
@@ -6253,7 +6246,7 @@ static void genericZrangebyscoreCommand(redisClient *c, int justcount) {
...
@@ -6253,7 +6246,7 @@ static void genericZrangebyscoreCommand(redisClient *c, int justcount) {
if
(
limit
>
0
)
limit
--
;
if
(
limit
>
0
)
limit
--
;
}
}
if
(
justcount
)
{
if
(
justcount
)
{
addReplyLong(c,(long)rangelen);
addReplyLong
Long
(
c
,(
long
)
rangelen
);
}
else
{
}
else
{
lenobj
->
ptr
=
sdscatprintf
(
sdsempty
(),
"*%lu
\r\n
"
,
lenobj
->
ptr
=
sdscatprintf
(
sdsempty
(),
"*%lu
\r\n
"
,
withscores
?
(
rangelen
*
2
)
:
rangelen
);
withscores
?
(
rangelen
*
2
)
:
rangelen
);
...
@@ -6323,9 +6316,9 @@ static void zrankGenericCommand(redisClient *c, int reverse) {
...
@@ -6323,9 +6316,9 @@ static void zrankGenericCommand(redisClient *c, int reverse) {
rank
=
zslGetRank
(
zsl
,
*
score
,
c
->
argv
[
2
]);
rank
=
zslGetRank
(
zsl
,
*
score
,
c
->
argv
[
2
]);
if
(
rank
)
{
if
(
rank
)
{
if
(
reverse
)
{
if
(
reverse
)
{
addReplyLong(c, zsl->length - rank);
addReplyLong
Long
(
c
,
zsl
->
length
-
rank
);
}
else
{
}
else
{
addReplyLong(c, rank-1);
addReplyLong
Long
(
c
,
rank
-
1
);
}
}
}
else
{
}
else
{
addReply
(
c
,
shared
.
nullbulk
);
addReply
(
c
,
shared
.
nullbulk
);
...
@@ -10035,7 +10028,7 @@ static int pubsubSubscribeChannel(redisClient *c, robj *channel) {
...
@@ -10035,7 +10028,7 @@ static int pubsubSubscribeChannel(redisClient *c, robj *channel) {
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
subscribebulk
);
addReply
(
c
,
shared
.
subscribebulk
);
addReplyBulk
(
c
,
channel
);
addReplyBulk
(
c
,
channel
);
addReplyLong(c,dictSize(c->pubsub_channels)+listLength(c->pubsub_patterns));
addReplyLong
Long
(
c
,
dictSize
(
c
->
pubsub_channels
)
+
listLength
(
c
->
pubsub_patterns
));
return
retval
;
return
retval
;
}
}
...
@@ -10071,7 +10064,7 @@ static int pubsubUnsubscribeChannel(redisClient *c, robj *channel, int notify) {
...
@@ -10071,7 +10064,7 @@ static int pubsubUnsubscribeChannel(redisClient *c, robj *channel, int notify) {
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
unsubscribebulk
);
addReply
(
c
,
shared
.
unsubscribebulk
);
addReplyBulk
(
c
,
channel
);
addReplyBulk
(
c
,
channel
);
addReplyLong(c,dictSize(c->pubsub_channels)+
addReplyLong
Long
(
c
,
dictSize
(
c
->
pubsub_channels
)
+
listLength
(
c
->
pubsub_patterns
));
listLength
(
c
->
pubsub_patterns
));
}
}
...
@@ -10097,7 +10090,7 @@ static int pubsubSubscribePattern(redisClient *c, robj *pattern) {
...
@@ -10097,7 +10090,7 @@ static int pubsubSubscribePattern(redisClient *c, robj *pattern) {
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
psubscribebulk
);
addReply
(
c
,
shared
.
psubscribebulk
);
addReplyBulk
(
c
,
pattern
);
addReplyBulk
(
c
,
pattern
);
addReplyLong(c,dictSize(c->pubsub_channels)+listLength(c->pubsub_patterns));
addReplyLong
Long
(
c
,
dictSize
(
c
->
pubsub_channels
)
+
listLength
(
c
->
pubsub_patterns
));
return
retval
;
return
retval
;
}
}
...
@@ -10122,7 +10115,7 @@ static int pubsubUnsubscribePattern(redisClient *c, robj *pattern, int notify) {
...
@@ -10122,7 +10115,7 @@ static int pubsubUnsubscribePattern(redisClient *c, robj *pattern, int notify) {
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
mbulk3
);
addReply
(
c
,
shared
.
punsubscribebulk
);
addReply
(
c
,
shared
.
punsubscribebulk
);
addReplyBulk
(
c
,
pattern
);
addReplyBulk
(
c
,
pattern
);
addReplyLong(c,dictSize(c->pubsub_channels)+
addReplyLong
Long
(
c
,
dictSize
(
c
->
pubsub_channels
)
+
listLength
(
c
->
pubsub_patterns
));
listLength
(
c
->
pubsub_patterns
));
}
}
decrRefCount
(
pattern
);
decrRefCount
(
pattern
);
...
@@ -10250,7 +10243,7 @@ static void punsubscribeCommand(redisClient *c) {
...
@@ -10250,7 +10243,7 @@ static void punsubscribeCommand(redisClient *c) {
static
void
publishCommand
(
redisClient
*
c
)
{
static
void
publishCommand
(
redisClient
*
c
)
{
int
receivers
=
pubsubPublishMessage
(
c
->
argv
[
1
],
c
->
argv
[
2
]);
int
receivers
=
pubsubPublishMessage
(
c
->
argv
[
1
],
c
->
argv
[
2
]);
addReplyLong(c,receivers);
addReplyLong
Long
(
c
,
receivers
);
}
}
/* ================================= Debugging ============================== */
/* ================================= Debugging ============================== */
...
...
staticsymbols.h
View file @
482b672d
...
@@ -8,7 +8,6 @@ static struct redisFunctionSym symsTable[] = {
...
@@ -8,7 +8,6 @@ static struct redisFunctionSym symsTable[] = {
{
"addReplyBulkCString"
,(
unsigned
long
)
addReplyBulkCString
},
{
"addReplyBulkCString"
,(
unsigned
long
)
addReplyBulkCString
},
{
"addReplyBulkLen"
,(
unsigned
long
)
addReplyBulkLen
},
{
"addReplyBulkLen"
,(
unsigned
long
)
addReplyBulkLen
},
{
"addReplyDouble"
,(
unsigned
long
)
addReplyDouble
},
{
"addReplyDouble"
,(
unsigned
long
)
addReplyDouble
},
{
"addReplyLong"
,(
unsigned
long
)
addReplyLong
},
{
"addReplyLongLong"
,(
unsigned
long
)
addReplyLongLong
},
{
"addReplyLongLong"
,(
unsigned
long
)
addReplyLongLong
},
{
"addReplySds"
,(
unsigned
long
)
addReplySds
},
{
"addReplySds"
,(
unsigned
long
)
addReplySds
},
{
"addReplyUlong"
,(
unsigned
long
)
addReplyUlong
},
{
"addReplyUlong"
,(
unsigned
long
)
addReplyUlong
},
...
...
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