コード例 #1
0
ファイル: t_list.c プロジェクト: RealHacker/redis-plus
void listTypeInsert(listTypeEntry *entry, robj *value, int where) {
    if (entry->li->encoding == OBJ_ENCODING_QUICKLIST) {
        value = getDecodedObject(value);
        sds str = value->ptr;
        size_t len = sdslen(str);
        if (where == LIST_TAIL) {
            quicklistInsertAfter((quicklist *)entry->entry.quicklist,
                                 &entry->entry, str, len);
        } else if (where == LIST_HEAD) {
            quicklistInsertBefore((quicklist *)entry->entry.quicklist,
                                  &entry->entry, str, len);
        }
        decrRefCount(value);
    } else {
        serverPanic("Unknown list encoding");
    }
}
コード例 #2
0
//列表类型的插入操作,将value对象插到where
void listTypeInsert(listTypeEntry *entry, robj *value, int where) {
    //对列表对象编码为quicklist类型操作
    if (entry->li->encoding == OBJ_ENCODING_QUICKLIST) {
        value = getDecodedObject(value);    //解码对象vlaue为字符串类型
        sds str = value->ptr;               //获得value对象所保存的值
        size_t len = sdslen(str);           //获得value值的长度
        if (where == LIST_TAIL) {           //给定的where为列表尾部
            //尾插
            quicklistInsertAfter((quicklist *)entry->entry.quicklist,
                                 &entry->entry, str, len);
        } else if (where == LIST_HEAD) {    //给定的where为列表头部
            //头插
            quicklistInsertBefore((quicklist *)entry->entry.quicklist,
                                  &entry->entry, str, len);
        }
        decrRefCount(value);    //引用计数减1,释放value对象
    } else {
        serverPanic("Unknown list encoding");
    }
}