| 1026 | : _rs(rs) {} |
| 1027 | |
| 1028 | brpc::RedisCommandHandlerResult Run(brpc::RedisConnContext* ctx, |
| 1029 | const std::vector<butil::StringPiece>& args, |
| 1030 | brpc::RedisReply* output, |
| 1031 | bool flush_batched) { |
| 1032 | if (!ctx->session) { |
| 1033 | output->SetError("ERR no auth"); |
| 1034 | return brpc::REDIS_CMD_HANDLED; |
| 1035 | } |
| 1036 | AuthSession* session = static_cast<AuthSession*>(ctx->session); |
| 1037 | if (session->_password != _rs->_password) { |
| 1038 | output->SetError("ERR no auth"); |
| 1039 | return brpc::REDIS_CMD_HANDLED; |
| 1040 | } |
| 1041 | if (args.size() < 2) { |
| 1042 | output->SetError("ERR wrong number of arguments for 'incr' command"); |
| 1043 | return brpc::REDIS_CMD_HANDLED; |
| 1044 | } |
| 1045 | int64_t value; |
| 1046 | s_mutex.lock(); |
| 1047 | value = ++int_map[args[1].as_string()]; |
| 1048 | s_mutex.unlock(); |
| 1049 | output->SetInteger(value); |
| 1050 | return brpc::REDIS_CMD_HANDLED; |
| 1051 | } |
| 1052 | |
| 1053 | private: |
| 1054 | RedisServiceImpl* _rs; |