mirror of
https://github.com/fluencelabs/redis
synced 2025-05-23 15:41:20 +00:00
rioInitWithFile nad rioInitWithBuffer functions now take a rio structure pointer to avoid copying a structure to return value to the caller.
This commit is contained in:
parent
69cecb511f
commit
f96a8a8054
@ -421,7 +421,7 @@ int rewriteAppendOnlyFile(char *filename) {
|
|||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
aof = rioInitWithFile(fp);
|
rioInitWithFile(&aof,fp);
|
||||||
for (j = 0; j < server.dbnum; j++) {
|
for (j = 0; j < server.dbnum; j++) {
|
||||||
char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n";
|
char selectcmd[] = "*2\r\n$6\r\nSELECT\r\n";
|
||||||
redisDb *db = server.db+j;
|
redisDb *db = server.db+j;
|
||||||
|
@ -1402,7 +1402,7 @@ void restoreCommand(redisClient *c) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = rioInitWithBuffer(c->argv[3]->ptr);
|
rioInitWithBuffer(&payload,c->argv[3]->ptr);
|
||||||
if (((type = rdbLoadObjectType(&payload)) == -1) ||
|
if (((type = rdbLoadObjectType(&payload)) == -1) ||
|
||||||
((obj = rdbLoadObject(type,&payload)) == NULL))
|
((obj = rdbLoadObject(type,&payload)) == NULL))
|
||||||
{
|
{
|
||||||
@ -1453,7 +1453,7 @@ void migrateCommand(redisClient *c) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = rioInitWithBuffer(sdsempty());
|
rioInitWithBuffer(&cmd,sdsempty());
|
||||||
redisAssert(rioWriteBulkCount(&cmd,'*',2));
|
redisAssert(rioWriteBulkCount(&cmd,'*',2));
|
||||||
redisAssert(rioWriteBulkString(&cmd,"SELECT",6));
|
redisAssert(rioWriteBulkString(&cmd,"SELECT",6));
|
||||||
redisAssert(rioWriteBulkLongLong(&cmd,dbid));
|
redisAssert(rioWriteBulkLongLong(&cmd,dbid));
|
||||||
@ -1467,7 +1467,7 @@ void migrateCommand(redisClient *c) {
|
|||||||
|
|
||||||
/* Finally the last argument that is the serailized object payload
|
/* Finally the last argument that is the serailized object payload
|
||||||
* in the form: <type><rdb-serialized-object>. */
|
* in the form: <type><rdb-serialized-object>. */
|
||||||
payload = rioInitWithBuffer(sdsempty());
|
rioInitWithBuffer(&payload,sdsempty());
|
||||||
redisAssert(rdbSaveObjectType(&payload,o));
|
redisAssert(rdbSaveObjectType(&payload,o));
|
||||||
redisAssert(rdbSaveObject(&payload,o) != -1);
|
redisAssert(rdbSaveObject(&payload,o) != -1);
|
||||||
redisAssert(rioWriteBulkString(&cmd,payload.io.buffer.ptr,sdslen(payload.io.buffer.ptr)));
|
redisAssert(rioWriteBulkString(&cmd,payload.io.buffer.ptr,sdslen(payload.io.buffer.ptr)));
|
||||||
@ -1544,7 +1544,7 @@ void dumpCommand(redisClient *c) {
|
|||||||
|
|
||||||
/* Serialize the object in a RDB-like format. It consist of an object type
|
/* Serialize the object in a RDB-like format. It consist of an object type
|
||||||
* byte followed by the serialized object. This is understood by RESTORE. */
|
* byte followed by the serialized object. This is understood by RESTORE. */
|
||||||
payload = rioInitWithBuffer(sdsempty());
|
rioInitWithBuffer(&payload,sdsempty());
|
||||||
redisAssert(rdbSaveObjectType(&payload,o));
|
redisAssert(rdbSaveObjectType(&payload,o));
|
||||||
redisAssert(rdbSaveObject(&payload,o));
|
redisAssert(rdbSaveObject(&payload,o));
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ int rdbSave(char *filename) {
|
|||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdb = rioInitWithFile(fp);
|
rioInitWithFile(&rdb,fp);
|
||||||
if (rdbWriteRaw(&rdb,"REDIS0002",9) == -1) goto werr;
|
if (rdbWriteRaw(&rdb,"REDIS0002",9) == -1) goto werr;
|
||||||
|
|
||||||
for (j = 0; j < server.dbnum; j++) {
|
for (j = 0; j < server.dbnum; j++) {
|
||||||
@ -948,7 +948,7 @@ int rdbLoad(char *filename) {
|
|||||||
|
|
||||||
fp = fopen(filename,"r");
|
fp = fopen(filename,"r");
|
||||||
if (!fp) return REDIS_ERR;
|
if (!fp) return REDIS_ERR;
|
||||||
rdb = rioInitWithFile(fp);
|
rioInitWithFile(&rdb,fp);
|
||||||
if (rioRead(&rdb,buf,9) == 0) goto eoferr;
|
if (rioRead(&rdb,buf,9) == 0) goto eoferr;
|
||||||
buf[9] = '\0';
|
buf[9] = '\0';
|
||||||
if (memcmp(buf,"REDIS",5) != 0) {
|
if (memcmp(buf,"REDIS",5) != 0) {
|
||||||
|
17
src/rio.c
17
src/rio.c
@ -52,16 +52,15 @@ static const rio rioFileIO = {
|
|||||||
{ { NULL, 0 } } /* union for io-specific vars */
|
{ { NULL, 0 } } /* union for io-specific vars */
|
||||||
};
|
};
|
||||||
|
|
||||||
rio rioInitWithFile(FILE *fp) {
|
void rioInitWithFile(rio *r, FILE *fp) {
|
||||||
rio r = rioFileIO;
|
*r = rioFileIO;
|
||||||
r.io.file.fp = fp;
|
r->io.file.fp = fp;
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
rio rioInitWithBuffer(sds s) {
|
|
||||||
rio r = rioBufferIO;
|
void rioInitWithBuffer(rio *r, sds s) {
|
||||||
r.io.buffer.ptr = s;
|
*r = rioBufferIO;
|
||||||
r.io.buffer.pos = 0;
|
r->io.buffer.ptr = s;
|
||||||
return r;
|
r->io.buffer.pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write multi bulk count in the format: "*<count>\r\n". */
|
/* Write multi bulk count in the format: "*<count>\r\n". */
|
||||||
|
@ -29,8 +29,8 @@ typedef struct _rio rio;
|
|||||||
#define rioWrite(rio,buf,len) ((rio)->write((rio),(buf),(len)))
|
#define rioWrite(rio,buf,len) ((rio)->write((rio),(buf),(len)))
|
||||||
#define rioRead(rio,buf,len) ((rio)->read((rio),(buf),(len)))
|
#define rioRead(rio,buf,len) ((rio)->read((rio),(buf),(len)))
|
||||||
|
|
||||||
rio rioInitWithFile(FILE *fp);
|
void rioInitWithFile(rio *r, FILE *fp);
|
||||||
rio rioInitWithBuffer(sds s);
|
void rioInitWithBuffer(rio *r, sds s);
|
||||||
|
|
||||||
size_t rioWriteBulkCount(rio *r, char prefix, int count);
|
size_t rioWriteBulkCount(rio *r, char prefix, int count);
|
||||||
size_t rioWriteBulkString(rio *r, const char *buf, size_t len);
|
size_t rioWriteBulkString(rio *r, const char *buf, size_t len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user