| 414 | } |
| 415 | |
| 416 | void RedisReply::SetArray(int size) { |
| 417 | if (_type != REDIS_REPLY_NIL) { |
| 418 | Reset(); |
| 419 | } |
| 420 | _type = REDIS_REPLY_ARRAY; |
| 421 | if (size < 0) { |
| 422 | LOG(ERROR) << "negative size=" << size << " when calling SetArray"; |
| 423 | return; |
| 424 | } else if (size == 0) { |
| 425 | _length = 0; |
| 426 | return; |
| 427 | } |
| 428 | RedisReply* subs = (RedisReply*)_arena->allocate(sizeof(RedisReply) * size); |
| 429 | if (!subs) { |
| 430 | LOG(FATAL) << "Fail to allocate RedisReply[" << size << "]"; |
| 431 | return; |
| 432 | } |
| 433 | for (int i = 0; i < size; ++i) { |
| 434 | new (&subs[i]) RedisReply(_arena); |
| 435 | } |
| 436 | _length = size; |
| 437 | _data.array.replies = subs; |
| 438 | } |
| 439 | |
| 440 | void RedisReply::SetStringImpl(const butil::StringPiece& str, RedisReplyType type) { |
| 441 | if (_type != REDIS_REPLY_NIL) { |