Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis conf parse failed #207

Open
naughtyGitCat opened this issue Mar 5, 2020 · 3 comments
Open

Redis conf parse failed #207

naughtyGitCat opened this issue Mar 5, 2020 · 3 comments
Labels

Comments

@naughtyGitCat
Copy link

                this.logger.LogDebug($"redis config string: \n{raw.ConfigString}");
                var parser = new IniDataParser(new IniParser.Model.Configuration.IniParserConfiguration { AllowKeysWithoutSection = true });
                parser.Configuration.CommentString = "#";
                var data = parser.Parse(raw.ConfigString);
                this.logger.LogDebug($"parsed conf: {data}");

turns:

IniParser.Exceptions.ParsingException: Unknown file format. Couldn't parse the line: 'bind 10.160.246.207'. while parsing line number 0 with value '' - IniParser version: 2.5.2.0 while parsing line number 1 with value 'bind 10.160.246.207' - IniParser version: 2.5.2.0
 ---> IniParser.Exceptions.ParsingException: Unknown file format. Couldn't parse the line: 'bind 100.100.206.207'. while parsing line number 0 with value '' - IniParser version: 2.5.2.0
   at IniParser.Parser.IniDataParser.ProcessLine(String currentLine, IniData currentIniData)
   at IniParser.Parser.IniDataParser.Parse(String iniDataString)
   --- End of inner exception stack trace ---
   at IniParser.Parser.IniDataParser.Parse(String iniDataString)

the raw.String is below:

bind 100.100.206.207
protected-mode yes
port 6579
tcp-backlog 1000
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
loglevel notice
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 300
maxmemory 2GB

# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
@naughtyGitCat
Copy link
Author

fixed with

                parser.Configuration.KeyValueAssigmentChar = ' ';

but the

save 900 1
save 300 10
save 60 10000

how to parse? the parser.Configuration.AllowDuplicateKeys = true only leaves one save

@naughtyGitCat
Copy link
Author

and unable to use System.Text.Json to serialize

System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.KeyValuePair`2[System.String,IniParser.Model.KeyData]' to type 'IniParser.Model.KeyData'.
   at get_Comments(Object )
   at System.Text.Json.JsonPropertyInfoCommon`4.GetValueAsObject(Object obj)
   at System.Text.Json.JsonSerializer.HandleEnumerable(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
   at System.Text.Json.JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteCore(Utf8JsonWriter writer, Object value, Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)

@naughtyGitCat
Copy link
Author

naughtyGitCat commented Mar 5, 2020

serialize problem fixed with

                var dict = new Dictionary<string, object>();
                foreach (var i in data.Global)
                {
                    dict.Add(i.KeyName, i.Value);
                }

hope there is a ToJson Method, or __json__ magic method

@rickyah rickyah added the bug label Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants