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

Method spop

src/RedisView/RedisLib/RedisClient.cpp:3228–3262  ·  view source on GitHub ↗

* 移除并返回集合中的一个随机元素,当key不存在或key是空集时,返回nil * @param[in] key 集合键 * @param[out] value 集合随机返回元素 * @return 成功true,失败false * @see * @note */

Source from the content-addressed store, hash-verified

3226 * @note
3227 */
3228bool RedisClient::spop(const QString & key, QByteArray &value) {
3229 _sErrorInfo.clear();
3230 if(key.trimmed().isEmpty()) {
3231 _sErrorInfo = "key is empty";
3232 return false;
3233 }
3234
3235 _vCmdList.clear();
3236 _vCmdList.push_back("SPOP");
3237 _vCmdList.push_back(key);
3238
3239 _cmdResult = command(_vCmdList);
3240 if(_cmdResult[0] == '-') {
3241 if(parseRespError(_cmdResult,_sValue))
3242 _sErrorInfo = _sValue;
3243 else
3244 _sErrorInfo = "parser resp error info failed";
3245 _bRet = false;
3246 } else if(_cmdResult[0] == '$') {
3247 if(parseRespBulkString(_cmdResult,value, _iRet)) {
3248 if(_iRet == -1) {
3249 _bRet = false;
3250 _sErrorInfo = "value is nil";
3251 } else
3252 _bRet = true;
3253 } else {
3254 _sErrorInfo = "parser resp bulk string info failed";
3255 _bRet = false;
3256 }
3257 } else {
3258 _bRet = false;
3259 _sErrorInfo = QString("parser resp type failed:") + _cmdResult[0];
3260 }
3261 return _bRet;
3262}
3263
3264/**
3265 * 将member元素从source集合移动到destination集合

Callers

nothing calls this directly

Calls 1

clearMethod · 0.45

Tested by

no test coverage detected