resp协议实现和使用hiredis进行测试
This commit is contained in:
@@ -30,6 +30,21 @@ static void set_default_config(AppConfig *cfg)
|
||||
strncpy(cfg->master_ip, "127.0.0.1", sizeof(cfg->master_ip) - 1);
|
||||
cfg->master_ip[sizeof(cfg->master_ip) - 1] = '\0';
|
||||
|
||||
strncpy(cfg->persist_dir, "data.default", sizeof(cfg->persist_dir) - 1);
|
||||
cfg->persist_dir[sizeof(cfg->persist_dir) - 1] = '\0';
|
||||
|
||||
strncpy(cfg->oplog_file, "kvs_oplog.default.db", sizeof(cfg->oplog_file) - 1);
|
||||
cfg->oplog_file[sizeof(cfg->oplog_file) - 1] = '\0';
|
||||
|
||||
strncpy(cfg->array_file, "kvs_array.default.db", sizeof(cfg->array_file) - 1);
|
||||
cfg->array_file[sizeof(cfg->array_file) - 1] = '\0';
|
||||
|
||||
strncpy(cfg->rbtree_file, "kvs_rbtree.default.db", sizeof(cfg->rbtree_file) - 1);
|
||||
cfg->rbtree_file[sizeof(cfg->rbtree_file) - 1] = '\0';
|
||||
|
||||
strncpy(cfg->hash_file, "kvs_hash.default.db", sizeof(cfg->hash_file) - 1);
|
||||
cfg->hash_file[sizeof(cfg->hash_file) - 1] = '\0';
|
||||
|
||||
cfg->port = 8888;
|
||||
cfg->log_level = LOG_LEVEL_INFO;
|
||||
cfg->mode = MODE_MASTER;
|
||||
@@ -182,7 +197,7 @@ int config_load(const char *filename, AppConfig *out_cfg)
|
||||
|
||||
xmlNodePtr mport_node = find_child(master, "port");
|
||||
if (mport_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(port_node);
|
||||
xmlChar *txt = xmlNodeGetContent(mport_node);
|
||||
if (txt) {
|
||||
out_cfg->master_port = atoi((char *)txt);
|
||||
xmlFree(txt);
|
||||
@@ -215,6 +230,56 @@ int config_load(const char *filename, AppConfig *out_cfg)
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr dir_node = find_child(pers, "dir");
|
||||
if (dir_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(dir_node);
|
||||
if (txt) {
|
||||
strncpy(out_cfg->persist_dir, (char *)txt, sizeof(out_cfg->persist_dir) - 1);
|
||||
out_cfg->persist_dir[sizeof(out_cfg->persist_dir) - 1] = '\0';
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr wal_node = find_child(pers, "wal");
|
||||
if (wal_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(wal_node);
|
||||
if (txt) {
|
||||
strncpy(out_cfg->oplog_file, (char *)txt, sizeof(out_cfg->oplog_file) - 1);
|
||||
out_cfg->oplog_file[sizeof(out_cfg->oplog_file) - 1] = '\0';
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr array_node = find_child(pers, "array");
|
||||
if (array_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(array_node);
|
||||
if (txt) {
|
||||
strncpy(out_cfg->array_file, (char *)txt, sizeof(out_cfg->array_file) - 1);
|
||||
out_cfg->array_file[sizeof(out_cfg->array_file) - 1] = '\0';
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr rbtree_node = find_child(pers, "rbtree");
|
||||
if (rbtree_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(rbtree_node);
|
||||
if (txt) {
|
||||
strncpy(out_cfg->rbtree_file, (char *)txt, sizeof(out_cfg->rbtree_file) - 1);
|
||||
out_cfg->rbtree_file[sizeof(out_cfg->rbtree_file) - 1] = '\0';
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr hash_node = find_child(pers, "hash");
|
||||
if (hash_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(hash_node);
|
||||
if (txt) {
|
||||
strncpy(out_cfg->hash_file, (char *)txt, sizeof(out_cfg->hash_file) - 1);
|
||||
out_cfg->hash_file[sizeof(out_cfg->hash_file) - 1] = '\0';
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* memory 部分 */
|
||||
|
||||
Reference in New Issue
Block a user