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
e12b27ac
Commit
e12b27ac
authored
Mar 09, 2011
by
Pieter Noordhuis
Browse files
Persistence code for encoded sorted sets
parent
d1c920c5
Changes
2
Show whitespace changes
Inline
Side-by-side
src/rdb.c
View file @
e12b27ac
...
...
@@ -302,7 +302,13 @@ int rdbSaveObject(FILE *fp, robj *o) {
redisPanic
(
"Unknown set encoding"
);
}
}
else
if
(
o
->
type
==
REDIS_ZSET
)
{
/* Save a set value */
/* Save a sorted set value */
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
size_t
l
=
ziplistBlobLen
((
unsigned
char
*
)
o
->
ptr
);
if
((
n
=
rdbSaveRawString
(
fp
,
o
->
ptr
,
l
))
==
-
1
)
return
-
1
;
nwritten
+=
n
;
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_RAW
)
{
zset
*
zs
=
o
->
ptr
;
dictIterator
*
di
=
dictGetIterator
(
zs
->
dict
);
dictEntry
*
de
;
...
...
@@ -320,6 +326,9 @@ int rdbSaveObject(FILE *fp, robj *o) {
nwritten
+=
n
;
}
dictReleaseIterator
(
di
);
}
else
{
redisPanic
(
"Unknown sorted set enoding"
);
}
}
else
if
(
o
->
type
==
REDIS_HASH
)
{
/* Save a hash value */
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPMAP
)
{
...
...
@@ -386,6 +395,8 @@ int rdbSaveKeyValuePair(FILE *fp, robj *key, robj *val,
vtype
=
REDIS_LIST_ZIPLIST
;
else
if
(
vtype
==
REDIS_SET
&&
val
->
encoding
==
REDIS_ENCODING_INTSET
)
vtype
=
REDIS_SET_INTSET
;
else
if
(
vtype
==
REDIS_ZSET
&&
val
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
vtype
=
REDIS_ZSET_ZIPLIST
;
/* Save type, key, value */
if
(
rdbSaveType
(
fp
,
vtype
)
==
-
1
)
return
-
1
;
if
(
rdbSaveStringObject
(
fp
,
key
)
==
-
1
)
return
-
1
;
...
...
@@ -811,7 +822,8 @@ robj *rdbLoadObject(int type, FILE *fp) {
}
}
else
if
(
type
==
REDIS_HASH_ZIPMAP
||
type
==
REDIS_LIST_ZIPLIST
||
type
==
REDIS_SET_INTSET
)
type
==
REDIS_SET_INTSET
||
type
==
REDIS_ZSET_ZIPLIST
)
{
robj
*
aux
=
rdbLoadStringObject
(
fp
);
...
...
@@ -846,6 +858,10 @@ robj *rdbLoadObject(int type, FILE *fp) {
if
(
intsetLen
(
o
->
ptr
)
>
server
.
set_max_intset_entries
)
setTypeConvert
(
o
,
REDIS_ENCODING_HT
);
break
;
case
REDIS_ZSET_ZIPLIST
:
o
->
type
=
REDIS_ZSET
;
o
->
encoding
=
REDIS_ENCODING_ZIPLIST
;
break
;
default:
redisPanic
(
"Unknown enoding"
);
break
;
...
...
src/redis.h
View file @
e12b27ac
...
...
@@ -70,10 +70,12 @@
#define REDIS_ZSET 3
#define REDIS_HASH 4
#define REDIS_VMPOINTER 8
/* Object types only used for persistence in .rdb files */
#define REDIS_HASH_ZIPMAP 9
#define REDIS_LIST_ZIPLIST 10
#define REDIS_SET_INTSET 11
#define REDIS_ZSET_ZIPLIST 12
/* Objects encoding. Some kind of objects like Strings and Hashes can be
* internally represented in multiple ways. The 'encoding' field of the object
...
...
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