MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _Config_set

Function _Config_set

src/commands/cmd_config.c:67–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void _Config_set
68(
69 RedisModuleCtx *ctx,
70 RedisModuleString **argv,
71 int argc
72) {
73 //--------------------------------------------------------------------------
74 // validate configuration
75 //--------------------------------------------------------------------------
76
77 // dryrun configuration, make sure all configurations are valid
78 for(int i = 0; i < argc; i += 2) {
79 RedisModuleString *key = argv[i];
80 RedisModuleString *val = argv[i+1];
81
82 //----------------------------------------------------------------------
83 // retrieve and validate config field
84 //----------------------------------------------------------------------
85
86 Config_Option_Field config_field;
87 const char *config_name = RedisModule_StringPtrLen(key, NULL);
88 if(!Config_Contains_field(config_name, &config_field)) {
89 RedisModule_ReplyWithError(ctx, "Unknown configuration field");
90 return;
91 }
92
93 // ensure field is a runtime configuration
94 bool configurable_field = false;
95 for(int i = 0; i < RUNTIME_CONFIG_COUNT; i++) {
96 if(RUNTIME_CONFIGS[i] == config_field) {
97 configurable_field = true;
98 break;
99 }
100 }
101
102 // field is not allowed to be reconfigured
103 if(!configurable_field) {
104 RedisModule_ReplyWithError(ctx, "This configuration parameter cannot be set at run-time");
105 return;
106 }
107
108 // make sure value is valid
109 char *error = NULL;
110 const char *val_str = RedisModule_StringPtrLen(val, NULL);
111 if(!Config_Option_dryrun(config_field, val_str, &error)) {
112 if(error != NULL) {
113 RedisModule_ReplyWithError(ctx, error);
114 } else {
115 char *errmsg;
116 int rc __attribute__((unused));
117 rc = asprintf(&errmsg, "Failed to set config value %s to %s", config_name, val_str);
118 RedisModule_ReplyWithError(ctx, errmsg);
119 free(errmsg);
120 }
121 return;
122 }
123 }
124

Callers 1

Graph_ConfigFunction · 0.85

Calls 3

Config_Contains_fieldFunction · 0.85
Config_Option_dryrunFunction · 0.85
Config_Option_setFunction · 0.85

Tested by

no test coverage detected