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

Replace all occurrences of "nil" in IDatabase(Async) xmldoc with less ambiguous alternatives #2702

Merged
merged 1 commit into from May 7, 2024

Conversation

bdach
Copy link
Contributor

@bdach bdach commented Apr 22, 2024

Closes #2697.

All of the replacements were empirically tested to be correct via simple programs in combination with a local redis instance.

Notably, there is one worrying nit; in testing it turns out that the IDatabase.List{Left,Right}Pop(RedisKey, long, CommandFlags) overload which I talked about in the issue can actually return null, contrary to its nullability annotations. This occurs on missing key; in that case redis replies

Nil reply: if the key does not exist.

as per https://redis.io/docs/latest/commands/lpop/, which then at

case ResultType.Array:
arr = result.GetItemsAsValues()!;

and later at

[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static T[]? ToArray<T>(in this RawResult result, Projection<RawResult, T> selector)
=> result.IsNull ? null : result.GetItems().ToArray(selector);

turns into a null.

I briefly attempted to rectify this, but the RedisValueArrayProcessor poses a problem here, as changing it to derive
ResultProcessor<RedisValue[]?> causes the solution to light up in red, and I'd rather not mess with that as a first contribution without at least prior discussion concerning direction there.

…ss ambiguous alternatives

Closes StackExchange#2697.

All of the replacements were tested to be correct via simple programs in
combination with a local redis instance.

Notably, there is one worrying nit; in testing it turns out that
the `IDatabase.List{Left,Right}Pop(RedisKey, long, CommandFlags)`
overload _can_ actually return null, contrary to its nullability
annotations. This occurs on missing key; in that case redis replies

	Nil reply: if the key does not exist.

as per https://redis.io/docs/latest/commands/lpop/, which then at

	https://github.com/StackExchange/StackExchange.Redis/blob/cb8b20df0e2975717bde97ce95ac20e8e8353572/src/StackExchange.Redis/ResultProcessor.cs#L1546-L1547

and later at

	https://github.com/StackExchange/StackExchange.Redis/blob/cb8b20df0e2975717bde97ce95ac20e8e8353572/src/StackExchange.Redis/ExtensionMethods.cs#L339-L341

turns into a `null`.

I briefly attempted to rectify this, but the `RedisValueArrayProcessor`
poses a problem here, as changing it to derive
`ResultProcessor<RedisValue[]?>` causes the solution to light up in red,
and I'd rather not mess with that as a first contribution.
Copy link
Collaborator

@NickCraver NickCraver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - went through and agree these are the best options. Thank you for this!

@NickCraver NickCraver merged commit 61c13c2 into StackExchange:main May 7, 2024
6 checks passed
@bdach bdach deleted the nil-in-docs branch May 8, 2024 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing nullability of IDatabase.ListRightPop() (and possibly more?)
2 participants