chenBright commented on code in PR #2902: URL: https://github.com/apache/brpc/pull/2902#discussion_r1976935956
########## example/redis_c++/redis_server.cpp: ########## @@ -91,32 +132,72 @@ class SetCommandHandler : public brpc::RedisCommandHandler { explicit SetCommandHandler(RedisServiceImpl* rsimpl) : _rsimpl(rsimpl) {} - brpc::RedisCommandHandlerResult Run(const std::vector<butil::StringPiece>& args, + brpc::RedisCommandHandlerResult Run(brpc::RedisConnContext* ctx, + const std::vector<butil::StringPiece>& args, brpc::RedisReply* output, bool /*flush_batched*/) override { + AuthSession* session = static_cast<AuthSession*>(ctx->session); + if (session->_user_name.empty()) { + output->FormatError("No user name"); + return brpc::REDIS_CMD_HANDLED; + } if (args.size() != 3ul) { output->FormatError("Expect 2 args for 'set', actually %lu", args.size()-1); return brpc::REDIS_CMD_HANDLED; } const std::string key(args[1].data(), args[1].size()); const std::string value(args[2].data(), args[2].size()); - _rsimpl->Set(key, value); + _rsimpl->Set(session->_user_name, key, value); output->SetStatus("OK"); return brpc::REDIS_CMD_HANDLED; } private: - RedisServiceImpl* _rsimpl; + RedisServiceImpl* _rsimpl; +}; + + + +class AuthCommandHandler : public brpc::RedisCommandHandler { +public: + explicit AuthCommandHandler(RedisServiceImpl* rsimpl) + : _rsimpl(rsimpl) {} + brpc::RedisCommandHandlerResult Run(brpc::RedisConnContext* ctx, + const std::vector<butil::StringPiece>& args, + brpc::RedisReply* output, + bool /*flush_batched*/) override { + if (args.size() != 3ul) { + output->FormatError("Expect 2 args for 'auth', actually %lu", args.size()-1); Review Comment: `args.size()-1` -> `args.size() - 1`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org