Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
003f0840
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
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,发现更多精彩内容 >>
提交
003f0840
编写于
6月 04, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renamed list wrapper functions to be more verbose
上级
d0686e07
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
76 deletion
+76
-76
redis.c
redis.c
+76
-76
未找到文件。
redis.c
浏览文件 @
003f0840
...
@@ -650,7 +650,7 @@ static struct redisCommand *lookupCommand(char *name);
...
@@ -650,7 +650,7 @@ static struct redisCommand *lookupCommand(char *name);
static
void
call
(
redisClient
*
c
,
struct
redisCommand
*
cmd
);
static
void
call
(
redisClient
*
c
,
struct
redisCommand
*
cmd
);
static
void
resetClient
(
redisClient
*
c
);
static
void
resetClient
(
redisClient
*
c
);
static
void
convertToRealHash
(
robj
*
o
);
static
void
convertToRealHash
(
robj
*
o
);
static
void
convertLis
t
(
robj
*
o
,
int
enc
);
static
void
listTypeConver
t
(
robj
*
o
,
int
enc
);
static
int
pubsubUnsubscribeAllChannels
(
redisClient
*
c
,
int
notify
);
static
int
pubsubUnsubscribeAllChannels
(
redisClient
*
c
,
int
notify
);
static
int
pubsubUnsubscribeAllPatterns
(
redisClient
*
c
,
int
notify
);
static
int
pubsubUnsubscribeAllPatterns
(
redisClient
*
c
,
int
notify
);
static
void
freePubsubPattern
(
void
*
p
);
static
void
freePubsubPattern
(
void
*
p
);
...
@@ -4181,7 +4181,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
...
@@ -4181,7 +4181,7 @@ static robj *rdbLoadObject(int type, FILE *fp) {
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
&&
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
&&
ele
->
encoding
==
REDIS_ENCODING_RAW
&&
ele
->
encoding
==
REDIS_ENCODING_RAW
&&
sdslen
(
ele
->
ptr
)
>
server
.
list_max_ziplist_value
)
sdslen
(
ele
->
ptr
)
>
server
.
list_max_ziplist_value
)
convertLis
t
(
o
,
REDIS_ENCODING_LIST
);
listTypeConver
t
(
o
,
REDIS_ENCODING_LIST
);
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
dec
=
getDecodedObject
(
ele
);
dec
=
getDecodedObject
(
ele
);
...
@@ -4910,19 +4910,19 @@ static void moveCommand(redisClient *c) {
...
@@ -4910,19 +4910,19 @@ static void moveCommand(redisClient *c) {
/* Check the argument length to see if it requires us to convert the ziplist
/* Check the argument length to see if it requires us to convert the ziplist
* to a real list. Only check raw-encoded objects because integer encoded
* to a real list. Only check raw-encoded objects because integer encoded
* objects are never too long. */
* objects are never too long. */
static
void
listTryConversion
(
robj
*
subject
,
robj
*
value
)
{
static
void
listT
ypeT
ryConversion
(
robj
*
subject
,
robj
*
value
)
{
if
(
subject
->
encoding
!=
REDIS_ENCODING_ZIPLIST
)
return
;
if
(
subject
->
encoding
!=
REDIS_ENCODING_ZIPLIST
)
return
;
if
(
value
->
encoding
==
REDIS_ENCODING_RAW
&&
if
(
value
->
encoding
==
REDIS_ENCODING_RAW
&&
sdslen
(
value
->
ptr
)
>
server
.
list_max_ziplist_value
)
sdslen
(
value
->
ptr
)
>
server
.
list_max_ziplist_value
)
convertLis
t
(
subject
,
REDIS_ENCODING_LIST
);
listTypeConver
t
(
subject
,
REDIS_ENCODING_LIST
);
}
}
static
void
lPush
(
robj
*
subject
,
robj
*
value
,
int
where
)
{
static
void
l
istType
Push
(
robj
*
subject
,
robj
*
value
,
int
where
)
{
/* Check if we need to convert the ziplist */
/* Check if we need to convert the ziplist */
listTryConversion
(
subject
,
value
);
listT
ypeT
ryConversion
(
subject
,
value
);
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
&&
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
&&
ziplistLen
(
subject
->
ptr
)
>
server
.
list_max_ziplist_entries
)
ziplistLen
(
subject
->
ptr
)
>
server
.
list_max_ziplist_entries
)
convertLis
t
(
subject
,
REDIS_ENCODING_LIST
);
listTypeConver
t
(
subject
,
REDIS_ENCODING_LIST
);
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
int
pos
=
(
where
==
REDIS_HEAD
)
?
ZIPLIST_HEAD
:
ZIPLIST_TAIL
;
int
pos
=
(
where
==
REDIS_HEAD
)
?
ZIPLIST_HEAD
:
ZIPLIST_TAIL
;
...
@@ -4941,7 +4941,7 @@ static void lPush(robj *subject, robj *value, int where) {
...
@@ -4941,7 +4941,7 @@ static void lPush(robj *subject, robj *value, int where) {
}
}
}
}
static
robj
*
lPop
(
robj
*
subject
,
int
where
)
{
static
robj
*
l
istType
Pop
(
robj
*
subject
,
int
where
)
{
robj
*
value
=
NULL
;
robj
*
value
=
NULL
;
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
p
;
unsigned
char
*
p
;
...
@@ -4978,7 +4978,7 @@ static robj *lPop(robj *subject, int where) {
...
@@ -4978,7 +4978,7 @@ static robj *lPop(robj *subject, int where) {
return
value
;
return
value
;
}
}
static
unsigned
long
lLength
(
robj
*
subject
)
{
static
unsigned
long
l
istType
Length
(
robj
*
subject
)
{
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
return
ziplistLen
(
subject
->
ptr
);
return
ziplistLen
(
subject
->
ptr
);
}
else
if
(
subject
->
encoding
==
REDIS_ENCODING_LIST
)
{
}
else
if
(
subject
->
encoding
==
REDIS_ENCODING_LIST
)
{
...
@@ -4995,18 +4995,18 @@ typedef struct {
...
@@ -4995,18 +4995,18 @@ typedef struct {
unsigned
char
direction
;
/* Iteration direction */
unsigned
char
direction
;
/* Iteration direction */
unsigned
char
*
zi
;
unsigned
char
*
zi
;
listNode
*
ln
;
listNode
*
ln
;
}
lIterator
;
}
l
istType
Iterator
;
/* Structure for an entry while iterating over a list. */
/* Structure for an entry while iterating over a list. */
typedef
struct
{
typedef
struct
{
lIterator
*
li
;
l
istType
Iterator
*
li
;
unsigned
char
*
zi
;
/* Entry in ziplist */
unsigned
char
*
zi
;
/* Entry in ziplist */
listNode
*
ln
;
/* Entry in linked list */
listNode
*
ln
;
/* Entry in linked list */
}
lEntry
;
}
l
istType
Entry
;
/* Initialize an iterator at the specified index. */
/* Initialize an iterator at the specified index. */
static
l
Iterator
*
l
InitIterator
(
robj
*
subject
,
int
index
,
unsigned
char
direction
)
{
static
l
istTypeIterator
*
listType
InitIterator
(
robj
*
subject
,
int
index
,
unsigned
char
direction
)
{
l
Iterator
*
li
=
zmalloc
(
sizeof
(
l
Iterator
));
l
istTypeIterator
*
li
=
zmalloc
(
sizeof
(
listType
Iterator
));
li
->
subject
=
subject
;
li
->
subject
=
subject
;
li
->
encoding
=
subject
->
encoding
;
li
->
encoding
=
subject
->
encoding
;
li
->
direction
=
direction
;
li
->
direction
=
direction
;
...
@@ -5021,14 +5021,14 @@ static lIterator *lInitIterator(robj *subject, int index, unsigned char directio
...
@@ -5021,14 +5021,14 @@ static lIterator *lInitIterator(robj *subject, int index, unsigned char directio
}
}
/* Clean up the iterator. */
/* Clean up the iterator. */
static
void
l
ReleaseIterator
(
l
Iterator
*
li
)
{
static
void
l
istTypeReleaseIterator
(
listType
Iterator
*
li
)
{
zfree
(
li
);
zfree
(
li
);
}
}
/* Stores pointer to current the entry in the provided entry structure
/* Stores pointer to current the entry in the provided entry structure
* and advances the position of the iterator. Returns 1 when the current
* and advances the position of the iterator. Returns 1 when the current
* entry is in fact an entry, 0 otherwise. */
* entry is in fact an entry, 0 otherwise. */
static
int
l
Next
(
lIterator
*
li
,
l
Entry
*
entry
)
{
static
int
l
istTypeNext
(
listTypeIterator
*
li
,
listType
Entry
*
entry
)
{
entry
->
li
=
li
;
entry
->
li
=
li
;
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
entry
->
zi
=
li
->
zi
;
entry
->
zi
=
li
->
zi
;
...
@@ -5055,8 +5055,8 @@ static int lNext(lIterator *li, lEntry *entry) {
...
@@ -5055,8 +5055,8 @@ static int lNext(lIterator *li, lEntry *entry) {
}
}
/* Return entry or NULL at the current position of the iterator. */
/* Return entry or NULL at the current position of the iterator. */
static
robj
*
l
Get
(
l
Entry
*
entry
)
{
static
robj
*
l
istTypeGet
(
listType
Entry
*
entry
)
{
lIterator
*
li
=
entry
->
li
;
l
istType
Iterator
*
li
=
entry
->
li
;
robj
*
value
=
NULL
;
robj
*
value
=
NULL
;
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
vstr
;
unsigned
char
*
vstr
;
...
@@ -5081,8 +5081,8 @@ static robj *lGet(lEntry *entry) {
...
@@ -5081,8 +5081,8 @@ static robj *lGet(lEntry *entry) {
}
}
/* Compare the given object with the entry at the current position. */
/* Compare the given object with the entry at the current position. */
static
int
l
Equal
(
l
Entry
*
entry
,
robj
*
o
)
{
static
int
l
istTypeEqual
(
listType
Entry
*
entry
,
robj
*
o
)
{
lIterator
*
li
=
entry
->
li
;
l
istType
Iterator
*
li
=
entry
->
li
;
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
redisAssert
(
o
->
encoding
==
REDIS_ENCODING_RAW
);
redisAssert
(
o
->
encoding
==
REDIS_ENCODING_RAW
);
return
ziplistCompare
(
entry
->
zi
,
o
->
ptr
,
sdslen
(
o
->
ptr
));
return
ziplistCompare
(
entry
->
zi
,
o
->
ptr
,
sdslen
(
o
->
ptr
));
...
@@ -5094,8 +5094,8 @@ static int lEqual(lEntry *entry, robj *o) {
...
@@ -5094,8 +5094,8 @@ static int lEqual(lEntry *entry, robj *o) {
}
}
/* Delete the element pointed to. */
/* Delete the element pointed to. */
static
void
l
Delete
(
l
Entry
*
entry
)
{
static
void
l
istTypeDelete
(
listType
Entry
*
entry
)
{
lIterator
*
li
=
entry
->
li
;
l
istType
Iterator
*
li
=
entry
->
li
;
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
li
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
p
=
entry
->
zi
;
unsigned
char
*
p
=
entry
->
zi
;
li
->
subject
->
ptr
=
ziplistDelete
(
li
->
subject
->
ptr
,
&
p
);
li
->
subject
->
ptr
=
ziplistDelete
(
li
->
subject
->
ptr
,
&
p
);
...
@@ -5118,18 +5118,18 @@ static void lDelete(lEntry *entry) {
...
@@ -5118,18 +5118,18 @@ static void lDelete(lEntry *entry) {
}
}
}
}
static
void
convertLis
t
(
robj
*
subject
,
int
enc
)
{
static
void
listTypeConver
t
(
robj
*
subject
,
int
enc
)
{
lIterator
*
li
;
l
istType
Iterator
*
li
;
lEntry
entry
;
l
istType
Entry
entry
;
redisAssert
(
subject
->
type
==
REDIS_LIST
);
redisAssert
(
subject
->
type
==
REDIS_LIST
);
if
(
enc
==
REDIS_ENCODING_LIST
)
{
if
(
enc
==
REDIS_ENCODING_LIST
)
{
list
*
l
=
listCreate
();
list
*
l
=
listCreate
();
/* lGet returns a robj with incremented refcount */
/* l
istType
Get returns a robj with incremented refcount */
li
=
lInitIterator
(
subject
,
0
,
REDIS_TAIL
);
li
=
l
istType
InitIterator
(
subject
,
0
,
REDIS_TAIL
);
while
(
l
Next
(
li
,
&
entry
))
listAddNodeTail
(
l
,
l
Get
(
&
entry
));
while
(
l
istTypeNext
(
li
,
&
entry
))
listAddNodeTail
(
l
,
listType
Get
(
&
entry
));
lReleaseIterator
(
li
);
l
istType
ReleaseIterator
(
li
);
subject
->
encoding
=
REDIS_ENCODING_LIST
;
subject
->
encoding
=
REDIS_ENCODING_LIST
;
zfree
(
subject
->
ptr
);
zfree
(
subject
->
ptr
);
...
@@ -5158,8 +5158,8 @@ static void pushGenericCommand(redisClient *c, int where) {
...
@@ -5158,8 +5158,8 @@ static void pushGenericCommand(redisClient *c, int where) {
return
;
return
;
}
}
}
}
lPush
(
lobj
,
c
->
argv
[
2
],
where
);
l
istType
Push
(
lobj
,
c
->
argv
[
2
],
where
);
addReplyLongLong
(
c
,
lLength
(
lobj
));
addReplyLongLong
(
c
,
l
istType
Length
(
lobj
));
server
.
dirty
++
;
server
.
dirty
++
;
}
}
...
@@ -5174,7 +5174,7 @@ static void rpushCommand(redisClient *c) {
...
@@ -5174,7 +5174,7 @@ static void rpushCommand(redisClient *c) {
static
void
llenCommand
(
redisClient
*
c
)
{
static
void
llenCommand
(
redisClient
*
c
)
{
robj
*
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
);
robj
*
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
);
if
(
o
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
if
(
o
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
addReplyUlong
(
c
,
lLength
(
o
));
addReplyUlong
(
c
,
l
istType
Length
(
o
));
}
}
static
void
lindexCommand
(
redisClient
*
c
)
{
static
void
lindexCommand
(
redisClient
*
c
)
{
...
@@ -5219,7 +5219,7 @@ static void lsetCommand(redisClient *c) {
...
@@ -5219,7 +5219,7 @@ static void lsetCommand(redisClient *c) {
int
index
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
int
index
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
robj
*
value
=
c
->
argv
[
3
];
robj
*
value
=
c
->
argv
[
3
];
listTryConversion
(
o
,
value
);
listT
ypeT
ryConversion
(
o
,
value
);
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
p
,
*
zl
=
o
->
ptr
;
unsigned
char
*
p
,
*
zl
=
o
->
ptr
;
p
=
ziplistIndex
(
zl
,
index
);
p
=
ziplistIndex
(
zl
,
index
);
...
@@ -5253,13 +5253,13 @@ static void popGenericCommand(redisClient *c, int where) {
...
@@ -5253,13 +5253,13 @@ static void popGenericCommand(redisClient *c, int where) {
robj
*
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
);
robj
*
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
);
if
(
o
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
if
(
o
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
robj
*
value
=
lPop
(
o
,
where
);
robj
*
value
=
l
istType
Pop
(
o
,
where
);
if
(
value
==
NULL
)
{
if
(
value
==
NULL
)
{
addReply
(
c
,
shared
.
nullbulk
);
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
}
else
{
addReplyBulk
(
c
,
value
);
addReplyBulk
(
c
,
value
);
decrRefCount
(
value
);
decrRefCount
(
value
);
if
(
lLength
(
o
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
if
(
l
istType
Length
(
o
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
++
;
server
.
dirty
++
;
}
}
}
}
...
@@ -5278,11 +5278,11 @@ static void lrangeCommand(redisClient *c) {
...
@@ -5278,11 +5278,11 @@ static void lrangeCommand(redisClient *c) {
int
end
=
atoi
(
c
->
argv
[
3
]
->
ptr
);
int
end
=
atoi
(
c
->
argv
[
3
]
->
ptr
);
int
llen
;
int
llen
;
int
rangelen
,
j
;
int
rangelen
,
j
;
lEntry
entry
;
l
istType
Entry
entry
;
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptymultibulk
))
==
NULL
if
((
o
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptymultibulk
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
llen
=
lLength
(
o
);
llen
=
l
istType
Length
(
o
);
/* convert negative indexes */
/* convert negative indexes */
if
(
start
<
0
)
start
=
llen
+
start
;
if
(
start
<
0
)
start
=
llen
+
start
;
...
@@ -5301,14 +5301,14 @@ static void lrangeCommand(redisClient *c) {
...
@@ -5301,14 +5301,14 @@ static void lrangeCommand(redisClient *c) {
/* Return the result in form of a multi-bulk reply */
/* Return the result in form of a multi-bulk reply */
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"*%d
\r\n
"
,
rangelen
));
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"*%d
\r\n
"
,
rangelen
));
l
Iterator
*
li
=
l
InitIterator
(
o
,
start
,
REDIS_TAIL
);
l
istTypeIterator
*
li
=
listType
InitIterator
(
o
,
start
,
REDIS_TAIL
);
for
(
j
=
0
;
j
<
rangelen
;
j
++
)
{
for
(
j
=
0
;
j
<
rangelen
;
j
++
)
{
redisAssert
(
lNext
(
li
,
&
entry
));
redisAssert
(
l
istType
Next
(
li
,
&
entry
));
value
=
lGet
(
&
entry
);
value
=
l
istType
Get
(
&
entry
);
addReplyBulk
(
c
,
value
);
addReplyBulk
(
c
,
value
);
decrRefCount
(
value
);
decrRefCount
(
value
);
}
}
lReleaseIterator
(
li
);
l
istType
ReleaseIterator
(
li
);
}
}
static
void
ltrimCommand
(
redisClient
*
c
)
{
static
void
ltrimCommand
(
redisClient
*
c
)
{
...
@@ -5322,7 +5322,7 @@ static void ltrimCommand(redisClient *c) {
...
@@ -5322,7 +5322,7 @@ static void ltrimCommand(redisClient *c) {
if
((
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
ok
))
==
NULL
||
if
((
o
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
ok
))
==
NULL
||
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
checkType
(
c
,
o
,
REDIS_LIST
))
return
;
llen
=
lLength
(
o
);
llen
=
l
istType
Length
(
o
);
/* convert negative indexes */
/* convert negative indexes */
if
(
start
<
0
)
start
=
llen
+
start
;
if
(
start
<
0
)
start
=
llen
+
start
;
...
@@ -5358,7 +5358,7 @@ static void ltrimCommand(redisClient *c) {
...
@@ -5358,7 +5358,7 @@ static void ltrimCommand(redisClient *c) {
}
else
{
}
else
{
redisPanic
(
"Unknown list encoding"
);
redisPanic
(
"Unknown list encoding"
);
}
}
if
(
lLength
(
o
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
if
(
l
istType
Length
(
o
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
++
;
server
.
dirty
++
;
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
}
}
...
@@ -5367,7 +5367,7 @@ static void lremCommand(redisClient *c) {
...
@@ -5367,7 +5367,7 @@ static void lremCommand(redisClient *c) {
robj
*
subject
,
*
obj
=
c
->
argv
[
3
];
robj
*
subject
,
*
obj
=
c
->
argv
[
3
];
int
toremove
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
int
toremove
=
atoi
(
c
->
argv
[
2
]
->
ptr
);
int
removed
=
0
;
int
removed
=
0
;
lEntry
entry
;
l
istType
Entry
entry
;
subject
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
);
subject
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
);
if
(
subject
==
NULL
||
checkType
(
c
,
subject
,
REDIS_LIST
))
return
;
if
(
subject
==
NULL
||
checkType
(
c
,
subject
,
REDIS_LIST
))
return
;
...
@@ -5376,29 +5376,29 @@ static void lremCommand(redisClient *c) {
...
@@ -5376,29 +5376,29 @@ static void lremCommand(redisClient *c) {
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
obj
=
getDecodedObject
(
obj
);
obj
=
getDecodedObject
(
obj
);
lIterator
*
li
;
l
istType
Iterator
*
li
;
if
(
toremove
<
0
)
{
if
(
toremove
<
0
)
{
toremove
=
-
toremove
;
toremove
=
-
toremove
;
li
=
lInitIterator
(
subject
,
-
1
,
REDIS_HEAD
);
li
=
l
istType
InitIterator
(
subject
,
-
1
,
REDIS_HEAD
);
}
else
{
}
else
{
li
=
lInitIterator
(
subject
,
0
,
REDIS_TAIL
);
li
=
l
istType
InitIterator
(
subject
,
0
,
REDIS_TAIL
);
}
}
while
(
lNext
(
li
,
&
entry
))
{
while
(
l
istType
Next
(
li
,
&
entry
))
{
if
(
lEqual
(
&
entry
,
obj
))
{
if
(
l
istType
Equal
(
&
entry
,
obj
))
{
lDelete
(
&
entry
);
l
istType
Delete
(
&
entry
);
server
.
dirty
++
;
server
.
dirty
++
;
removed
++
;
removed
++
;
if
(
toremove
&&
removed
==
toremove
)
break
;
if
(
toremove
&&
removed
==
toremove
)
break
;
}
}
}
}
lReleaseIterator
(
li
);
l
istType
ReleaseIterator
(
li
);
/* Clean up raw encoded object */
/* Clean up raw encoded object */
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
decrRefCount
(
obj
);
decrRefCount
(
obj
);
if
(
lLength
(
subject
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
if
(
l
istType
Length
(
subject
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
":%d
\r\n
"
,
removed
));
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
":%d
\r\n
"
,
removed
));
}
}
...
@@ -5422,12 +5422,12 @@ static void rpoplpushcommand(redisClient *c) {
...
@@ -5422,12 +5422,12 @@ static void rpoplpushcommand(redisClient *c) {
if
((
sobj
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
if
((
sobj
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
sobj
,
REDIS_LIST
))
return
;
checkType
(
c
,
sobj
,
REDIS_LIST
))
return
;
if
(
lLength
(
sobj
)
==
0
)
{
if
(
l
istType
Length
(
sobj
)
==
0
)
{
addReply
(
c
,
shared
.
nullbulk
);
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
}
else
{
robj
*
dobj
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
2
]);
robj
*
dobj
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
2
]);
if
(
dobj
&&
checkType
(
c
,
dobj
,
REDIS_LIST
))
return
;
if
(
dobj
&&
checkType
(
c
,
dobj
,
REDIS_LIST
))
return
;
value
=
lPop
(
sobj
,
REDIS_TAIL
);
value
=
l
istType
Pop
(
sobj
,
REDIS_TAIL
);
/* Add the element to the target list (unless it's directly
/* Add the element to the target list (unless it's directly
* passed to some BLPOP-ing client */
* passed to some BLPOP-ing client */
...
@@ -5437,17 +5437,17 @@ static void rpoplpushcommand(redisClient *c) {
...
@@ -5437,17 +5437,17 @@ static void rpoplpushcommand(redisClient *c) {
dobj
=
createZiplistObject
();
dobj
=
createZiplistObject
();
dbAdd
(
c
->
db
,
c
->
argv
[
2
],
dobj
);
dbAdd
(
c
->
db
,
c
->
argv
[
2
],
dobj
);
}
}
lPush
(
dobj
,
value
,
REDIS_HEAD
);
l
istType
Push
(
dobj
,
value
,
REDIS_HEAD
);
}
}
/* Send the element to the client as reply as well */
/* Send the element to the client as reply as well */
addReplyBulk
(
c
,
value
);
addReplyBulk
(
c
,
value
);
/* lPop returns an object with its refcount incremented */
/* l
istType
Pop returns an object with its refcount incremented */
decrRefCount
(
value
);
decrRefCount
(
value
);
/* Delete the source list when it is empty */
/* Delete the source list when it is empty */
if
(
lLength
(
sobj
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
if
(
l
istType
Length
(
sobj
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
++
;
server
.
dirty
++
;
}
}
}
}
...
@@ -6070,7 +6070,7 @@ static zskiplistNode *zslFirstWithScore(zskiplist *zsl, double score) {
...
@@ -6070,7 +6070,7 @@ static zskiplistNode *zslFirstWithScore(zskiplist *zsl, double score) {
* Returns 0 when the element cannot be found, rank otherwise.
* Returns 0 when the element cannot be found, rank otherwise.
* Note that the rank is 1-based due to the span of zsl->header to the
* Note that the rank is 1-based due to the span of zsl->header to the
* first element. */
* first element. */
static
unsigned
long
zslGetRank
(
zskiplist
*
zsl
,
double
score
,
robj
*
o
)
{
static
unsigned
long
zsl
istType
GetRank
(
zskiplist
*
zsl
,
double
score
,
robj
*
o
)
{
zskiplistNode
*
x
;
zskiplistNode
*
x
;
unsigned
long
rank
=
0
;
unsigned
long
rank
=
0
;
int
i
;
int
i
;
...
@@ -6094,7 +6094,7 @@ static unsigned long zslGetRank(zskiplist *zsl, double score, robj *o) {
...
@@ -6094,7 +6094,7 @@ static unsigned long zslGetRank(zskiplist *zsl, double score, robj *o) {
}
}
/* Finds an element by its rank. The rank argument needs to be 1-based. */
/* Finds an element by its rank. The rank argument needs to be 1-based. */
zskiplistNode
*
zslGetElementByRank
(
zskiplist
*
zsl
,
unsigned
long
rank
)
{
zskiplistNode
*
zsl
istType
GetElementByRank
(
zskiplist
*
zsl
,
unsigned
long
rank
)
{
zskiplistNode
*
x
;
zskiplistNode
*
x
;
unsigned
long
traversed
=
0
;
unsigned
long
traversed
=
0
;
int
i
;
int
i
;
...
@@ -6560,10 +6560,10 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
...
@@ -6560,10 +6560,10 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
/* check if starting point is trivial, before searching
/* check if starting point is trivial, before searching
* the element in log(N) time */
* the element in log(N) time */
if
(
reverse
)
{
if
(
reverse
)
{
ln
=
start
==
0
?
zsl
->
tail
:
zslGetElementByRank
(
zsl
,
llen
-
start
);
ln
=
start
==
0
?
zsl
->
tail
:
zsl
istType
GetElementByRank
(
zsl
,
llen
-
start
);
}
else
{
}
else
{
ln
=
start
==
0
?
ln
=
start
==
0
?
zsl
->
header
->
forward
[
0
]
:
zslGetElementByRank
(
zsl
,
start
+
1
);
zsl
->
header
->
forward
[
0
]
:
zsl
istType
GetElementByRank
(
zsl
,
start
+
1
);
}
}
/* Return the result in form of a multi-bulk reply */
/* Return the result in form of a multi-bulk reply */
...
@@ -6760,7 +6760,7 @@ static void zrankGenericCommand(redisClient *c, int reverse) {
...
@@ -6760,7 +6760,7 @@ static void zrankGenericCommand(redisClient *c, int reverse) {
}
}
score
=
dictGetEntryVal
(
de
);
score
=
dictGetEntryVal
(
de
);
rank
=
zslGetRank
(
zsl
,
*
score
,
c
->
argv
[
2
]);
rank
=
zsl
istType
GetRank
(
zsl
,
*
score
,
c
->
argv
[
2
]);
if
(
rank
)
{
if
(
rank
)
{
if
(
reverse
)
{
if
(
reverse
)
{
addReplyLongLong
(
c
,
zsl
->
length
-
rank
);
addReplyLongLong
(
c
,
zsl
->
length
-
rank
);
...
@@ -7407,7 +7407,7 @@ static void sortCommand(redisClient *c) {
...
@@ -7407,7 +7407,7 @@ static void sortCommand(redisClient *c) {
/* Load the sorting vector with all the objects to sort */
/* Load the sorting vector with all the objects to sort */
switch
(
sortval
->
type
)
{
switch
(
sortval
->
type
)
{
case
REDIS_LIST
:
vectorlen
=
lLength
(
sortval
);
break
;
case
REDIS_LIST
:
vectorlen
=
l
istType
Length
(
sortval
);
break
;
case
REDIS_SET
:
vectorlen
=
dictSize
((
dict
*
)
sortval
->
ptr
);
break
;
case
REDIS_SET
:
vectorlen
=
dictSize
((
dict
*
)
sortval
->
ptr
);
break
;
case
REDIS_ZSET
:
vectorlen
=
dictSize
(((
zset
*
)
sortval
->
ptr
)
->
dict
);
break
;
case
REDIS_ZSET
:
vectorlen
=
dictSize
(((
zset
*
)
sortval
->
ptr
)
->
dict
);
break
;
default:
vectorlen
=
0
;
redisPanic
(
"Bad SORT type"
);
/* Avoid GCC warning */
default:
vectorlen
=
0
;
redisPanic
(
"Bad SORT type"
);
/* Avoid GCC warning */
...
@@ -7416,15 +7416,15 @@ static void sortCommand(redisClient *c) {
...
@@ -7416,15 +7416,15 @@ static void sortCommand(redisClient *c) {
j
=
0
;
j
=
0
;
if
(
sortval
->
type
==
REDIS_LIST
)
{
if
(
sortval
->
type
==
REDIS_LIST
)
{
l
Iterator
*
li
=
l
InitIterator
(
sortval
,
0
,
REDIS_TAIL
);
l
istTypeIterator
*
li
=
listType
InitIterator
(
sortval
,
0
,
REDIS_TAIL
);
lEntry
entry
;
l
istType
Entry
entry
;
while
(
lNext
(
li
,
&
entry
))
{
while
(
l
istType
Next
(
li
,
&
entry
))
{
vector
[
j
].
obj
=
lGet
(
&
entry
);
vector
[
j
].
obj
=
l
istType
Get
(
&
entry
);
vector
[
j
].
u
.
score
=
0
;
vector
[
j
].
u
.
score
=
0
;
vector
[
j
].
u
.
cmpobj
=
NULL
;
vector
[
j
].
u
.
cmpobj
=
NULL
;
j
++
;
j
++
;
}
}
lReleaseIterator
(
li
);
l
istType
ReleaseIterator
(
li
);
}
else
{
}
else
{
dict
*
set
;
dict
*
set
;
dictIterator
*
di
;
dictIterator
*
di
;
...
@@ -7542,7 +7542,7 @@ static void sortCommand(redisClient *c) {
...
@@ -7542,7 +7542,7 @@ static void sortCommand(redisClient *c) {
listIter
li
;
listIter
li
;
if
(
!
getop
)
{
if
(
!
getop
)
{
lPush
(
sobj
,
vector
[
j
].
obj
,
REDIS_TAIL
);
l
istType
Push
(
sobj
,
vector
[
j
].
obj
,
REDIS_TAIL
);
}
else
{
}
else
{
listRewind
(
operations
,
&
li
);
listRewind
(
operations
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
...
@@ -7553,10 +7553,10 @@ static void sortCommand(redisClient *c) {
...
@@ -7553,10 +7553,10 @@ static void sortCommand(redisClient *c) {
if
(
sop
->
type
==
REDIS_SORT_GET
)
{
if
(
sop
->
type
==
REDIS_SORT_GET
)
{
if
(
!
val
)
val
=
createStringObject
(
""
,
0
);
if
(
!
val
)
val
=
createStringObject
(
""
,
0
);
/* lPush does an incrRefCount, so we should take care
/* l
istType
Push does an incrRefCount, so we should take care
* care of the incremented refcount caused by either
* care of the incremented refcount caused by either
* lookupKeyByPattern or createStringObject("",0) */
* lookupKeyByPattern or createStringObject("",0) */
lPush
(
sobj
,
val
,
REDIS_TAIL
);
l
istType
Push
(
sobj
,
val
,
REDIS_TAIL
);
decrRefCount
(
val
);
decrRefCount
(
val
);
}
else
{
}
else
{
/* always fails */
/* always fails */
...
@@ -11075,14 +11075,14 @@ static void computeDatasetDigest(unsigned char *final) {
...
@@ -11075,14 +11075,14 @@ static void computeDatasetDigest(unsigned char *final) {
if
(
o
->
type
==
REDIS_STRING
)
{
if
(
o
->
type
==
REDIS_STRING
)
{
mixObjectDigest
(
digest
,
o
);
mixObjectDigest
(
digest
,
o
);
}
else
if
(
o
->
type
==
REDIS_LIST
)
{
}
else
if
(
o
->
type
==
REDIS_LIST
)
{
l
Iterator
*
li
=
l
InitIterator
(
o
,
0
,
REDIS_TAIL
);
l
istTypeIterator
*
li
=
listType
InitIterator
(
o
,
0
,
REDIS_TAIL
);
lEntry
entry
;
l
istType
Entry
entry
;
while
(
lNext
(
li
,
&
entry
))
{
while
(
l
istType
Next
(
li
,
&
entry
))
{
robj
*
eleobj
=
lGet
(
&
entry
);
robj
*
eleobj
=
l
istType
Get
(
&
entry
);
mixObjectDigest
(
digest
,
eleobj
);
mixObjectDigest
(
digest
,
eleobj
);
decrRefCount
(
eleobj
);
decrRefCount
(
eleobj
);
}
}
lReleaseIterator
(
li
);
l
istType
ReleaseIterator
(
li
);
}
else
if
(
o
->
type
==
REDIS_SET
)
{
}
else
if
(
o
->
type
==
REDIS_SET
)
{
dict
*
set
=
o
->
ptr
;
dict
*
set
=
o
->
ptr
;
dictIterator
*
di
=
dictGetIterator
(
set
);
dictIterator
*
di
=
dictGetIterator
(
set
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录