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
485014cc
Commit
485014cc
authored
Sep 05, 2017
by
antirez
Browse files
Streams: RDB saving.
parent
100d43c1
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/rax.c
View file @
485014cc
...
...
@@ -1655,6 +1655,11 @@ int raxEOF(raxIterator *it) {
return
it
->
flags
&
RAX_ITER_EOF
;
}
/* Return the number of elements inside the radix tree. */
uint64_t
raxSize
(
rax
*
rax
)
{
return
rax
->
numele
;
}
/* ----------------------------- Introspection ------------------------------ */
/* This function is mostly used for debugging and learning purposes.
...
...
src/rax.h
View file @
485014cc
...
...
@@ -157,5 +157,6 @@ int raxCompare(raxIterator *iter, const char *op, unsigned char *key, size_t key
void
raxStop
(
raxIterator
*
it
);
int
raxEOF
(
raxIterator
*
it
);
void
raxShow
(
rax
*
rax
);
uint64_t
raxSize
(
rax
*
rax
);
#endif
src/rdb.c
View file @
485014cc
...
...
@@ -31,6 +31,7 @@
#include "lzf.h"
/* LZF compression library */
#include "zipmap.h"
#include "endianconv.h"
#include "stream.h"
#include <math.h>
#include <sys/types.h>
...
...
@@ -622,6 +623,8 @@ int rdbSaveObjectType(rio *rdb, robj *o) {
return
rdbSaveType
(
rdb
,
RDB_TYPE_HASH
);
else
serverPanic
(
"Unknown hash encoding"
);
case
OBJ_STREAM
:
return
rdbSaveType
(
rdb
,
RDB_TYPE_STREAM_LISTPACKS
);
case
OBJ_MODULE
:
return
rdbSaveType
(
rdb
,
RDB_TYPE_MODULE_2
);
default:
...
...
@@ -762,7 +765,26 @@ ssize_t rdbSaveObject(rio *rdb, robj *o) {
}
else
{
serverPanic
(
"Unknown hash encoding"
);
}
}
else
if
(
o
->
type
==
OBJ_STREAM
)
{
/* Store how many listpacks we have inside the radix tree. */
stream
*
s
=
o
->
ptr
;
rax
*
rax
=
s
->
rax
;
if
((
n
=
rdbSaveLen
(
rdb
,
raxSize
(
rax
)))
==
-
1
)
return
-
1
;
nwritten
+=
n
;
/* Serialize all the listpacks inside the radix tree as they are,
* when loading back, we'll use the first entry of each listpack
* to insert it back into the radix tree. */
raxIterator
ri
;
raxStart
(
&
ri
,
rax
);
raxSeek
(
&
ri
,
"^"
,
NULL
,
0
);
while
(
raxNext
(
&
ri
))
{
unsigned
char
*
lp
=
ri
.
data
;
size_t
lp_bytes
=
lpBytes
(
lp
);
if
((
n
=
rdbSaveRawString
(
rdb
,
lp
,
lp_bytes
))
==
-
1
)
return
-
1
;
nwritten
+=
n
;
}
raxStop
(
&
ri
);
}
else
if
(
o
->
type
==
OBJ_MODULE
)
{
/* Save a module-specific value. */
RedisModuleIO
io
;
...
...
src/stream.h
View file @
485014cc
...
...
@@ -2,6 +2,7 @@
#define STREAM_H
#include "rax.h"
#include "listpack.h"
/* Stream item ID: a 128 bit number composed of a milliseconds time and
* a sequence counter. IDs generated in the same millisecond (or in a past
...
...
src/t_stream.c
View file @
485014cc
...
...
@@ -32,7 +32,6 @@
*/
#include "server.h"
#include "listpack.h"
#include "endianconv.h"
#include "stream.h"
...
...
@@ -169,7 +168,6 @@ void streamAppendItem(stream *s, robj **argv, int numfields, streamID *added_id)
s
->
length
++
;
s
->
last_id
=
id
;
if
(
added_id
)
*
added_id
=
id
;
raxShow
(
s
->
rax
);
}
/* Send the specified range to the client 'c'. The range the client will
...
...
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