阅读setrange命令源码

This commit is contained in:
LingZhaoHui 2020-11-08 21:53:52 +08:00
parent 6322eb58fa
commit a335044204

View File

@ -196,7 +196,9 @@ void getsetCommand(client *c) {
notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[1],c->db->id);
server.dirty++;
}
/**
* setrange命令实现详情
* */
void setrangeCommand(client *c) {
robj *o;
long offset;
@ -247,6 +249,11 @@ void setrangeCommand(client *c) {
}
if (sdslen(value) > 0) {
/**
* value的长度加offset会大于原值长度时
* sdsgrowzero函数sdsgrowzero函数会进行识别offset+sdslen(value)
*
* */
o->ptr = sdsgrowzero(o->ptr,offset+sdslen(value));
memcpy((char*)o->ptr+offset,value,sdslen(value));
signalModifiedKey(c,c->db,c->argv[1]);