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
9c8e3cee
Commit
9c8e3cee
authored
Mar 14, 2010
by
antirez
Browse files
Append only file support for hashes
parent
08af4d5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
9c8e3cee
...
@@ -7551,7 +7551,7 @@ fmterr:
...
@@ -7551,7 +7551,7 @@ fmterr:
}
}
/* Write an object into a file in the bulk format $<count>\r\n<payload>\r\n */
/* Write an object into a file in the bulk format $<count>\r\n<payload>\r\n */
static
int
fwriteBulk
(
FILE
*
fp
,
robj
*
obj
)
{
static int fwriteBulk
Object
(FILE *fp, robj *obj) {
char buf[128];
char buf[128];
int decrrc = 0;
int decrrc = 0;
...
@@ -7576,6 +7576,18 @@ err:
...
@@ -7576,6 +7576,18 @@ err:
return 0;
return 0;
}
}
/* Write binary-safe string into a file in the bulkformat
* $<count>\r\n<payload>\r\n */
static int fwriteBulkString(FILE *fp, char *s, unsigned long len) {
char buf[128];
snprintf(buf,sizeof(buf),"$%ld\r\n",(unsigned long)len);
if (fwrite(buf,strlen(buf),1,fp) == 0) return 0;
if (len && fwrite(s,len,1,fp) == 0) return 0;
if (fwrite("\r\n",2,1,fp) == 0) return 0;
return 1;
}
/* Write a double value in bulk format $<count>\r\n<payload>\r\n */
/* Write a double value in bulk format $<count>\r\n<payload>\r\n */
static int fwriteBulkDouble(FILE *fp, double d) {
static int fwriteBulkDouble(FILE *fp, double d) {
char buf[128], dbuf[128];
char buf[128], dbuf[128];
...
@@ -7658,8 +7670,8 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -7658,8 +7670,8 @@ static int rewriteAppendOnlyFile(char *filename) {
char cmd[]="*3\r\n$3\r\nSET\r\n";
char cmd[]="*3\r\n$3\r\nSET\r\n";
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
/* Key and value */
/* Key and value */
if
(
fwriteBulk
(
fp
,
key
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,key) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
o
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,o) == 0) goto werr;
} else if (o->type == REDIS_LIST) {
} else if (o->type == REDIS_LIST) {
/* Emit the RPUSHes needed to rebuild the list */
/* Emit the RPUSHes needed to rebuild the list */
list *list = o->ptr;
list *list = o->ptr;
...
@@ -7672,8 +7684,8 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -7672,8 +7684,8 @@ static int rewriteAppendOnlyFile(char *filename) {
robj *eleobj = listNodeValue(ln);
robj *eleobj = listNodeValue(ln);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
key
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,key) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
eleobj
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,eleobj) == 0) goto werr;
}
}
} else if (o->type == REDIS_SET) {
} else if (o->type == REDIS_SET) {
/* Emit the SADDs needed to rebuild the set */
/* Emit the SADDs needed to rebuild the set */
...
@@ -7686,8 +7698,8 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -7686,8 +7698,8 @@ static int rewriteAppendOnlyFile(char *filename) {
robj *eleobj = dictGetEntryKey(de);
robj *eleobj = dictGetEntryKey(de);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
key
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,key) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
eleobj
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,eleobj) == 0) goto werr;
}
}
dictReleaseIterator(di);
dictReleaseIterator(di);
} else if (o->type == REDIS_ZSET) {
} else if (o->type == REDIS_ZSET) {
...
@@ -7702,11 +7714,43 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -7702,11 +7714,43 @@ static int rewriteAppendOnlyFile(char *filename) {
double *score = dictGetEntryVal(de);
double *score = dictGetEntryVal(de);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
key
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,key) == 0) goto werr;
if (fwriteBulkDouble(fp,*score) == 0) goto werr;
if (fwriteBulkDouble(fp,*score) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
eleobj
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,eleobj) == 0) goto werr;
}
}
dictReleaseIterator(di);
dictReleaseIterator(di);
} else if (o->type == REDIS_HASH) {
char cmd[]="*4\r\n$4\r\nHSET\r\n";
/* Emit the HSETs needed to rebuild the hash */
if (o->encoding == REDIS_ENCODING_ZIPMAP) {
unsigned char *p = zipmapRewind(o->ptr);
unsigned char *field, *val;
unsigned int flen, vlen;
while((p = zipmapNext(p,&field,&flen,&val,&vlen)) != NULL) {
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkObject(fp,key) == 0) goto werr;
if (fwriteBulkString(fp,(char*)field,flen) == -1)
return -1;
if (fwriteBulkString(fp,(char*)val,vlen) == -1)
return -1;
}
} else {
dictIterator *di = dictGetIterator(o->ptr);
dictEntry *de;
while((de = dictNext(di)) != NULL) {
robj *field = dictGetEntryKey(de);
robj *val = dictGetEntryVal(de);
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwriteBulkObject(fp,key) == 0) goto werr;
if (fwriteBulkObject(fp,field) == -1) return -1;
if (fwriteBulkObject(fp,val) == -1) return -1;
}
dictReleaseIterator(di);
}
} else {
} else {
redisAssert(0 != 0);
redisAssert(0 != 0);
}
}
...
@@ -7716,7 +7760,7 @@ static int rewriteAppendOnlyFile(char *filename) {
...
@@ -7716,7 +7760,7 @@ static int rewriteAppendOnlyFile(char *filename) {
/* If this key is already expired skip it */
/* If this key is already expired skip it */
if (expiretime < now) continue;
if (expiretime < now) continue;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if (fwrite(cmd,sizeof(cmd)-1,1,fp) == 0) goto werr;
if
(
fwriteBulk
(
fp
,
key
)
==
0
)
goto
werr
;
if (fwriteBulk
Object
(fp,key) == 0) goto werr;
if (fwriteBulkLong(fp,expiretime) == 0) goto werr;
if (fwriteBulkLong(fp,expiretime) == 0) goto werr;
}
}
if (swapped) decrRefCount(o);
if (swapped) decrRefCount(o);
...
...
staticsymbols.h
View file @
9c8e3cee
...
@@ -24,6 +24,7 @@ static struct redisFunctionSym symsTable[] = {
...
@@ -24,6 +24,7 @@ static struct redisFunctionSym symsTable[] = {
{
"closeTimedoutClients"
,(
unsigned
long
)
closeTimedoutClients
},
{
"closeTimedoutClients"
,(
unsigned
long
)
closeTimedoutClients
},
{
"compareStringObjects"
,(
unsigned
long
)
compareStringObjects
},
{
"compareStringObjects"
,(
unsigned
long
)
compareStringObjects
},
{
"computeObjectSwappability"
,(
unsigned
long
)
computeObjectSwappability
},
{
"computeObjectSwappability"
,(
unsigned
long
)
computeObjectSwappability
},
{
"convertToRealHash"
,(
unsigned
long
)
convertToRealHash
},
{
"createClient"
,(
unsigned
long
)
createClient
},
{
"createClient"
,(
unsigned
long
)
createClient
},
{
"createHashObject"
,(
unsigned
long
)
createHashObject
},
{
"createHashObject"
,(
unsigned
long
)
createHashObject
},
{
"createListObject"
,(
unsigned
long
)
createListObject
},
{
"createListObject"
,(
unsigned
long
)
createListObject
},
...
@@ -75,9 +76,10 @@ static struct redisFunctionSym symsTable[] = {
...
@@ -75,9 +76,10 @@ static struct redisFunctionSym symsTable[] = {
{
"freeSetObject"
,(
unsigned
long
)
freeSetObject
},
{
"freeSetObject"
,(
unsigned
long
)
freeSetObject
},
{
"freeStringObject"
,(
unsigned
long
)
freeStringObject
},
{
"freeStringObject"
,(
unsigned
long
)
freeStringObject
},
{
"freeZsetObject"
,(
unsigned
long
)
freeZsetObject
},
{
"freeZsetObject"
,(
unsigned
long
)
freeZsetObject
},
{
"fwriteBulk"
,(
unsigned
long
)
fwriteBulk
},
{
"fwriteBulkDouble"
,(
unsigned
long
)
fwriteBulkDouble
},
{
"fwriteBulkDouble"
,(
unsigned
long
)
fwriteBulkDouble
},
{
"fwriteBulkLong"
,(
unsigned
long
)
fwriteBulkLong
},
{
"fwriteBulkLong"
,(
unsigned
long
)
fwriteBulkLong
},
{
"fwriteBulkObject"
,(
unsigned
long
)
fwriteBulkObject
},
{
"fwriteBulkString"
,(
unsigned
long
)
fwriteBulkString
},
{
"genRedisInfoString"
,(
unsigned
long
)
genRedisInfoString
},
{
"genRedisInfoString"
,(
unsigned
long
)
genRedisInfoString
},
{
"genericZrangebyscoreCommand"
,(
unsigned
long
)
genericZrangebyscoreCommand
},
{
"genericZrangebyscoreCommand"
,(
unsigned
long
)
genericZrangebyscoreCommand
},
{
"getCommand"
,(
unsigned
long
)
getCommand
},
{
"getCommand"
,(
unsigned
long
)
getCommand
},
...
@@ -131,6 +133,7 @@ static struct redisFunctionSym symsTable[] = {
...
@@ -131,6 +133,7 @@ static struct redisFunctionSym symsTable[] = {
{
"processInputBuffer"
,(
unsigned
long
)
processInputBuffer
},
{
"processInputBuffer"
,(
unsigned
long
)
processInputBuffer
},
{
"pushGenericCommand"
,(
unsigned
long
)
pushGenericCommand
},
{
"pushGenericCommand"
,(
unsigned
long
)
pushGenericCommand
},
{
"qsortCompareSetsByCardinality"
,(
unsigned
long
)
qsortCompareSetsByCardinality
},
{
"qsortCompareSetsByCardinality"
,(
unsigned
long
)
qsortCompareSetsByCardinality
},
{
"qsortCompareZsetopsrcByCardinality"
,(
unsigned
long
)
qsortCompareZsetopsrcByCardinality
},
{
"queueIOJob"
,(
unsigned
long
)
queueIOJob
},
{
"queueIOJob"
,(
unsigned
long
)
queueIOJob
},
{
"queueMultiCommand"
,(
unsigned
long
)
queueMultiCommand
},
{
"queueMultiCommand"
,(
unsigned
long
)
queueMultiCommand
},
{
"randomkeyCommand"
,(
unsigned
long
)
randomkeyCommand
},
{
"randomkeyCommand"
,(
unsigned
long
)
randomkeyCommand
},
...
@@ -250,13 +253,17 @@ static struct redisFunctionSym symsTable[] = {
...
@@ -250,13 +253,17 @@ static struct redisFunctionSym symsTable[] = {
{
"zcardCommand"
,(
unsigned
long
)
zcardCommand
},
{
"zcardCommand"
,(
unsigned
long
)
zcardCommand
},
{
"zcountCommand"
,(
unsigned
long
)
zcountCommand
},
{
"zcountCommand"
,(
unsigned
long
)
zcountCommand
},
{
"zincrbyCommand"
,(
unsigned
long
)
zincrbyCommand
},
{
"zincrbyCommand"
,(
unsigned
long
)
zincrbyCommand
},
{
"zinterCommand"
,(
unsigned
long
)
zinterCommand
},
{
"zrangeCommand"
,(
unsigned
long
)
zrangeCommand
},
{
"zrangeCommand"
,(
unsigned
long
)
zrangeCommand
},
{
"zrangeGenericCommand"
,(
unsigned
long
)
zrangeGenericCommand
},
{
"zrangeGenericCommand"
,(
unsigned
long
)
zrangeGenericCommand
},
{
"zrangebyscoreCommand"
,(
unsigned
long
)
zrangebyscoreCommand
},
{
"zrangebyscoreCommand"
,(
unsigned
long
)
zrangebyscoreCommand
},
{
"zrankCommand"
,(
unsigned
long
)
zrankCommand
},
{
"zrankCommand"
,(
unsigned
long
)
zrankCommand
},
{
"zrankGenericCommand"
,(
unsigned
long
)
zrankGenericCommand
},
{
"zremCommand"
,(
unsigned
long
)
zremCommand
},
{
"zremCommand"
,(
unsigned
long
)
zremCommand
},
{
"zremrangebyrankCommand"
,(
unsigned
long
)
zremrangebyrankCommand
},
{
"zremrangebyscoreCommand"
,(
unsigned
long
)
zremrangebyscoreCommand
},
{
"zremrangebyscoreCommand"
,(
unsigned
long
)
zremrangebyscoreCommand
},
{
"zrevrangeCommand"
,(
unsigned
long
)
zrevrangeCommand
},
{
"zrevrangeCommand"
,(
unsigned
long
)
zrevrangeCommand
},
{
"zrevrankCommand"
,(
unsigned
long
)
zrevrankCommand
},
{
"zscoreCommand"
,(
unsigned
long
)
zscoreCommand
},
{
"zscoreCommand"
,(
unsigned
long
)
zscoreCommand
},
{
"zslCreate"
,(
unsigned
long
)
zslCreate
},
{
"zslCreate"
,(
unsigned
long
)
zslCreate
},
{
"zslCreateNode"
,(
unsigned
long
)
zslCreateNode
},
{
"zslCreateNode"
,(
unsigned
long
)
zslCreateNode
},
...
@@ -266,5 +273,7 @@ static struct redisFunctionSym symsTable[] = {
...
@@ -266,5 +273,7 @@ static struct redisFunctionSym symsTable[] = {
{
"zslFreeNode"
,(
unsigned
long
)
zslFreeNode
},
{
"zslFreeNode"
,(
unsigned
long
)
zslFreeNode
},
{
"zslInsert"
,(
unsigned
long
)
zslInsert
},
{
"zslInsert"
,(
unsigned
long
)
zslInsert
},
{
"zslRandomLevel"
,(
unsigned
long
)
zslRandomLevel
},
{
"zslRandomLevel"
,(
unsigned
long
)
zslRandomLevel
},
{
"zunionCommand"
,(
unsigned
long
)
zunionCommand
},
{
"zunionInterGenericCommand"
,(
unsigned
long
)
zunionInterGenericCommand
},
{
NULL
,
0
}
{
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