* 序列化给定key,并返回被序列化的值 * @param[in] key 字符串键 * @param[out] value 序列化后值 * @return 成功rue,失败false * @see * @note */
| 1528 | * @note |
| 1529 | */ |
| 1530 | bool RedisClient::dump(const QString & key, QByteArray & value) { |
| 1531 | _sErrorInfo.clear(); |
| 1532 | if(key.trimmed().isEmpty()) { |
| 1533 | _sErrorInfo = "key is empty"; |
| 1534 | return false; |
| 1535 | } |
| 1536 | |
| 1537 | _vCmdList.clear(); |
| 1538 | _vCmdList.push_back("DUMP"); |
| 1539 | _vCmdList.push_back(key); |
| 1540 | |
| 1541 | _cmdResult = command(_vCmdList); |
| 1542 | if(_cmdResult[0] == '-') { |
| 1543 | if(parseRespError(_cmdResult,_sValue)) |
| 1544 | _sErrorInfo = _sValue; |
| 1545 | else |
| 1546 | _sErrorInfo = "parser resp error info failed"; |
| 1547 | _bRet = false; |
| 1548 | } else if(_cmdResult[0] == '$') { |
| 1549 | if(parseRespBulkString(_cmdResult,value, _iRet)) { |
| 1550 | if(_iRet == -1) { |
| 1551 | _bRet = false; |
| 1552 | _sErrorInfo = "value is nil"; |
| 1553 | } else |
| 1554 | _bRet = true; |
| 1555 | } else { |
| 1556 | _sErrorInfo = "parser resp bulk string info failed"; |
| 1557 | _bRet = false; |
| 1558 | } |
| 1559 | } else { |
| 1560 | _bRet = false; |
| 1561 | _sErrorInfo = QString("parser resp type failed:") + _cmdResult[0]; |
| 1562 | } |
| 1563 | return _bRet; |
| 1564 | } |
| 1565 | |
| 1566 | /** |
| 1567 | * 返回key中字符串值的子字符串,字符串的截取范围由start和stop两个偏移量决定(包括start和stop在内)。 |