Skip to content

Commit 61c13c2

Browse files
authored
Replace all occurrences of "nil" in IDatabase(Async) xmldoc with less ambiguous alternatives (#2702)
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 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 without at least prior discussion concerning direction there.
1 parent cb8b20d commit 61c13c2

File tree

2 files changed

+58
-56
lines changed

2 files changed

+58
-56
lines changed

src/StackExchange.Redis/Interfaces/IDatabase.cs

+29-28
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
331331
/// <param name="key">The key of the hash.</param>
332332
/// <param name="hashField">The field in the hash to get.</param>
333333
/// <param name="flags">The flags to use for this operation.</param>
334-
/// <returns>The value associated with field, or nil when field is not present in the hash or key does not exist.</returns>
334+
/// <returns>The value associated with field, or <see cref="RedisValue.Null"/> when field is not present in the hash or key does not exist.</returns>
335335
/// <remarks><seealso href="https://redis.io/commands/hget"/></remarks>
336336
RedisValue HashGet(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);
337337

@@ -341,13 +341,14 @@ public interface IDatabase : IRedis, IDatabaseAsync
341341
/// <param name="key">The key of the hash.</param>
342342
/// <param name="hashField">The field in the hash to get.</param>
343343
/// <param name="flags">The flags to use for this operation.</param>
344-
/// <returns>The value associated with field, or nil when field is not present in the hash or key does not exist.</returns>
344+
/// <returns>The value associated with field, or <see langword="null"/> when field is not present in the hash or key does not exist.</returns>
345345
/// <remarks><seealso href="https://redis.io/commands/hget"/></remarks>
346346
Lease<byte>? HashGetLease(RedisKey key, RedisValue hashField, CommandFlags flags = CommandFlags.None);
347347

348348
/// <summary>
349349
/// Returns the values associated with the specified fields in the hash stored at key.
350-
/// For every field that does not exist in the hash, a nil value is returned.Because a non-existing keys are treated as empty hashes, running HMGET against a non-existing key will return a list of nil values.
350+
/// For every field that does not exist in the hash, a <see langword="RedisValue.Null"/> value is returned.
351+
/// Because non-existing keys are treated as empty hashes, running HMGET against a non-existing key will return a list of <see langword="RedisValue.Null"/> values.
351352
/// </summary>
352353
/// <param name="key">The key of the hash.</param>
353354
/// <param name="hashFields">The fields in the hash to get.</param>
@@ -802,7 +803,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
802803
/// Return a random key from the currently selected database.
803804
/// </summary>
804805
/// <param name="flags">The flags to use for this operation.</param>
805-
/// <returns>The random key, or nil when the database is empty.</returns>
806+
/// <returns>The random key, or <see cref="RedisKey.Null"/> when the database is empty.</returns>
806807
/// <remarks><seealso href="https://redis.io/commands/randomkey"/></remarks>
807808
RedisKey KeyRandom(CommandFlags flags = CommandFlags.None);
808809

@@ -847,7 +848,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
847848
/// </summary>
848849
/// <param name="key">The key to check.</param>
849850
/// <param name="flags">The flags to use for this operation.</param>
850-
/// <returns>TTL, or nil when key does not exist or does not have a timeout.</returns>
851+
/// <returns>TTL, or <see langword="null"/> when key does not exist or does not have a timeout.</returns>
851852
/// <remarks><seealso href="https://redis.io/commands/ttl"/></remarks>
852853
TimeSpan? KeyTimeToLive(RedisKey key, CommandFlags flags = CommandFlags.None);
853854

@@ -888,7 +889,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
888889
/// <param name="key">The key of the list.</param>
889890
/// <param name="index">The index position to get the value at.</param>
890891
/// <param name="flags">The flags to use for this operation.</param>
891-
/// <returns>The requested element, or nil when index is out of range.</returns>
892+
/// <returns>The requested element, or <see cref="RedisValue.Null"/> when index is out of range.</returns>
892893
/// <remarks><seealso href="https://redis.io/commands/lindex"/></remarks>
893894
RedisValue ListGetByIndex(RedisKey key, long index, CommandFlags flags = CommandFlags.None);
894895

@@ -921,7 +922,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
921922
/// </summary>
922923
/// <param name="key">The key of the list.</param>
923924
/// <param name="flags">The flags to use for this operation.</param>
924-
/// <returns>The value of the first element, or nil when key does not exist.</returns>
925+
/// <returns>The value of the first element, or <see cref="RedisValue.Null"/> when key does not exist.</returns>
925926
/// <remarks><seealso href="https://redis.io/commands/lpop"/></remarks>
926927
RedisValue ListLeftPop(RedisKey key, CommandFlags flags = CommandFlags.None);
927928

@@ -932,7 +933,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
932933
/// <param name="key">The key of the list.</param>
933934
/// <param name="count">The number of elements to remove</param>
934935
/// <param name="flags">The flags to use for this operation.</param>
935-
/// <returns>Array of values that were popped, or nil if the key doesn't exist.</returns>
936+
/// <returns>Array of values that were popped, or <see langword="null"/> if the key doesn't exist.</returns>
936937
/// <remarks><seealso href="https://redis.io/commands/lpop"/></remarks>
937938
RedisValue[] ListLeftPop(RedisKey key, long count, CommandFlags flags = CommandFlags.None);
938939

@@ -1075,7 +1076,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
10751076
/// </summary>
10761077
/// <param name="key">The key of the list.</param>
10771078
/// <param name="flags">The flags to use for this operation.</param>
1078-
/// <returns>The element being popped.</returns>
1079+
/// <returns>The element being popped, or <see cref="RedisValue.Null"/> when key does not exist..</returns>
10791080
/// <remarks><seealso href="https://redis.io/commands/rpop"/></remarks>
10801081
RedisValue ListRightPop(RedisKey key, CommandFlags flags = CommandFlags.None);
10811082

@@ -1086,7 +1087,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
10861087
/// <param name="key">The key of the list.</param>
10871088
/// <param name="count">The number of elements to pop</param>
10881089
/// <param name="flags">The flags to use for this operation.</param>
1089-
/// <returns>Array of values that were popped, or nil if the key doesn't exist.</returns>
1090+
/// <returns>Array of values that were popped, or <see langword="null"/> if the key doesn't exist.</returns>
10901091
/// <remarks><seealso href="https://redis.io/commands/rpop"/></remarks>
10911092
RedisValue[] ListRightPop(RedisKey key, long count, CommandFlags flags = CommandFlags.None);
10921093

@@ -1494,7 +1495,7 @@ public interface IDatabase : IRedis, IDatabaseAsync
14941495
/// </summary>
14951496
/// <param name="key">The key of the set.</param>
14961497
/// <param name="flags">The flags to use for this operation.</param>
1497-
/// <returns>The removed element, or nil when key does not exist.</returns>
1498+
/// <returns>The removed element, or <see cref="RedisValue.Null"/> when key does not exist.</returns>
14981499
/// <remarks><seealso href="https://redis.io/commands/spop"/></remarks>
14991500
RedisValue SetPop(RedisKey key, CommandFlags flags = CommandFlags.None);
15001501

@@ -2122,7 +2123,7 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
21222123

21232124
/// <summary>
21242125
/// Returns the score of member in the sorted set at key.
2125-
/// If member does not exist in the sorted set, or key does not exist, nil is returned.
2126+
/// If member does not exist in the sorted set, or key does not exist, <see langword="null"/> is returned.
21262127
/// </summary>
21272128
/// <param name="key">The key of the sorted set.</param>
21282129
/// <param name="member">The member to get a score for.</param>
@@ -2151,7 +2152,7 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
21512152
/// <param name="key">The key of the sorted set.</param>
21522153
/// <param name="order">The order to sort by (defaults to ascending).</param>
21532154
/// <param name="flags">The flags to use for this operation.</param>
2154-
/// <returns>The removed element, or nil when key does not exist.</returns>
2155+
/// <returns>The removed element, or <see langword="null"/> when key does not exist.</returns>
21552156
/// <remarks>
21562157
/// <seealso href="https://redis.io/commands/zpopmin"/>,
21572158
/// <seealso href="https://redis.io/commands/zpopmax"/>
@@ -2674,32 +2675,32 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
26742675
double StringDecrement(RedisKey key, double value, CommandFlags flags = CommandFlags.None);
26752676

26762677
/// <summary>
2677-
/// Get the value of key. If the key does not exist the special value nil is returned.
2678+
/// Get the value of key. If the key does not exist the special value <see cref="RedisValue.Null"/> is returned.
26782679
/// An error is returned if the value stored at key is not a string, because GET only handles string values.
26792680
/// </summary>
26802681
/// <param name="key">The key of the string.</param>
26812682
/// <param name="flags">The flags to use for this operation.</param>
2682-
/// <returns>The value of key, or nil when key does not exist.</returns>
2683+
/// <returns>The value of key, or <see cref="RedisValue.Null"/> when key does not exist.</returns>
26832684
/// <remarks><seealso href="https://redis.io/commands/get"/></remarks>
26842685
RedisValue StringGet(RedisKey key, CommandFlags flags = CommandFlags.None);
26852686

26862687
/// <summary>
26872688
/// Returns the values of all specified keys.
2688-
/// For every key that does not hold a string value or does not exist, the special value nil is returned.
2689+
/// For every key that does not hold a string value or does not exist, the special value <see cref="RedisValue.Null"/> is returned.
26892690
/// </summary>
26902691
/// <param name="keys">The keys of the strings.</param>
26912692
/// <param name="flags">The flags to use for this operation.</param>
2692-
/// <returns>The values of the strings with nil for keys do not exist.</returns>
2693+
/// <returns>The values of the strings with <see cref="RedisValue.Null"/> for keys do not exist.</returns>
26932694
/// <remarks><seealso href="https://redis.io/commands/mget"/></remarks>
26942695
RedisValue[] StringGet(RedisKey[] keys, CommandFlags flags = CommandFlags.None);
26952696

26962697
/// <summary>
2697-
/// Get the value of key. If the key does not exist the special value nil is returned.
2698+
/// Get the value of key. If the key does not exist the special value <see langword="null"/> is returned.
26982699
/// An error is returned if the value stored at key is not a string, because GET only handles string values.
26992700
/// </summary>
27002701
/// <param name="key">The key of the string.</param>
27012702
/// <param name="flags">The flags to use for this operation.</param>
2702-
/// <returns>The value of key, or nil when key does not exist.</returns>
2703+
/// <returns>The value of key, or <see langword="null"/> when key does not exist.</returns>
27032704
/// <remarks><seealso href="https://redis.io/commands/get"/></remarks>
27042705
Lease<byte>? StringGetLease(RedisKey key, CommandFlags flags = CommandFlags.None);
27052706

@@ -2733,7 +2734,7 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
27332734
/// <param name="key">The key of the string.</param>
27342735
/// <param name="value">The value to replace the existing value with.</param>
27352736
/// <param name="flags">The flags to use for this operation.</param>
2736-
/// <returns>The old value stored at key, or nil when key did not exist.</returns>
2737+
/// <returns>The old value stored at key, or <see cref="RedisValue.Null"/> when key did not exist.</returns>
27372738
/// <remarks><seealso href="https://redis.io/commands/getset"/></remarks>
27382739
RedisValue StringGetSet(RedisKey key, RedisValue value, CommandFlags flags = CommandFlags.None);
27392740

@@ -2744,7 +2745,7 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
27442745
/// <param name="key">The key of the string.</param>
27452746
/// <param name="expiry">The expiry to set. <see langword="null"/> will remove expiry.</param>
27462747
/// <param name="flags">The flags to use for this operation.</param>
2747-
/// <returns>The value of key, or nil when key does not exist.</returns>
2748+
/// <returns>The value of key, or <see cref="RedisValue.Null"/> when key does not exist.</returns>
27482749
/// <remarks><seealso href="https://redis.io/commands/getex"/></remarks>
27492750
RedisValue StringGetSetExpiry(RedisKey key, TimeSpan? expiry, CommandFlags flags = CommandFlags.None);
27502751

@@ -2755,29 +2756,29 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
27552756
/// <param name="key">The key of the string.</param>
27562757
/// <param name="expiry">The exact date and time to expire at. <see cref="DateTime.MaxValue"/> will remove expiry.</param>
27572758
/// <param name="flags">The flags to use for this operation.</param>
2758-
/// <returns>The value of key, or nil when key does not exist.</returns>
2759+
/// <returns>The value of key, or <see cref="RedisValue.Null"/> when key does not exist.</returns>
27592760
/// <remarks><seealso href="https://redis.io/commands/getex"/></remarks>
27602761
RedisValue StringGetSetExpiry(RedisKey key, DateTime expiry, CommandFlags flags = CommandFlags.None);
27612762

27622763
/// <summary>
27632764
/// Get the value of key and delete the key.
2764-
/// If the key does not exist the special value nil is returned.
2765+
/// If the key does not exist the special value <see cref="RedisValue.Null"/> is returned.
27652766
/// An error is returned if the value stored at key is not a string, because GET only handles string values.
27662767
/// </summary>
27672768
/// <param name="key">The key of the string.</param>
27682769
/// <param name="flags">The flags to use for this operation.</param>
2769-
/// <returns>The value of key, or nil when key does not exist.</returns>
2770+
/// <returns>The value of key, or <see cref="RedisValue.Null"/> when key does not exist.</returns>
27702771
/// <remarks><seealso href="https://redis.io/commands/getdelete"/></remarks>
27712772
RedisValue StringGetDelete(RedisKey key, CommandFlags flags = CommandFlags.None);
27722773

27732774
/// <summary>
27742775
/// Get the value of key.
2775-
/// If the key does not exist the special value nil is returned.
2776+
/// If the key does not exist the special value <see langword="default"/> is returned.
27762777
/// An error is returned if the value stored at key is not a string, because GET only handles string values.
27772778
/// </summary>
27782779
/// <param name="key">The key of the string.</param>
27792780
/// <param name="flags">The flags to use for this operation.</param>
2780-
/// <returns>The value of key and its expiry, or nil when key does not exist.</returns>
2781+
/// <returns>The value of key and its expiry, or <see langword="default"/> when key does not exist.</returns>
27812782
/// <remarks><seealso href="https://redis.io/commands/get"/></remarks>
27822783
RedisValueWithExpiry StringGetWithExpiry(RedisKey key, CommandFlags flags = CommandFlags.None);
27832784

@@ -2901,7 +2902,7 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
29012902
/// <param name="expiry">The expiry to set.</param>
29022903
/// <param name="when">Which condition to set the value under (defaults to <see cref="When.Always"/>).</param>
29032904
/// <param name="flags">The flags to use for this operation.</param>
2904-
/// <returns>The previous value stored at <paramref name="key"/>, or nil when key did not exist.</returns>
2905+
/// <returns>The previous value stored at <paramref name="key"/>, or <see cref="RedisValue.Null"/> when key did not exist.</returns>
29052906
/// <remarks>
29062907
/// <para>This method uses the <c>SET</c> command with the <c>GET</c> option introduced in Redis 6.2.0 instead of the deprecated <c>GETSET</c> command.</para>
29072908
/// <para><seealso href="https://redis.io/commands/set"/></para>
@@ -2917,7 +2918,7 @@ IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key,
29172918
/// <param name="keepTtl">Whether to maintain the existing key's TTL (KEEPTTL flag).</param>
29182919
/// <param name="when">Which condition to set the value under (defaults to <see cref="When.Always"/>).</param>
29192920
/// <param name="flags">The flags to use for this operation.</param>
2920-
/// <returns>The previous value stored at <paramref name="key"/>, or nil when key did not exist.</returns>
2921+
/// <returns>The previous value stored at <paramref name="key"/>, or <see cref="RedisValue.Null"/> when key did not exist.</returns>
29212922
/// <remarks>This method uses the SET command with the GET option introduced in Redis 6.2.0 instead of the deprecated GETSET command.</remarks>
29222923
/// <remarks><seealso href="https://redis.io/commands/set"/></remarks>
29232924
RedisValue StringSetAndGet(RedisKey key, RedisValue value, TimeSpan? expiry = null, bool keepTtl = false, When when = When.Always, CommandFlags flags = CommandFlags.None);

0 commit comments

Comments
 (0)