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
58104d83
Commit
58104d83
authored
Jul 10, 2017
by
Salvatore Sanfilippo
Committed by
GitHub
Jul 10, 2017
Browse files
Merge pull request #4113 from guybe7/module_io_bytes
Modules: Fix io->bytes calculation in RDB save
parents
11182a1a
dfb68cd2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
58104d83
...
@@ -2885,13 +2885,18 @@ void moduleRDBLoadError(RedisModuleIO *io) {
...
@@ -2885,13 +2885,18 @@ void moduleRDBLoadError(RedisModuleIO *io) {
* data types. */
* data types. */
void RM_SaveUnsigned(RedisModuleIO *io, uint64_t value) {
void RM_SaveUnsigned(RedisModuleIO *io, uint64_t value) {
if (io->error) return;
if (io->error) return;
/* Save opcode. */
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_UINT);
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_UINT);
if (retval != -1) rdbSaveLen(io->rio, value);
if (retval == -1) goto saveerr;
if (retval == -1) {
io->bytes += retval;
io->error = 1;
/* Save value. */
} else {
retval = rdbSaveLen(io->rio, value);
io->bytes += retval;
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
/* Load an unsigned 64 bit value from the RDB file. This function should only
...
@@ -2934,26 +2939,36 @@ int64_t RM_LoadSigned(RedisModuleIO *io) {
...
@@ -2934,26 +2939,36 @@ int64_t RM_LoadSigned(RedisModuleIO *io) {
* the RDB file. */
* the RDB file. */
void RM_SaveString(RedisModuleIO *io, RedisModuleString *s) {
void RM_SaveString(RedisModuleIO *io, RedisModuleString *s) {
if (io->error) return;
if (io->error) return;
/* Save opcode. */
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_STRING);
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_STRING);
if (retval != -1) retval = rdbSaveStringObject(io->rio,s);
if (retval == -1) goto saveerr;
if (retval == -1) {
io->bytes += retval;
io->error = 1;
/* Save value. */
} else {
retval = rdbSaveStringObject(io->rio, s);
io->bytes += retval;
if (retval == -1) goto saveerr;
}
io->bytes += retval;
return;
saveerr:
io->error = 1;
}
}
/* Like RedisModule_SaveString() but takes a raw C pointer and length
/* Like RedisModule_SaveString() but takes a raw C pointer and length
* as input. */
* as input. */
void RM_SaveStringBuffer(RedisModuleIO *io, const char *str, size_t len) {
void RM_SaveStringBuffer(RedisModuleIO *io, const char *str, size_t len) {
if (io->error) return;
if (io->error) return;
/* Save opcode. */
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_STRING);
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_STRING);
if (retval != -1) retval = rdbSaveRawString(io->rio,(unsigned char*)str,len);
if (retval == -1) goto saveerr;
if (retval == -1) {
io->bytes += retval;
io->error = 1;
/* Save value. */
} else {
retval = rdbSaveRawString(io->rio, (unsigned char*)str,len);
io->bytes += retval;
if (retval == -1) goto saveerr;
}
io->bytes += retval;
return;
saveerr:
io->error = 1;
}
}
/* Implements RM_LoadString() and RM_LoadStringBuffer() */
/* Implements RM_LoadString() and RM_LoadStringBuffer() */
...
@@ -3001,13 +3016,18 @@ char *RM_LoadStringBuffer(RedisModuleIO *io, size_t *lenptr) {
...
@@ -3001,13 +3016,18 @@ char *RM_LoadStringBuffer(RedisModuleIO *io, size_t *lenptr) {
* It is possible to load back the value with RedisModule_LoadDouble(). */
* It is possible to load back the value with RedisModule_LoadDouble(). */
void RM_SaveDouble(RedisModuleIO *io, double value) {
void RM_SaveDouble(RedisModuleIO *io, double value) {
if (io->error) return;
if (io->error) return;
/* Save opcode. */
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_DOUBLE);
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_DOUBLE);
if (retval != -1) retval = rdbSaveBinaryDoubleValue(io->rio, value);
if (retval == -1) goto saveerr;
if (retval == -1) {
io->bytes += retval;
io->error = 1;
/* Save value. */
} else {
retval = rdbSaveBinaryDoubleValue(io->rio, value);
io->bytes += retval;
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
/* In the context of the rdb_save method of a module data type, loads back the
...
@@ -3032,13 +3052,18 @@ loaderr:
...
@@ -3032,13 +3052,18 @@ loaderr:
* It is possible to load back the value with RedisModule_LoadFloat(). */
* It is possible to load back the value with RedisModule_LoadFloat(). */
void RM_SaveFloat(RedisModuleIO *io, float value) {
void RM_SaveFloat(RedisModuleIO *io, float value) {
if (io->error) return;
if (io->error) return;
/* Save opcode. */
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_FLOAT);
int retval = rdbSaveLen(io->rio, RDB_MODULE_OPCODE_FLOAT);
if (retval != -1) retval = rdbSaveBinaryFloatValue(io->rio, value);
if (retval == -1) goto saveerr;
if (retval == -1) {
io->bytes += retval;
io->error = 1;
/* Save value. */
} else {
retval = rdbSaveBinaryFloatValue(io->rio, value);
io->bytes += retval;
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
/* 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