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