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
4b00bebd
Commit
4b00bebd
authored
Feb 04, 2010
by
antirez
Browse files
APPEND command
parent
ed9e4966
Changes
3
Show whitespace changes
Inline
Side-by-side
redis-cli.c
View file @
4b00bebd
...
...
@@ -63,6 +63,7 @@ static struct redisCommand cmdTable[] = {
{
"get"
,
2
,
REDIS_CMD_INLINE
},
{
"set"
,
3
,
REDIS_CMD_BULK
},
{
"setnx"
,
3
,
REDIS_CMD_BULK
},
{
"append"
,
3
,
REDIS_CMD_BULK
},
{
"del"
,
-
2
,
REDIS_CMD_INLINE
},
{
"exists"
,
2
,
REDIS_CMD_INLINE
},
{
"incr"
,
2
,
REDIS_CMD_INLINE
},
...
...
redis.c
View file @
4b00bebd
...
...
@@ -650,6 +650,7 @@ static void multiCommand(redisClient *c);
static void execCommand(redisClient *c);
static void blpopCommand(redisClient *c);
static void brpopCommand(redisClient *c);
static void appendCommand(redisClient *c);
/*================================= Globals ================================= */
...
...
@@ -659,6 +660,7 @@ static struct redisCommand cmdTable[] = {
{"get",getCommand,2,REDIS_CMD_INLINE},
{"set",setCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"setnx",setnxCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"append",appendCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM},
{"del",delCommand,-2,REDIS_CMD_INLINE},
{"exists",existsCommand,2,REDIS_CMD_INLINE},
{"incr",incrCommand,2,REDIS_CMD_INLINE|REDIS_CMD_DENYOOM},
...
...
@@ -3695,6 +3697,52 @@ static void decrbyCommand(redisClient *c) {
incrDecrCommand(c,-incr);
}
static void appendCommand(redisClient *c) {
int retval;
size_t totlen;
robj *o;
o = lookupKeyWrite(c->db,c->argv[1]);
if (o == NULL) {
/* Create the key */
retval = dictAdd(c->db->dict,c->argv[1],c->argv[2]);
incrRefCount(c->argv[1]);
incrRefCount(c->argv[2]);
totlen = stringObjectLen(c->argv[2]);
} else {
dictEntry *de;
de = dictFind(c->db->dict,c->argv[1]);
assert(de != NULL);
o = dictGetEntryVal(de);
if (o->type != REDIS_STRING) {
addReply(c,shared.wrongtypeerr);
return;
}
/* If the object is specially encoded or shared we have to make
* a copy */
if (o->refcount != 1 || o->encoding != REDIS_ENCODING_RAW) {
robj *decoded = getDecodedObject(o);
o = createStringObject(decoded->ptr, sdslen(decoded->ptr));
decrRefCount(decoded);
dictReplace(c->db->dict,c->argv[1],o);
}
/* APPEND! */
if (c->argv[2]->encoding == REDIS_ENCODING_RAW) {
o->ptr = sdscatlen(o->ptr,
c->argv[2]->ptr, sdslen(c->argv[2]->ptr));
} else {
o->ptr = sdscatprintf(o->ptr, "%ld",
(unsigned long) c->argv[2]->ptr);
}
totlen = sdslen(o->ptr);
}
server.dirty++;
addReplySds(c,sdscatprintf(sdsempty(),":%lu\r\n",(unsigned long)totlen));
}
/* ========================= Type agnostic commands ========================= */
static void delCommand(redisClient *c) {
...
...
sds.c
View file @
4b00bebd
...
...
@@ -159,7 +159,7 @@ sds sdscpy(sds s, char *t) {
sds
sdscatprintf
(
sds
s
,
const
char
*
fmt
,
...)
{
va_list
ap
;
char
*
buf
,
*
t
;
size_t
buflen
=
32
;
size_t
buflen
=
16
;
while
(
1
)
{
buf
=
zmalloc
(
buflen
);
...
...
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