11using NRedisStack . Core ;
2+ using NRedisStack . Core . DataTypes ;
23using StackExchange . Redis ;
4+
35namespace NRedisStack
46{
57
@@ -19,5 +21,61 @@ public static bool ClientSetInfo(this IDatabase db, SetInfoAttr attr, string val
1921 return false ;
2022 return db . Execute ( CoreCommandBuilder . ClientSetInfo ( attr , value ) ) . OKtoBoolean ( ) ;
2123 }
24+
25+ /// <summary>
26+ /// The BZMPOP command.
27+ /// <p/>
28+ /// Removes and returns up to <paramref name="count"/> entries from the first non-empty sorted set in
29+ /// <paramref name="keys"/>. If none of the sets contain elements, the call blocks on the server until elements
30+ /// become available or the given <paramref name="timeout"/> passes. A <paramref name="timeout"/> of <c>0</c>
31+ /// means to wait indefinitely server-side. Returns <c>null</c> if the server timeout expires.
32+ /// <p/>
33+ /// When using this, pay attention to the timeout configured on the <see cref="ConnectionMultiplexer"/>, which
34+ /// by default can be too small, in which case you want to increase it:
35+ /// <code>
36+ /// ConfigurationOptions configurationOptions = new ConfigurationOptions();
37+ /// configurationOptions.SyncTimeout = 120000; // set a meaningful value here
38+ /// configurationOptions.EndPoints.Add("localhost");
39+ /// ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions);
40+ /// </code>
41+ /// If the connection multiplexer timeout expires, a <c>StackExchange.Redis.RedisTimeoutException</c> will be
42+ /// thrown.
43+ /// <p/>
44+ /// This is an extension method added to the <see cref="IDatabase"/> class, for convenience.
45+ /// </summary>
46+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
47+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
48+ /// <param name="keys">The keys to check.</param>
49+ /// <param name="minMaxModifier">Specify from which end of the sorted set to pop values. If set to <c>MinMaxModifier.Min</c>
50+ /// then the minimum elements will be popped, otherwise the maximum values.</param>
51+ /// <param name="count">The maximum number of records to pop out. If set to <c>null</c> then the server default
52+ /// will be used.</param>
53+ /// <returns>A collection of sorted set entries paired with their scores, together with the key they were popped
54+ /// from, or <c>null</c> if the server timeout expires.</returns>
55+ /// <remarks><seealso href="https://redis.io/commands/bzmpop"/></remarks>
56+ public static Tuple < RedisKey , List < RedisValueWithScore > > ? BzmPop ( this IDatabase db , int timeout , RedisKey [ ] keys , MinMaxModifier minMaxModifier , long ? count = null )
57+ {
58+ var command = CoreCommandBuilder . BzmPop ( timeout , keys , minMaxModifier , count ) ;
59+ return db . Execute ( command ) . ToSortedSetPopResult ( ) ;
60+ }
61+
62+ /// <summary>
63+ /// Syntactic sugar for <see cref="BzmPop(StackExchange.Redis.IDatabase,int,StackExchange.Redis.RedisKey[],StackExchange.Redis.Order,System.Nullable{long})"/>,
64+ /// where only one key is used.
65+ /// </summary>
66+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
67+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
68+ /// <param name="key">The key to check.</param>
69+ /// <param name="minMaxModifier">Specify from which end of the sorted set to pop values. If set to <c>MinMaxModifier.Min</c>
70+ /// then the minimum elements will be popped, otherwise the maximum values.</param>
71+ /// <param name="count">The maximum number of records to pop out. If set to <c>null</c> then the server default
72+ /// will be used.</param>
73+ /// <returns>A collection of sorted set entries paired with their scores, together with the key they were popped
74+ /// from, or <c>null</c> if the server timeout expires.</returns>
75+ /// <remarks><seealso href="https://redis.io/commands/bzmpop"/></remarks>
76+ public static Tuple < RedisKey , List < RedisValueWithScore > > ? BzmPop ( this IDatabase db , int timeout , RedisKey key , MinMaxModifier minMaxModifier , long ? count = null )
77+ {
78+ return BzmPop ( db , timeout , new [ ] { key } , minMaxModifier , count ) ;
79+ }
2280 }
2381}
0 commit comments