| 7 | } |
| 8 | |
| 9 | bool RedisHashModel::GetData( const std::string& key, RedisResult& results ) |
| 10 | { |
| 11 | bool retVal = false; |
| 12 | redisReply* reply = GetClient()->Command("HKEYS %s", key.c_str()); |
| 13 | if (!reply) return retVal; |
| 14 | results.NewColumn("Field "); |
| 15 | results.NewColumn("Value"); |
| 16 | if (reply->type == REDIS_REPLY_ARRAY) |
| 17 | { |
| 18 | std::size_t i = 0; |
| 19 | redisReply* tmpReply ; |
| 20 | bool isOK = true; |
| 21 | while (i < reply->elements) |
| 22 | { |
| 23 | tmpReply = reply->element[i]; |
| 24 | redisReply* theReply = GetClient()->Command("HGET %s %s", key.c_str(), tmpReply->str); |
| 25 | if (!theReply) break; |
| 26 | if (theReply->type != REDIS_REPLY_STRING) |
| 27 | { |
| 28 | isOK = false; |
| 29 | freeReplyObject(theReply); |
| 30 | break; |
| 31 | } |
| 32 | results.NewRow(); |
| 33 | |
| 34 | string& myFiled = results.Value(results.RowSize()-1, 0) ; |
| 35 | myFiled.assign(tmpReply->str, tmpReply->len); |
| 36 | |
| 37 | string& myvalue = results.Value(results.RowSize()-1, 1) ; |
| 38 | myvalue.assign(theReply->str, theReply->len); |
| 39 | freeReplyObject(theReply); |
| 40 | i++; |
| 41 | } |
| 42 | if (isOK) |
| 43 | retVal = true; |
| 44 | } |
| 45 | freeReplyObject(reply); |
| 46 | return retVal; |
| 47 | } |
| 48 | |
| 49 | bool RedisHashModel::UpdateData( const std::string& key, |
| 50 | const std::string& oldValue, |