如何使用天翼云主机建设网站,对新网站做seo大概需要多久,西安效果图制作,专业网站定制团队在Redis server启动过程中#xff0c;实现了实例化和初始化
1、哨兵实例化过程#xff0c;采用redis sentinel指令实例化还是redis server下的参数实例化--sentinel。
// 检查服务器是否以 Sentinel 模式启动
server.sentinel_mode checkForSentinelMode(argc,argv);/* Re…在Redis server启动过程中实现了实例化和初始化
1、哨兵实例化过程采用redis sentinel指令实例化还是redis server下的参数实例化--sentinel。
// 检查服务器是否以 Sentinel 模式启动
server.sentinel_mode checkForSentinelMode(argc,argv);/* Returns 1 if there is --sentinel among the arguments or if* argv[0] is exactly redis-sentinel. */
int checkForSentinelMode(int argc, char **argv) {int j;if (strstr(argv[0],redis-sentinel) ! NULL) return 1;for (j 1; j argc; j)if (!strcmp(argv[j],--sentinel)) return 1;return 0;
}2、如果Redis实例以哨兵模式启动执行初始化此时又两个函数需要注意
// 如果服务器以 Sentinel 模式启动。需要执行以下两个初始化操作。if (server.sentinel_mode) {initSentinelConfig();initSentinel();}
initSentinelConfig函数负责初始化哨兵的配置端口号供全局使用。
// 这个函数会用 Sentinel 所属的属性覆盖服务器默认的属性
void initSentinelConfig(void) {server.port REDIS_SENTINEL_PORT;
}
2、initSentinel函数操作比较多基本就是预分配一些配置需要的空间并且初始化默认值。
1、初始化server哨兵命令列表。
2、初始化主服务器信息字典。
3、初始化 TILT 模式的相关选项。
4、初始化脚本相关选项。
/* Perform the Sentinel mode initialization. */
// 以 Sentinel 模式初始化服务器
void initSentinel(void) {int j;/* Remove usual Redis commands from the command table, then just add* the SENTINEL command. */// 清空 Redis 服务器的命令表该表用于普通模式dictEmpty(server.commands,NULL);// 将 SENTINEL 模式所用的命令添加进命令表for (j 0; j sizeof(sentinelcmds)/sizeof(sentinelcmds[0]); j) {int retval;struct redisCommand *cmd sentinelcmdsj;retval dictAdd(server.commands, sdsnew(cmd-name), cmd);redisAssert(retval DICT_OK);}/* Initialize various data structures. *//* 初始化 Sentinel 的状态 */// 初始化纪元sentinel.current_epoch 0;// 初始化保存主服务器信息的字典sentinel.masters dictCreate(instancesDictType,NULL);// 初始化 TILT 模式的相关选项sentinel.tilt 0;sentinel.tilt_start_time 0;sentinel.previous_time mstime();// 初始化脚本相关选项sentinel.running_scripts 0;sentinel.scripts_queue listCreate();
}
3、启动哨兵实例。
sentinelIsRunning函数--
sentinelGenerateInitialMonitorEvents函数--
sentinelEvent函数--
pubsubPublishMessage函数
发布订阅模式解决哨兵与master、slave节点、或者哨兵实例之间的通讯问题。实际就是通过
pubsubPublishMessage函数完成发布消息给redis客户端列表和订阅了该频道channel的实例哨兵或者主节点。
/* Publish a message ** 将 message 发送到所有订阅频道 channel 的客户端* 以及所有订阅了和 channel 频道匹配的模式的客户端。*/
int pubsubPublishMessage(robj *channel, robj *message) {int receivers 0;dictEntry *de;listNode *ln;listIter li;/* Send to clients listening for that channel */// 取出包含所有订阅频道 channel 的客户端的链表// 并将消息发送给它们de dictFind(server.pubsub_channels,channel);if (de) {list *list dictGetVal(de);listNode *ln;listIter li;// 遍历客户端链表将 message 发送给它们listRewind(list,li);while ((ln listNext(li)) ! NULL) {redisClient *c ln-value;// 回复客户端。// 示例// 1) message// 2) xxx// 3) helloaddReply(c,shared.mbulkhdr[3]);// message 字符串addReply(c,shared.messagebulk);// 消息的来源频道addReplyBulk(c,channel);// 消息内容addReplyBulk(c,message);// 接收客户端计数receivers;}}/* Send to clients listening to matching channels */// 将消息也发送给那些和频道匹配的模式if (listLength(server.pubsub_patterns)) {// 遍历模式链表listRewind(server.pubsub_patterns,li);channel getDecodedObject(channel);while ((ln listNext(li)) ! NULL) {// 取出 pubsubPatternpubsubPattern *pat ln-value;// 如果 channel 和 pattern 匹配// 就给所有订阅该 pattern 的客户端发送消息if (stringmatchlen((char*)pat-pattern-ptr,sdslen(pat-pattern-ptr),(char*)channel-ptr,sdslen(channel-ptr),0)) {// 回复客户端// 示例// 1) pmessage// 2) *// 3) xxx// 4) helloaddReply(pat-client,shared.mbulkhdr[4]);addReply(pat-client,shared.pmessagebulk);addReplyBulk(pat-client,pat-pattern);addReplyBulk(pat-client,channel);addReplyBulk(pat-client,message);// 对接收消息的客户端进行计数receivers;}}decrRefCount(channel);}// 返回计数return receivers;
}