acl  3.5.3.0
acl::redis_pubsub类 参考

#include <redis_pubsub.hpp>

+ 类 acl::redis_pubsub 继承关系图:
+ acl::redis_pubsub 的协作图:

Public 成员函数

 redis_pubsub (void)
 
 redis_pubsub (redis_client *conn)
 
 redis_pubsub (redis_client_cluster *cluster)
 
ACL_CPP_DEPRECATED redis_pubsub (redis_client_cluster *cluster, size_t max_conns)
 
 redis_pubsub (redis_client_pipeline *pipeline)
 
virtual ~redis_pubsub (void)
 
int publish (const char *channel, const char *msg, size_t len)
 
int subscribe (const char *first_channel,...)
 
int subscribe (const std::vector< const char * > &channels)
 
int subscribe (const std::vector< string > &channels)
 
int unsubscribe (const char *first_channel,...)
 
int unsubscribe (const std::vector< const char * > &channels)
 
int unsubscribe (const std::vector< string > &channels)
 
int psubscribe (const char *first_pattern,...)
 
int psubscribe (const std::vector< const char * > &patterns)
 
int psubscribe (const std::vector< string > &patterns)
 
int punsubscribe (const char *first_pattern,...)
 
int punsubscribe (const std::vector< const char * > &patterns)
 
int punsubscribe (const std::vector< string > &patterns)
 
bool get_message (string &channel, string &msg, string *message_type=NULL, string *pattern=NULL, int timeout=-1)
 
int pubsub_channels (std::vector< string > *channels, const char *first_pattern,...)
 
int pubsub_channels (const std::vector< const char * > &patterns, std::vector< string > *channels)
 
int pubsub_channels (const std::vector< string > &patterns, std::vector< string > *channels)
 
int pubsub_numsub (std::map< string, int > &out, const char *first_channel,...)
 
int pubsub_numsub (const std::vector< const char * > &channels, std::map< string, int > &out)
 
int pubsub_numsub (const std::vector< string > &channels, std::map< string, int > &out)
 
int pubsub_numpat ()
 
- Public 成员函数 继承自 acl::redis_command
 redis_command (void)
 
 redis_command (redis_client *conn)
 
 redis_command (redis_client_cluster *cluster)
 
ACL_CPP_DEPRECATED redis_command (redis_client_cluster *cluster, size_t max_conns)
 
 redis_command (redis_client_pipeline *pipeline)
 
virtual ~redis_command (void)
 
void set_check_addr (bool on)
 
void clear (bool save_slot=false)
 
void reset (bool save_slot=false)
 
void set_client (redis_client *conn)
 
redis_clientget_client (void) const
 
const char * get_client_addr (void) const
 
void set_cluster (redis_client_cluster *cluster)
 
ACL_CPP_DEPRECATED void set_cluster (redis_client_cluster *cluster, size_t max_conns)
 
redis_client_clusterget_cluster (void) const
 
void set_pipeline (redis_client_pipeline *pipeline, bool use_mbox=true)
 
redis_client_pipelineget_pipeline (void) const
 
dbuf_poolget_dbuf (void) const
 
redis_result_t result_type (void) const
 
const char * result_status (void) const
 
const char * result_error (void) const
 
size_t result_size (void) const
 
int result_number (bool *success=NULL) const
 
long long int result_number64 (bool *success=NULL) const
 
const char * get_result (size_t i, size_t *len=NULL) const
 
bool eof (void) const
 
const redis_resultget_result (void) const
 
const redis_resultresult_child (size_t i) const
 
const char * result_value (size_t i, size_t *len=NULL) const
 
void set_slice_request (bool on)
 
void set_slice_respond (bool on)
 
const redis_resultrequest (size_t argc, const char *argv[], size_t lens[], size_t nchild=0)
 
const redis_resultrequest (const std::vector< string > &args, size_t nchild=0)
 
const stringrequest_buf (void) const
 
void build_request (size_t argc, const char *argv[], size_t lens[])
 
void hash_slot (const char *key)
 
void hash_slot (const char *key, size_t len)
 
int get_slot (void) const
 
bool is_check_addr (void) const
 
const char * get_addr (const char *info)
 
void set_client_addr (const char *addr)
 
void set_client_addr (redis_client &conn)
 
redis_request * get_request_obj (void) const
 
stringget_request_buf (void) const
 
bool is_slice_req (void) const
 
redis_pipeline_messageget_pipeline_message (void)
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 acl::redis_command
static void build_request (size_t argc, const char *argv[], size_t lens[], string &out)
 
- Protected 成员函数 继承自 acl::redis_command
const redis_resultrun (size_t nchild=0, int *timeout=NULL)
 
void clear_request (void)
 
const redis_result ** scan_keys (const char *cmd, const char *key, int &cursor, size_t &size, const char *pattern, const size_t *count)
 
const redis_result ** scan_keys (const char *cmd, const char *key, size_t klen, int &cursor, size_t &size, const char *pattern, const size_t *count)
 
void build (const char *cmd, const char *key, const std::map< string, string > &attrs)
 
void build (const char *cmd, const char *key, size_t klen, const std::map< string, string > &attrs)
 
void build (const char *cmd, const char *key, const std::map< string, const char * > &attrs)
 
void build (const char *cmd, const char *key, const std::vector< string > &names, const std::vector< string > &values)
 
void build (const char *cmd, const char *key, size_t klen, const std::vector< string > &names, const std::vector< string > &values)
 
void build (const char *cmd, const char *key, const std::vector< const char * > &names, const std::vector< const char * > &values)
 
void build (const char *cmd, const char *key, const char *names[], const char *values[], size_t argc)
 
void build (const char *cmd, const char *key, const int names[], const char *values[], size_t argc)
 
void build (const char *cmd, const char *key, const char *names[], const size_t names_len[], const char *values[], const size_t values_len[], size_t argc)
 
void build (const char *cmd, const char *key, size_t klen, const char *names[], const size_t names_len[], const char *values[], const size_t values_len[], size_t argc)
 
void build (const char *cmd, const char *key, const std::vector< string > &names)
 
void build (const char *cmd, const char *key, size_t klen, const std::vector< string > &names)
 
void build (const char *cmd, const char *key, const std::vector< const char * > &names)
 
void build (const char *cmd, const char *key, const std::vector< int > &names)
 
void build (const char *cmd, const char *key, const char *names[], size_t argc)
 
void build (const char *cmd, const char *key, const char *names[], const size_t lens[], size_t argc)
 
void build (const char *cmd, const char *key, size_t klen, const char *names[], const size_t lens[], size_t argc)
 
void build (const char *cmd, const char *key, const int names[], size_t argc)
 
int get_number (bool *success=NULL)
 
long long int get_number64 (bool *success=NULL)
 
int get_number (std::vector< int > &out)
 
int get_number64 (std::vector< long long int > &out)
 
bool check_status (const char *success="OK")
 
int get_status (std::vector< bool > &out)
 
const char * get_status (void)
 
int get_string (string &buf)
 
int get_string (string *buf)
 
int get_string (char *buf, size_t size)
 
int get_strings (std::vector< string > &result)
 
int get_strings (std::vector< string > *result)
 
int get_strings (std::list< string > &result)
 
int get_strings (std::list< string > *result)
 
int get_strings (std::map< string, string > &result)
 
int get_strings (std::vector< string > &names, std::vector< string > &values)
 
int get_strings (std::vector< const char * > &names, std::vector< const char * > &values)
 
void argv_space (size_t n)
 
void build_request1 (size_t argc, const char *argv[], size_t lens[])
 
void build_request2 (size_t argc, const char *argv[], size_t lens[])
 
void logger_result (const redis_result *result)
 
- Protected 成员函数 继承自 acl::acl::noncopyable
 noncopyable ()
 
 ~noncopyable ()
 
- Protected 属性 继承自 acl::redis_command
dbuf_pooldbuf_
 
bool check_addr_
 
char addr_ [32]
 
redis_clientconn_
 
redis_client_clustercluster_
 
redis_client_pipelinepipeline_
 
bool pipe_use_mbox_
 
int slot_
 
int redirect_max_
 
int redirect_sleep_
 
bool slice_req_
 
stringrequest_buf_
 
redis_request * request_obj_
 
size_t argv_size_
 
const char ** argv_
 
size_t * argv_lens_
 
size_t argc_
 
bool slice_res_
 
redis_pipeline_messagepipe_msg_
 
const redis_resultresult_
 

详细描述

在文件 redis_pubsub.hpp12 行定义.

构造及析构函数说明

◆ redis_pubsub() [1/5]

acl::redis_pubsub::redis_pubsub ( void  )

◆ redis_pubsub() [2/5]

acl::redis_pubsub::redis_pubsub ( redis_client conn)

◆ redis_pubsub() [3/5]

acl::redis_pubsub::redis_pubsub ( redis_client_cluster cluster)

◆ redis_pubsub() [4/5]

ACL_CPP_DEPRECATED acl::redis_pubsub::redis_pubsub ( redis_client_cluster cluster,
size_t  max_conns 
)

◆ redis_pubsub() [5/5]

acl::redis_pubsub::redis_pubsub ( redis_client_pipeline pipeline)

◆ ~redis_pubsub()

virtual acl::redis_pubsub::~redis_pubsub ( void  )
virtual

成员函数说明

◆ get_message()

bool acl::redis_pubsub::get_message ( string channel,
string msg,
string message_type = NULL,
string pattern = NULL,
int  timeout = -1 
)

在订阅频道后可以循环调用本函数从所订阅的频道中获取订阅消息; 在调用 subscribe 或 psubscribe 后才可调用本函数来获取所订阅的频道的消息 get messages posted to channels after SUBSCRIBE or PSUBSCRIBE

参数
channel{string&} 存放当前有消息的频道名 buffer for storing the channel associate with the msg
msg{string&} 存放当前获得的消息内容 store the message posted to the channel
message_type{string*} will store messsage or pmessage
pattern{string*} will store pattern set by psubscribe
timeout{int} 当该值 >= 0 时,表示等待消息超时时间(秒) when timeout >= 0, which was used as the waiting time for reading(second)
返回
{bool} 是否成功,如果返回 false 则表示出错或超时 true on success, false on error or waiting timeout

◆ psubscribe() [1/3]

int acl::redis_pubsub::psubscribe ( const char *  first_pattern,
  ... 
)

订阅一个或多个符合给定模式的频道;每个模式以 * 作为匹配符;在调用本函数后的操作 只能发送的命令有:subscribe、unsubscribe、psubscribe、punsubscribe、 get_message,只有取消订阅了所有频道(或连接重建)后才摆脱该限制 listen for messages published to channels matching the give patterns

参数
first_pattern{const char*} 第一个匹配模式串 the first pattern in pattern list, the last parameter must be NULL int the variable args
返回
{int} 返回当前已经成功订阅的频道个数(即所订阅的所有频道数量) the number of channels listened by the current client

◆ psubscribe() [2/3]

int acl::redis_pubsub::psubscribe ( const std::vector< const char * > &  patterns)

◆ psubscribe() [3/3]

int acl::redis_pubsub::psubscribe ( const std::vector< string > &  patterns)

◆ publish()

int acl::redis_pubsub::publish ( const char *  channel,
const char *  msg,
size_t  len 
)

将信息发送到指定的频道 channel post a message to a channel

参数
channel{const char*} 所发送消息的目标频道 the specified channel
msg{const char*} 消息内容 the message to be sent
len{size_t} 消息长度 the message's length
返回
{int} 成功发送至订阅该频道的订阅者数量 the number of clients that received the message -1:表示出错 error happened 0:没有订阅者 no client subscribe the channel >0:订阅该频道的订阅者数量 the number of clients that received the message

◆ pubsub_channels() [1/3]

int acl::redis_pubsub::pubsub_channels ( std::vector< string > *  channels,
const char *  first_pattern,
  ... 
)

列出当前的活跃频道:活跃频道指的是那些至少有一个订阅者的频道, 订阅模式的 客户端不计算在内 Lists the currently active channels.

参数
channels{std::vector<string>*} 非空时存放频道结果集 store the active channels
first_pattern{const char*} 作为附加的匹配模式第一个匹配字符串, 该指针可以为 NULL,此时获取指所有的活跃频道;对于变参而言最后一个参数需为 NULL the first pattern in a variable args ending with NULL arg, and the first arg can be NULL.
返回
{int} 返回活跃频道数; -1 表示出错 the number of active channels. -1 if error

操作成功后可以通过以下任一方式获得数据 1、基类方法 get_value 获得指定下标的元素数据 2、基类方法 get_child 获得指定下标的元素对象(redis_result),然后再通过 redis_result::argv_to_string 方法获得元素数据 3、基类方法 get_result 方法取得总结果集对象 redis_result,然后再通过 redis_result::get_child 获得一个元素对象,然后再通过方式 2 中指定 的方法获得该元素的数据 4、基类方法 get_children 获得结果元素数组对象,再通过 redis_result 中 的方法 argv_to_string 从每一个元素对象中获得元素数据 5、在调用方法中传入非空的存储结果对象的地址

◆ pubsub_channels() [2/3]

int acl::redis_pubsub::pubsub_channels ( const std::vector< const char * > &  patterns,
std::vector< string > *  channels 
)

◆ pubsub_channels() [3/3]

int acl::redis_pubsub::pubsub_channels ( const std::vector< string > &  patterns,
std::vector< string > *  channels 
)

◆ pubsub_numpat()

int acl::redis_pubsub::pubsub_numpat ( )

返回订阅模式的数量,这个命令返回的不是订阅模式的客户端的数量, 而是客户端订阅的 所有模式的数量总和 Returns the number of subscriptions to patterns.

返回
{int} 客户端所有订阅模式的总和,-1 表示出错 the number of patterns all the clients are subscribed to, -1 if error.

◆ pubsub_numsub() [1/3]

int acl::redis_pubsub::pubsub_numsub ( std::map< string, int > &  out,
const char *  first_channel,
  ... 
)

返回给定频道的订阅者数量, 订阅模式的客户端不计算在内 Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.

参数
out{std::map<string, int>&} 存储查询结果,其中 out->first 存放 频道名,out->second 在座该频道的订阅者数量 store the results
first_channel{const char*} 第一个频道 该指针可以为 NULL,此时获取指所有的活跃频道;对于变参而言最后一个参数需为 NULL the first pattern in a variable args ending with NULL arg, and the first arg can be NULL.
返回
{int} 频道的数量,-1 表示出错

◆ pubsub_numsub() [2/3]

int acl::redis_pubsub::pubsub_numsub ( const std::vector< const char * > &  channels,
std::map< string, int > &  out 
)

◆ pubsub_numsub() [3/3]

int acl::redis_pubsub::pubsub_numsub ( const std::vector< string > &  channels,
std::map< string, int > &  out 
)

◆ punsubscribe() [1/3]

int acl::redis_pubsub::punsubscribe ( const char *  first_pattern,
  ... 
)

根据模式匹配串取消订阅给定的一个或多个频道的信息 stop listening for messaged posted to channels matching the given patterns

参数
first_pattern{const char*} 第一个匹配模式串 the first parttern in a variable args ending with NULL
返回
{int} 返回剩余的所订阅的频道的个数 the rest number of channels be listened by the client

◆ punsubscribe() [2/3]

int acl::redis_pubsub::punsubscribe ( const std::vector< const char * > &  patterns)

◆ punsubscribe() [3/3]

int acl::redis_pubsub::punsubscribe ( const std::vector< string > &  patterns)

◆ subscribe() [1/3]

int acl::redis_pubsub::subscribe ( const char *  first_channel,
  ... 
)

订阅给定的一个或多个频道的信息;在调用本函数后的操作只能发送的命令有: subscribe、unsubscribe、psubscribe、punsubscribe、get_message,只有 取消订阅了所有频道(或连接重建)后才摆脱该限制 subscribe one or more channel(s). Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE and PUNSUBSCRIBE commands

参数
first_channel{const char*} 所订阅的频道列表的第一个非空字符串 的频道,对于变参列表中的最后一个必须是 NULL the first non-NULL channel in the channel list, and the last parameter must be NULL indicating the end of the channel list
返回
{int} 返回当前已经成功订阅的频道个数(即所订阅的所有频道数量) the number of channels subscribed by the current client

◆ subscribe() [2/3]

int acl::redis_pubsub::subscribe ( const std::vector< const char * > &  channels)

◆ subscribe() [3/3]

int acl::redis_pubsub::subscribe ( const std::vector< string > &  channels)

◆ unsubscribe() [1/3]

int acl::redis_pubsub::unsubscribe ( const char *  first_channel,
  ... 
)

取消订阅给定的一个或多个频道的信息 stop listening for messages posted to the given channels

参数
first_channel{const char*} 所取消的所订阅频道列表的第一个频道 the fist channel in channel list, and the last parameter must be NULL indicating the end of the channel list
返回
{int} 返回剩余的所订阅的频道的个数 the rest channels listened by the current client

◆ unsubscribe() [2/3]

int acl::redis_pubsub::unsubscribe ( const std::vector< const char * > &  channels)

◆ unsubscribe() [3/3]

int acl::redis_pubsub::unsubscribe ( const std::vector< string > &  channels)

该类的文档由以下文件生成: