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
2b59cfdf
Commit
2b59cfdf
authored
Oct 26, 2009
by
antirez
Browse files
ZSET now saved on disk like any other type
parent
a7866db6
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
2b59cfdf
...
...
@@ -379,6 +379,7 @@ static size_t stringObjectLen(robj *o);
static
void
processInputBuffer
(
redisClient
*
c
);
static
zskiplist
*
zslCreate
(
void
);
static
void
zslFree
(
zskiplist
*
zsl
);
static
void
zslInsert
(
zskiplist
*
zsl
,
double
score
,
robj
*
obj
);
static
void
authCommand
(
redisClient
*
c
);
static
void
pingCommand
(
redisClient
*
c
);
...
...
@@ -2352,6 +2353,21 @@ static int rdbSave(char *filename) {
if
(
rdbSaveStringObject
(
fp
,
eleobj
)
==
-
1
)
goto
werr
;
}
dictReleaseIterator
(
di
);
}
else
if
(
o
->
type
==
REDIS_ZSET
)
{
/* Save a set value */
zset
*
zs
=
o
->
ptr
;
dictIterator
*
di
=
dictGetIterator
(
zs
->
dict
);
dictEntry
*
de
;
if
(
rdbSaveLen
(
fp
,
dictSize
(
zs
->
dict
))
==
-
1
)
goto
werr
;
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
robj
*
eleobj
=
dictGetEntryKey
(
de
);
double
*
score
=
dictGetEntryVal
(
de
);
if
(
rdbSaveStringObject
(
fp
,
eleobj
)
==
-
1
)
goto
werr
;
if
(
rdbSaveDoubleValue
(
fp
,
*
score
)
==
-
1
)
goto
werr
;
}
dictReleaseIterator
(
di
);
}
else
{
assert
(
0
!=
0
);
}
...
...
@@ -2631,6 +2647,27 @@ static int rdbLoad(char *filename) {
dictAdd
((
dict
*
)
o
->
ptr
,
ele
,
NULL
);
}
}
}
else
if
(
type
==
REDIS_ZSET
)
{
/* Read list/set value */
uint32_t
zsetlen
;
zset
*
zs
;
if
((
zsetlen
=
rdbLoadLen
(
fp
,
rdbver
,
NULL
))
==
REDIS_RDB_LENERR
)
goto
eoferr
;
o
=
createZsetObject
();
zs
=
o
->
ptr
;
/* Load every single element of the list/set */
while
(
zsetlen
--
)
{
robj
*
ele
;
double
*
score
=
zmalloc
(
sizeof
(
double
));
if
((
ele
=
rdbLoadStringObject
(
fp
,
rdbver
))
==
NULL
)
goto
eoferr
;
tryObjectEncoding
(
ele
);
if
(
rdbLoadDoubleValue
(
fp
,
score
)
==
-
1
)
goto
eoferr
;
dictAdd
(
zs
->
dict
,
ele
,
score
);
zslInsert
(
zs
->
zsl
,
*
score
,
ele
);
incrRefCount
(
ele
);
/* added to skiplist */
}
}
else
{
assert
(
0
!=
0
);
}
...
...
@@ -5114,6 +5151,8 @@ static struct redisFunctionSym symsTable[] = {
{
"zrangeCommand"
,(
unsigned
long
)
zrangeCommand
},
{
"zrevrangeCommand"
,(
unsigned
long
)
zrevrangeCommand
},
{
"zremCommand"
,(
unsigned
long
)
zremCommand
},
{
"rdbSaveDoubleValue"
,(
unsigned
long
)
rdbSaveDoubleValue
},
{
"rdbLoadDoubleValue"
,(
unsigned
long
)
rdbLoadDoubleValue
},
{
NULL
,
0
}
};
...
...
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