MCPcopy Create free account
hub / github.com/cc20110101/RedisView / linsert

Method linsert

src/RedisView/RedisLib/RedisClient.cpp:2204–2240  ·  view source on GitHub ↗

* 链表插入数据 * @param[in] key 链表键值 * @param[in] position 链表位置,0是BEFORE,1是AFTER * @param[in] pivot 链表查找元素值 * @param[in] value 链表要插入元素值 * @param[out] llRet 没有pivot为-1,没有key或空链表为0,其他为列表长度 * @return 成功true,失败false * @see * @note */

Source from the content-addressed store, hash-verified

2202 * @note
2203 */
2204bool RedisClient::linsert(const QString & key, const int position, const QString & pivot, const QString & value, qlonglong & llRet) {
2205 _sErrorInfo.clear();
2206 if(key.trimmed().isEmpty()) {
2207 _sErrorInfo = "key is empty";
2208 return false;
2209 }
2210
2211 _vCmdList.clear();
2212 _vCmdList.push_back("LINSERT");
2213 _vCmdList.push_back(key);
2214 if(position)
2215 _vCmdList.push_back("AFTER");
2216 else
2217 _vCmdList.push_back("BEFORE");
2218 _vCmdList.push_back(pivot);
2219 _vCmdList.push_back(value);
2220
2221 _cmdResult = command(_vCmdList);
2222 if(_cmdResult[0] == '-') {
2223 if(parseRespError(_cmdResult,_sValue))
2224 _sErrorInfo = _sValue;
2225 else
2226 _sErrorInfo = "parser resp error info failed";
2227 _bRet = false;
2228 } else if(_cmdResult[0] == ':') {
2229 if(parseRespInteger(_cmdResult,llRet)) {
2230 _bRet = true;
2231 } else {
2232 _sErrorInfo = "parser resp integer info failed";
2233 _bRet = false;
2234 }
2235 } else {
2236 _bRet = false;
2237 _sErrorInfo = QString("parser resp type failed:") + _cmdResult[0];
2238 }
2239 return _bRet;
2240}
2241
2242/**
2243 * 移除并返回列表key的头元素,当key不存在时,返回nil

Callers

nothing calls this directly

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected