RedisValue equality treats "1,000", "(5)" and " 5 " as numbers, via NumberStyles.Any
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
調査の方向性
Format.cs:178 と RedisValue.Simplify() が使用する TryParseDouble のパスから始め、それを NumberStyles.Integer を使用する整数解析のパスと比較します。列挙されている等価性のケースと、提案されている NumberStyles の代替案を確認します。受け入れる数値テキストのセマンティクスについて合意され、影響を受ける比較にリグレッションカバレッジが追加されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Raised during review of #3230, where the numeric side of RedisValue equality came up. Pre-existing
behaviour, not caused by that PR.
What happens
operator == runs Simplify() on both sides, so text that parses as a number is compared as a number.
Format.cs:178 does that parse with NumberStyles.Any:
return double.TryParse(s, NumberStyles.Any, NumberFormatInfo.InvariantInfo, out value);
NumberStyles.Any allows thousands separators, parentheses for negatives, leading and trailing whitespace, a
currency symbol, and exponents. So:
| comparison | result | storage |
|---|---|---|
"1,000" == "1000" |
True | String / String |
"(5)" == "-5" |
True | String / String |
" 5 " == "5" |
True | String / String |
"1,0,0,0" == "1000" |
True | String / String |
"5." == "5" |
True | String / String |
"+5" == "5" |
True | String / String |
"1e2" == "100" |
True | String / String |
Both sides are String-typed throughout — these are ordinary string values, not numbers that happen to be
spelled differently.
Every integer path in Format.cs uses the much tighter NumberStyles.Integer; TryParseDouble is the only
one using Any, which makes it look more like an oversight than a decision.
Why it matters
These are distinct values on the server — distinct set members, distinct hash fields, distinct keys — that
compare equal in the client. Anything deduplicating RedisValues in a HashSet<RedisValue>, or keying a
Dictionary<RedisValue, T>, silently merges them. " 5 " and "5" are plainly different values by any
reading.
It is at least self-consistent: GetHashCode simplifies too, so equal values do share a hash and no hash
container is corrupted. The problem is that the equality is much wider than "numeric text".
Possible direction
NumberStyles.Float (leading/trailing whitespace, leading sign, decimal point, exponent) would drop the
separators, parentheses and currency symbol while keeping what Redis actually emits for numbers. Even that
leaves " 5 " == "5" true and "1e2" == "100" true, so the whitespace and exponent allowances are worth a
separate decision.
Any change here alters shipped comparison behaviour, so it wants its own discussion rather than being folded
into unrelated work — hence this issue rather than a PR.
- 主要言語
- C#
- スター
- 6.2k
- フォーク
- 1.6k
- 平均マージ
- 1日 5時間
- マージ済み PR(30日)
- 27
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
StackExchange/StackExchange.Redis のほかの issue
-
Overload of `StringSetAsync` has a small documenation error対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
StackExchange/StackExchange.Redis#3269 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
StackExchange/StackExchange.Redis#3249 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
HotKeysClusterTests.CanUseClusterFilter skips intermittently, hiding the assertions it exists forオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
StackExchange/StackExchange.Redis#3239 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
StackExchange/StackExchange.Redis#3252 · コメント 8 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
StackExchange/StackExchange.Redis#3240 ·
メンテナーはふだん 1 日以内に返信
StackExchange/StackExchange.Redis の issue をすべて見る
似ている issue
-
A numeric literal is parsed in the host's culture, so 1.5 is 15 in a made EXE on a comma-decimal OSオープンbug interpreter silently-wrong small
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
reactiveui/ReactiveUI.Binding.SourceGenerators#176 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
dotnet/csharpstandard#1830 ·
メンテナーはふだん 1 日以内に返信
-
c:docs p:high size:S t:docs
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信