Commit bd7522b6 authored by zhujiashun's avatar zhujiashun

redis_server_protocol: improve user comment

parent 0c96ecef
......@@ -115,9 +115,13 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
}
const Server* server = static_cast<const Server*>(arg);
if (server) {
RedisService* rs = server->options().redis_service;
if (!rs) {
return MakeParseError(PARSE_ERROR_TRY_OTHERS);
}
ServerContext* ctx = static_cast<ServerContext*>(socket->parsing_context());
if (ctx == NULL) {
RedisConnection* conn = server->options().redis_service->NewConnection();
RedisConnection* conn = rs->NewConnection();
if (!conn) {
LOG(ERROR) << "Fail to new redis connection from redis service";
return MakeParseError(PARSE_ERROR_TRY_OTHERS);
......
......@@ -208,7 +208,22 @@ private:
std::ostream& operator<<(std::ostream& os, const RedisRequest&);
std::ostream& operator<<(std::ostream& os, const RedisResponse&);
class RedisConnection;
// Implement this class and assign an instance to ServerOption.redis_service
// to enable redis support. The return type of NewConnection(), which is
// RedisConnection, should also be implemented by users.
class RedisService {
public:
virtual ~RedisService() {}
virtual RedisConnection* NewConnection() = 0;
};
// Implement this class and make RedisServiceImpl::NewConnection return the
// implemented class. Notice that one TCP connection corresponds to one RedisConnection
// instance, and for the same TCP connection, OnRedisMessage is called sequentially.
// But OnRedisMessage are called concurrently between different TCP connections.
// Read src/brpc/redis_message.h to get the idea how to read and write RedisMessage.
class RedisConnection {
public:
virtual ~RedisConnection() {}
......@@ -216,11 +231,6 @@ public:
RedisMessage* output, butil::Arena* arena) = 0;
};
class RedisService {
public:
virtual ~RedisService() {}
virtual RedisConnection* NewConnection() = 0;
};
} // namespace brpc
......
......@@ -237,7 +237,7 @@ struct ServerOptions {
// Customize parameters of HTTP2, defined in http2.h
H2Settings h2_settings;
// For processing Redis conneections.
// For processing Redis connections. Read src/brpc/redis.h for details.
// Default: NULL (disabled)
RedisService* redis_service;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment