11using NRedisStack . Core ;
2+ using NRedisStack . Core . DataTypes ;
23using StackExchange . Redis ;
4+
35namespace NRedisStack
46{
57
@@ -19,5 +21,159 @@ 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"/> expires. 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 in the client, on the
34+ /// <see cref="ConnectionMultiplexer"/>, which by default can be too small:
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 in the client, a <c>StackExchange.Redis.RedisTimeoutException</c>
42+ /// is 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 , double timeout , RedisKey [ ] keys , MinMaxModifier minMaxModifier , long ? count = null )
57+ {
58+ var command = CoreCommandBuilder . BzmPop ( timeout , keys , minMaxModifier , count ) ;
59+ return db . Execute ( command ) . ToSortedSetPopResults ( ) ;
60+ }
61+
62+ /// <summary>
63+ /// Syntactic sugar for
64+ /// <see cref="BzmPop(StackExchange.Redis.IDatabase,double,StackExchange.Redis.RedisKey[],NRedisStack.Core.DataTypes.MinMaxModifier,System.Nullable{long})"/>,
65+ /// where only one key is used.
66+ /// </summary>
67+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
68+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
69+ /// <param name="key">The key to check.</param>
70+ /// <param name="minMaxModifier">Specify from which end of the sorted set to pop values. If set to <c>MinMaxModifier.Min</c>
71+ /// then the minimum elements will be popped, otherwise the maximum values.</param>
72+ /// <param name="count">The maximum number of records to pop out. If set to <c>null</c> then the server default
73+ /// will be used.</param>
74+ /// <returns>A collection of sorted set entries paired with their scores, together with the key they were popped
75+ /// from, or <c>null</c> if the server timeout expires.</returns>
76+ /// <remarks><seealso href="https://redis.io/commands/bzmpop"/></remarks>
77+ public static Tuple < RedisKey , List < RedisValueWithScore > > ? BzmPop ( this IDatabase db , double timeout , RedisKey key , MinMaxModifier minMaxModifier , long ? count = null )
78+ {
79+ return BzmPop ( db , timeout , new [ ] { key } , minMaxModifier , count ) ;
80+ }
81+
82+ /// <summary>
83+ /// The BZPOPMIN command.
84+ /// <p/>
85+ /// Removes and returns the entry with the smallest score from the first non-empty sorted set in
86+ /// <paramref name="keys"/>. If none of the sets contain elements, the call blocks on the server until elements
87+ /// become available, or the given <paramref name="timeout"/> expires. A <paramref name="timeout"/> of <c>0</c>
88+ /// means to wait indefinitely server-side. Returns <c>null</c> if the server timeout expires.
89+ /// <p/>
90+ /// When using this, pay attention to the timeout configured in the client, on the
91+ /// <see cref="ConnectionMultiplexer"/>, which by default can be too small:
92+ /// <code>
93+ /// ConfigurationOptions configurationOptions = new ConfigurationOptions();
94+ /// configurationOptions.SyncTimeout = 120000; // set a meaningful value here
95+ /// configurationOptions.EndPoints.Add("localhost");
96+ /// ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions);
97+ /// </code>
98+ /// If the connection multiplexer timeout expires in the client, a <c>StackExchange.Redis.RedisTimeoutException</c>
99+ /// is thrown.
100+ /// <p/>
101+ /// This is an extension method added to the <see cref="IDatabase"/> class, for convenience.
102+ /// </summary>
103+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
104+ /// <param name="keys">The keys to check.</param>
105+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
106+ /// <returns>A sorted set entry paired with its score, together with the key it was popped from, or <c>null</c>
107+ /// if the server timeout expires.</returns>
108+ /// <remarks><seealso href="https://redis.io/commands/bzpopmin"/></remarks>
109+ public static Tuple < RedisKey , RedisValueWithScore > ? BzPopMin ( this IDatabase db , RedisKey [ ] keys , double timeout )
110+ {
111+ var command = CoreCommandBuilder . BzPopMin ( keys , timeout ) ;
112+ return db . Execute ( command ) . ToSortedSetPopResult ( ) ;
113+ }
114+
115+ /// <summary>
116+ /// Syntactic sugar for <see cref="BzPopMin(StackExchange.Redis.IDatabase,StackExchange.Redis.RedisKey[],double)"/>,
117+ /// where only one key is used.
118+ /// </summary>
119+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
120+ /// <param name="key">The key to check.</param>
121+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
122+ /// <returns>A sorted set entry paired with its score, together with the key it was popped from, or <c>null</c>
123+ /// if the server timeout expires.</returns>
124+ /// <remarks><seealso href="https://redis.io/commands/bzpopmin"/></remarks>
125+ public static Tuple < RedisKey , RedisValueWithScore > ? BzPopMin ( this IDatabase db , RedisKey key , double timeout )
126+ {
127+ return BzPopMin ( db , new [ ] { key } , timeout ) ;
128+ }
129+
130+
131+ /// <summary>
132+ /// The BZPOPMAX command.
133+ /// <p/>
134+ /// Removes and returns the entry with the highest score from the first non-empty sorted set in
135+ /// <paramref name="keys"/>. If none of the sets contain elements, the call blocks on the server until elements
136+ /// become available, or the given <paramref name="timeout"/> expires. A <paramref name="timeout"/> of <c>0</c>
137+ /// means to wait indefinitely server-side. Returns <c>null</c> if the server timeout expires.
138+ /// <p/>
139+ /// When using this, pay attention to the timeout configured in the client, on the
140+ /// <see cref="ConnectionMultiplexer"/>, which by default can be too small:
141+ /// <code>
142+ /// ConfigurationOptions configurationOptions = new ConfigurationOptions();
143+ /// configurationOptions.SyncTimeout = 120000; // set a meaningful value here
144+ /// configurationOptions.EndPoints.Add("localhost");
145+ /// ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(configurationOptions);
146+ /// </code>
147+ /// If the connection multiplexer timeout expires in the client, a <c>StackExchange.Redis.RedisTimeoutException</c>
148+ /// is thrown.
149+ /// <p/>
150+ /// This is an extension method added to the <see cref="IDatabase"/> class, for convenience.
151+ /// </summary>
152+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
153+ /// <param name="keys">The keys to check.</param>
154+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
155+ /// <returns>A sorted set entry paired with its score, together with the key it was popped from, or <c>null</c>
156+ /// if the server timeout expires.</returns>
157+ /// <remarks><seealso href="https://redis.io/commands/bzpopmax"/></remarks>
158+ public static Tuple < RedisKey , RedisValueWithScore > ? BzPopMax ( this IDatabase db , RedisKey [ ] keys , double timeout )
159+ {
160+ var command = CoreCommandBuilder . BzPopMax ( keys , timeout ) ;
161+ return db . Execute ( command ) . ToSortedSetPopResult ( ) ;
162+ }
163+
164+ /// <summary>
165+ /// Syntactic sugar for <see cref="BzPopMax(StackExchange.Redis.IDatabase,StackExchange.Redis.RedisKey[],double)"/>,
166+ /// where only one key is used.
167+ /// </summary>
168+ /// <param name="db">The <see cref="IDatabase"/> class where this extension method is applied.</param>
169+ /// <param name="key">The key to check.</param>
170+ /// <param name="timeout">Server-side timeout for the wait. A value of <c>0</c> means to wait indefinitely.</param>
171+ /// <returns>A sorted set entry paired with its score, together with the key it was popped from, or <c>null</c>
172+ /// if the server timeout expires.</returns>
173+ /// <remarks><seealso href="https://redis.io/commands/bzpopmax"/></remarks>
174+ public static Tuple < RedisKey , RedisValueWithScore > ? BzPopMax ( this IDatabase db , RedisKey key , double timeout )
175+ {
176+ return BzPopMax ( db , new [ ] { key } , timeout ) ;
177+ }
22178 }
23179}
0 commit comments