Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
99bb1c74
Commit
99bb1c74
authored
Jul 10, 2017
by
Guy Benoish
Committed by
antirez
Jul 14, 2017
Browse files
Modules: Fix io->bytes calculation in RDB save
parent
cfdcd440
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
99bb1c74
...
...
@@ -2885,13 +2885,18 @@ void moduleRDBLoadError(RedisModuleIO *io) {
* data types. */
void
RM_SaveUnsigned
(
RedisModuleIO
*
io
,
uint64_t
value
)
{
if
(
io
->
error
)
return
;
/* Save opcode. */
int
retval
=
rdbSaveLen
(
io
->
rio
,
RDB_MODULE_OPCODE_UINT
);
if
(
retval
!=
-
1
)
rdbSaveLen
(
io
->
rio
,
value
);
if
(
retval
==
-
1
)
{
io
->
error
=
1
;
}
else
{
io
->
bytes
+=
retval
;
}
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
/* Save value. */
retval
=
rdbSaveLen
(
io
->
rio
,
value
);
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
return
;
saveerr:
io
->
error
=
1
;
}
/* Load an unsigned 64 bit value from the RDB file. This function should only
...
...
@@ -2934,26 +2939,36 @@ int64_t RM_LoadSigned(RedisModuleIO *io) {
* the RDB file. */
void
RM_SaveString
(
RedisModuleIO
*
io
,
RedisModuleString
*
s
)
{
if
(
io
->
error
)
return
;
/* Save opcode. */
int
retval
=
rdbSaveLen
(
io
->
rio
,
RDB_MODULE_OPCODE_STRING
);
if
(
retval
!=
-
1
)
retval
=
rdbSaveStringObject
(
io
->
rio
,
s
);
if
(
retval
==
-
1
)
{
io
->
error
=
1
;
}
else
{
io
->
bytes
+=
retval
;
}
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
/* Save value. */
retval
=
rdbSaveStringObject
(
io
->
rio
,
s
);
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
return
;
saveerr:
io
->
error
=
1
;
}
/* Like RedisModule_SaveString() but takes a raw C pointer and length
* as input. */
void
RM_SaveStringBuffer
(
RedisModuleIO
*
io
,
const
char
*
str
,
size_t
len
)
{
if
(
io
->
error
)
return
;
/* Save opcode. */
int
retval
=
rdbSaveLen
(
io
->
rio
,
RDB_MODULE_OPCODE_STRING
);
if
(
retval
!=
-
1
)
retval
=
rdbSaveRawString
(
io
->
rio
,(
unsigned
char
*
)
str
,
len
);
if
(
retval
==
-
1
)
{
io
->
error
=
1
;
}
else
{
io
->
bytes
+=
retval
;
}
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
/* Save value. */
retval
=
rdbSaveRawString
(
io
->
rio
,
(
unsigned
char
*
)
str
,
len
);
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
return
;
saveerr:
io
->
error
=
1
;
}
/* Implements RM_LoadString() and RM_LoadStringBuffer() */
...
...
@@ -3001,13 +3016,18 @@ char *RM_LoadStringBuffer(RedisModuleIO *io, size_t *lenptr) {
* It is possible to load back the value with RedisModule_LoadDouble(). */
void
RM_SaveDouble
(
RedisModuleIO
*
io
,
double
value
)
{
if
(
io
->
error
)
return
;
/* Save opcode. */
int
retval
=
rdbSaveLen
(
io
->
rio
,
RDB_MODULE_OPCODE_DOUBLE
);
if
(
retval
!=
-
1
)
retval
=
rdbSaveBinaryDoubleValue
(
io
->
rio
,
value
);
if
(
retval
==
-
1
)
{
io
->
error
=
1
;
}
else
{
io
->
bytes
+=
retval
;
}
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
/* Save value. */
retval
=
rdbSaveBinaryDoubleValue
(
io
->
rio
,
value
);
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
return
;
saveerr:
io
->
error
=
1
;
}
/* In the context of the rdb_save method of a module data type, loads back the
...
...
@@ -3032,13 +3052,18 @@ loaderr:
* It is possible to load back the value with RedisModule_LoadFloat(). */
void
RM_SaveFloat
(
RedisModuleIO
*
io
,
float
value
)
{
if
(
io
->
error
)
return
;
/* Save opcode. */
int
retval
=
rdbSaveLen
(
io
->
rio
,
RDB_MODULE_OPCODE_FLOAT
);
if
(
retval
!=
-
1
)
retval
=
rdbSaveBinaryFloatValue
(
io
->
rio
,
value
);
if
(
retval
==
-
1
)
{
io
->
error
=
1
;
}
else
{
io
->
bytes
+=
retval
;
}
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
/* Save value. */
retval
=
rdbSaveBinaryFloatValue
(
io
->
rio
,
value
);
if
(
retval
==
-
1
)
goto
saveerr
;
io
->
bytes
+=
retval
;
return
;
saveerr:
io
->
error
=
1
;
}
/* In the context of the rdb_save method of a module data type, loads back the
...
...
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