Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
8c304be3
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
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,发现更多精彩内容 >>
提交
8c304be3
编写于
12月 14, 2010
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cow friendly HGETALL and variants
上级
5ce3a24d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
22 deletion
+58
-22
src/debug.c
src/debug.c
+2
-2
src/redis.h
src/redis.h
+2
-1
src/t_hash.c
src/t_hash.c
+54
-19
未找到文件。
src/debug.c
浏览文件 @
8c304be3
...
...
@@ -152,10 +152,10 @@ void computeDatasetDigest(unsigned char *final) {
unsigned
char
eledigest
[
20
];
memset
(
eledigest
,
0
,
20
);
obj
=
hashTypeCurrent
(
hi
,
REDIS_HASH_KEY
);
obj
=
hashTypeCurrent
Object
(
hi
,
REDIS_HASH_KEY
);
mixObjectDigest
(
eledigest
,
obj
);
decrRefCount
(
obj
);
obj
=
hashTypeCurrent
(
hi
,
REDIS_HASH_VALUE
);
obj
=
hashTypeCurrent
Object
(
hi
,
REDIS_HASH_VALUE
);
mixObjectDigest
(
eledigest
,
obj
);
decrRefCount
(
obj
);
xorDigest
(
digest
,
eledigest
,
20
);
...
...
src/redis.h
浏览文件 @
8c304be3
...
...
@@ -832,7 +832,8 @@ unsigned long hashTypeLength(robj *o);
hashTypeIterator
*
hashTypeInitIterator
(
robj
*
subject
);
void
hashTypeReleaseIterator
(
hashTypeIterator
*
hi
);
int
hashTypeNext
(
hashTypeIterator
*
hi
);
robj
*
hashTypeCurrent
(
hashTypeIterator
*
hi
,
int
what
);
int
hashTypeCurrent
(
hashTypeIterator
*
hi
,
int
what
,
robj
**
objval
,
unsigned
char
**
v
,
unsigned
int
*
vlen
);
robj
*
hashTypeCurrentObject
(
hashTypeIterator
*
hi
,
int
what
);
robj
*
hashTypeLookupWriteOrCreate
(
redisClient
*
c
,
robj
*
key
);
/* Pub / Sub */
...
...
src/t_hash.c
浏览文件 @
8c304be3
...
...
@@ -185,24 +185,50 @@ int hashTypeNext(hashTypeIterator *hi) {
}
/* Get key or value object at current iteration position.
* This increases the refcount of the field object by 1. */
robj
*
hashTypeCurrent
(
hashTypeIterator
*
hi
,
int
what
)
{
robj
*
o
;
* The returned item differs with the hash object encoding:
* - When encoding is REDIS_ENCODING_HT, the objval pointer is populated
* with the original object.
* - When encoding is REDIS_ENCODING_ZIPMAP, a pointer to the string and
* its length is retunred populating the v and vlen pointers.
* This function is copy on write friendly as accessing objects in read only
* does not require writing to any memory page.
*
* The function returns the encoding of the object, so that the caller
* can underestand if the key or value was returned as object or C string. */
int
hashTypeCurrent
(
hashTypeIterator
*
hi
,
int
what
,
robj
**
objval
,
unsigned
char
**
v
,
unsigned
int
*
vlen
)
{
if
(
hi
->
encoding
==
REDIS_ENCODING_ZIPMAP
)
{
if
(
what
&
REDIS_HASH_KEY
)
{
o
=
createStringObject
((
char
*
)
hi
->
zk
,
hi
->
zklen
);
*
v
=
hi
->
zk
;
*
vlen
=
hi
->
zklen
;
}
else
{
o
=
createStringObject
((
char
*
)
hi
->
zv
,
hi
->
zvlen
);
*
v
=
hi
->
zv
;
*
vlen
=
hi
->
zvlen
;
}
}
else
{
if
(
what
&
REDIS_HASH_KEY
)
{
o
=
dictGetEntryKey
(
hi
->
de
);
}
else
{
o
=
dictGetEntryVal
(
hi
->
de
);
}
incrRefCount
(
o
);
if
(
what
&
REDIS_HASH_KEY
)
*
objval
=
dictGetEntryKey
(
hi
->
de
);
else
*
objval
=
dictGetEntryVal
(
hi
->
de
);
}
return
hi
->
encoding
;
}
/* A non copy-on-write friendly but higher level version of hashTypeCurrent()
* that always returns an object with refcount incremented by one (or a new
* object), so it's up to the caller to decrRefCount() the object if no
* reference is retained. */
robj
*
hashTypeCurrentObject
(
hashTypeIterator
*
hi
,
int
what
)
{
robj
*
obj
;
unsigned
char
*
v
;
unsigned
int
vlen
;
int
encoding
=
hashTypeCurrent
(
hi
,
what
,
&
obj
,
&
v
,
&
vlen
);
if
(
encoding
==
REDIS_ENCODING_HT
)
{
incrRefCount
(
obj
);
return
obj
;
}
else
{
return
createStringObject
((
char
*
)
v
,
vlen
);
}
return
o
;
}
robj
*
hashTypeLookupWriteOrCreate
(
redisClient
*
c
,
robj
*
key
)
{
...
...
@@ -392,7 +418,7 @@ void hlenCommand(redisClient *c) {
}
void
genericHgetallCommand
(
redisClient
*
c
,
int
flags
)
{
robj
*
o
,
*
obj
;
robj
*
o
;
unsigned
long
count
=
0
;
hashTypeIterator
*
hi
;
void
*
replylen
=
NULL
;
...
...
@@ -403,16 +429,25 @@ void genericHgetallCommand(redisClient *c, int flags) {
replylen
=
addDeferredMultiBulkLength
(
c
);
hi
=
hashTypeInitIterator
(
o
);
while
(
hashTypeNext
(
hi
)
!=
REDIS_ERR
)
{
robj
*
obj
;
unsigned
char
*
v
;
unsigned
int
vlen
;
int
encoding
;
if
(
flags
&
REDIS_HASH_KEY
)
{
obj
=
hashTypeCurrent
(
hi
,
REDIS_HASH_KEY
);
addReplyBulk
(
c
,
obj
);
decrRefCount
(
obj
);
encoding
=
hashTypeCurrent
(
hi
,
REDIS_HASH_KEY
,
&
obj
,
&
v
,
&
vlen
);
if
(
encoding
==
REDIS_ENCODING_HT
)
addReplyBulk
(
c
,
obj
);
else
addReplyBulkCBuffer
(
c
,
v
,
vlen
);
count
++
;
}
if
(
flags
&
REDIS_HASH_VALUE
)
{
obj
=
hashTypeCurrent
(
hi
,
REDIS_HASH_VALUE
);
addReplyBulk
(
c
,
obj
);
decrRefCount
(
obj
);
encoding
=
hashTypeCurrent
(
hi
,
REDIS_HASH_VALUE
,
&
obj
,
&
v
,
&
vlen
);
if
(
encoding
==
REDIS_ENCODING_HT
)
addReplyBulk
(
c
,
obj
);
else
addReplyBulkCBuffer
(
c
,
v
,
vlen
);
count
++
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录