Skip to content

Commit 74faeff

Browse files
authored
Merge branch 'main' into currantw/password_update_api
2 parents b6ad7ec + 1308018 commit 74faeff

14 files changed

+265
-250
lines changed

sources/Valkey.Glide/Abstract/Database.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<ValkeyResult> ExecuteAsync(string command, params object[] arg
4646

4747
public async Task<ValkeyResult> ExecuteAsync(string command, ICollection<object>? args, CommandFlags flags = CommandFlags.None)
4848
{
49-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
49+
GuardClauses.ThrowIfCommandFlags(flags);
5050
object? res = await Command(Request.CustomCommand([command, .. args?.Select(a => a.ToString()!) ?? []]));
5151
return ValkeyResult.Create(res);
5252
}

sources/Valkey.Glide/Abstract/ValkeyServer.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public ValkeyResult Execute(string command, ICollection<object> args, CommandFla
3030

3131
public async Task<ValkeyResult> ExecuteAsync(string command, ICollection<object> args, CommandFlags flags = CommandFlags.None)
3232
{
33-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
33+
GuardClauses.ThrowIfCommandFlags(flags);
3434
object? res = await _conn.Command(Request.CustomCommand([command, .. args?.Select(a => a.ToString()!) ?? []]), MakeRoute());
3535
return ValkeyResult.Create(res);
3636
}
@@ -53,7 +53,7 @@ private Route MakeRoute()
5353

5454
public Task<string?> InfoRawAsync(ValkeyValue section = default, CommandFlags flags = CommandFlags.None)
5555
{
56-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
56+
GuardClauses.ThrowIfCommandFlags(flags);
5757
InfoOptions.Section[] sections = section.Type == ValkeyValue.StorageType.Null ? [] :
5858
[Enum.Parse<InfoOptions.Section>(section.ToString(), true)];
5959

@@ -71,91 +71,91 @@ public Task<IGrouping<string, KeyValuePair<string, string>>[]> InfoAsync(ValkeyV
7171

7272
public async Task<TimeSpan> PingAsync(CommandFlags flags = CommandFlags.None)
7373
{
74-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
74+
GuardClauses.ThrowIfCommandFlags(flags);
7575
return await _conn.Command(Request.Ping(), MakeRoute());
7676
}
7777

7878
public async Task<TimeSpan> PingAsync(ValkeyValue message, CommandFlags flags = CommandFlags.None)
7979
{
80-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
80+
GuardClauses.ThrowIfCommandFlags(flags);
8181
return await _conn.Command(Request.Ping(message), MakeRoute());
8282
}
8383

8484
public async Task<ValkeyValue> EchoAsync(ValkeyValue message, CommandFlags flags = CommandFlags.None)
8585
{
86-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
86+
GuardClauses.ThrowIfCommandFlags(flags);
8787
return await _conn.Command(Request.Echo(message), MakeRoute());
8888
}
8989

9090
public async Task<ValkeyValue> ClientGetNameAsync(CommandFlags flags = CommandFlags.None)
9191
{
92-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
92+
GuardClauses.ThrowIfCommandFlags(flags);
9393
return await _conn.Command(Request.ClientGetName(), MakeRoute());
9494
}
9595

9696
public async Task<long> ClientIdAsync(CommandFlags flags = CommandFlags.None)
9797
{
98-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
98+
GuardClauses.ThrowIfCommandFlags(flags);
9999
return await _conn.Command(Request.ClientId(), MakeRoute());
100100
}
101101

102102
public async Task<KeyValuePair<string, string>[]> ConfigGetAsync(ValkeyValue pattern = default, CommandFlags flags = CommandFlags.None)
103103
{
104-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
104+
GuardClauses.ThrowIfCommandFlags(flags);
105105
return await _conn.Command(Request.ConfigGetAsync(pattern), MakeRoute());
106106
}
107107

108108
public async Task ConfigResetStatisticsAsync(CommandFlags flags = CommandFlags.None)
109109
{
110-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
110+
GuardClauses.ThrowIfCommandFlags(flags);
111111
_ = await _conn.Command(Request.ConfigResetStatisticsAsync(), MakeRoute());
112112
}
113113

114114
public async Task ConfigRewriteAsync(CommandFlags flags = CommandFlags.None)
115115
{
116-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
116+
GuardClauses.ThrowIfCommandFlags(flags);
117117
_ = await _conn.Command(Request.ConfigRewriteAsync(), MakeRoute());
118118
}
119119

120120
public async Task ConfigSetAsync(ValkeyValue setting, ValkeyValue value, CommandFlags flags = CommandFlags.None)
121121
{
122-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
122+
GuardClauses.ThrowIfCommandFlags(flags);
123123
_ = await _conn.Command(Request.ConfigSetAsync(setting, value), MakeRoute());
124124
}
125125

126126
public async Task<long> DatabaseSizeAsync(int database = -1, CommandFlags flags = CommandFlags.None)
127127
{
128-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
128+
GuardClauses.ThrowIfCommandFlags(flags);
129129
return await _conn.Command(Request.DatabaseSizeAsync(database), MakeRoute());
130130
}
131131

132132
public async Task FlushAllDatabasesAsync(CommandFlags flags = CommandFlags.None)
133133
{
134-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
134+
GuardClauses.ThrowIfCommandFlags(flags);
135135
_ = await _conn.Command(Request.FlushAllDatabasesAsync(), MakeRoute());
136136
}
137137

138138
public async Task FlushDatabaseAsync(int database = -1, CommandFlags flags = CommandFlags.None)
139139
{
140-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
140+
GuardClauses.ThrowIfCommandFlags(flags);
141141
_ = await _conn.Command(Request.FlushDatabaseAsync(database), MakeRoute());
142142
}
143143

144144
public async Task<DateTime> LastSaveAsync(CommandFlags flags = CommandFlags.None)
145145
{
146-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
146+
GuardClauses.ThrowIfCommandFlags(flags);
147147
return await _conn.Command(Request.LastSaveAsync(), MakeRoute());
148148
}
149149

150150
public async Task<DateTime> TimeAsync(CommandFlags flags = CommandFlags.None)
151151
{
152-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
152+
GuardClauses.ThrowIfCommandFlags(flags);
153153
return await _conn.Command(Request.TimeAsync(), MakeRoute());
154154
}
155155

156156
public async Task<string> LolwutAsync(CommandFlags flags = CommandFlags.None)
157157
{
158-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
158+
GuardClauses.ThrowIfCommandFlags(flags);
159159
return await _conn.Command(Request.LolwutAsync(), MakeRoute());
160160
}
161161
}

sources/Valkey.Glide/Abstract/ValkeyTransaction.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
22

3+
using Valkey.Glide.Internals;
4+
35
namespace Valkey.Glide;
46

57
internal class ValkeyTransaction : ValkeyBatch, ITransaction
@@ -24,7 +26,7 @@ public bool Execute(CommandFlags flags = CommandFlags.None)
2426

2527
public async Task<bool> ExecuteAsync(CommandFlags flags = CommandFlags.None)
2628
{
27-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
29+
GuardClauses.ThrowIfCommandFlags(flags);
2830
await ExecuteImpl();
2931
return _tcs.Task.Result is not null;
3032
}

sources/Valkey.Glide/BaseClient.GenericCommands.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,37 @@ public abstract partial class BaseClient : IGenericBaseCommands
1010
{
1111
public async Task<bool> KeyDeleteAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
1212
{
13-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
13+
GuardClauses.ThrowIfCommandFlags(flags);
1414
return await Command(Request.KeyDeleteAsync(key));
1515
}
1616

1717
public async Task<long> KeyDeleteAsync(ValkeyKey[] keys, CommandFlags flags = CommandFlags.None)
1818
{
19-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
19+
GuardClauses.ThrowIfCommandFlags(flags);
2020
return await Command(Request.KeyDeleteAsync(keys));
2121
}
2222

2323
public async Task<bool> KeyUnlinkAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
2424
{
25-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
25+
GuardClauses.ThrowIfCommandFlags(flags);
2626
return await Command(Request.KeyUnlinkAsync(key));
2727
}
2828

2929
public async Task<long> KeyUnlinkAsync(ValkeyKey[] keys, CommandFlags flags = CommandFlags.None)
3030
{
31-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
31+
GuardClauses.ThrowIfCommandFlags(flags);
3232
return await Command(Request.KeyUnlinkAsync(keys));
3333
}
3434

3535
public async Task<bool> KeyExistsAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
3636
{
37-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
37+
GuardClauses.ThrowIfCommandFlags(flags);
3838
return await Command(Request.KeyExistsAsync(key));
3939
}
4040

4141
public async Task<long> KeyExistsAsync(ValkeyKey[] keys, CommandFlags flags = CommandFlags.None)
4242
{
43-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
43+
GuardClauses.ThrowIfCommandFlags(flags);
4444
return await Command(Request.KeyExistsAsync(keys));
4545
}
4646

@@ -49,7 +49,7 @@ public async Task<bool> KeyExpireAsync(ValkeyKey key, TimeSpan? expiry, CommandF
4949

5050
public async Task<bool> KeyExpireAsync(ValkeyKey key, TimeSpan? expiry, ExpireWhen when, CommandFlags flags = CommandFlags.None)
5151
{
52-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
52+
GuardClauses.ThrowIfCommandFlags(flags);
5353
return await Command(Request.KeyExpireAsync(key, expiry, when));
5454
}
5555

@@ -58,138 +58,138 @@ public async Task<bool> KeyExpireAsync(ValkeyKey key, DateTime? expiry, CommandF
5858

5959
public async Task<bool> KeyExpireAsync(ValkeyKey key, DateTime? expiry, ExpireWhen when, CommandFlags flags = CommandFlags.None)
6060
{
61-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
61+
GuardClauses.ThrowIfCommandFlags(flags);
6262
return await Command(Request.KeyExpireAsync(key, expiry, when));
6363
}
6464

6565
public async Task<TimeSpan?> KeyTimeToLiveAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
6666
{
67-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
67+
GuardClauses.ThrowIfCommandFlags(flags);
6868
return await Command(Request.KeyTimeToLiveAsync(key));
6969
}
7070

7171
public async Task<ValkeyType> KeyTypeAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
7272
{
73-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
73+
GuardClauses.ThrowIfCommandFlags(flags);
7474
return await Command(Request.KeyTypeAsync(key));
7575
}
7676

7777
public async Task<bool> KeyRenameAsync(ValkeyKey key, ValkeyKey newKey, CommandFlags flags = CommandFlags.None)
7878
{
79-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
79+
GuardClauses.ThrowIfCommandFlags(flags);
8080
return await Command(Request.KeyRenameAsync(key, newKey));
8181
}
8282

8383
public async Task<bool> KeyRenameNXAsync(ValkeyKey key, ValkeyKey newKey, CommandFlags flags = CommandFlags.None)
8484
{
85-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
85+
GuardClauses.ThrowIfCommandFlags(flags);
8686
return await Command(Request.KeyRenameNXAsync(key, newKey));
8787
}
8888

8989
public async Task<bool> KeyPersistAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
9090
{
91-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
91+
GuardClauses.ThrowIfCommandFlags(flags);
9292
return await Command(Request.KeyPersistAsync(key));
9393
}
9494

9595
public async Task<byte[]?> KeyDumpAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
9696
{
97-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
97+
GuardClauses.ThrowIfCommandFlags(flags);
9898
return await Command(Request.KeyDumpAsync(key));
9999
}
100100

101101
public async Task KeyRestoreAsync(ValkeyKey key, byte[] value, TimeSpan? expiry = null, RestoreOptions? restoreOptions = null, CommandFlags flags = CommandFlags.None)
102102
{
103-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
103+
GuardClauses.ThrowIfCommandFlags(flags);
104104
_ = await Command(Request.KeyRestoreAsync(key, value, expiry, restoreOptions));
105105
}
106106

107107
public async Task KeyRestoreDateTimeAsync(ValkeyKey key, byte[] value, DateTime? expiry = null, RestoreOptions? restoreOptions = null, CommandFlags flags = CommandFlags.None)
108108
{
109-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
109+
GuardClauses.ThrowIfCommandFlags(flags);
110110
_ = await Command(Request.KeyRestoreDateTimeAsync(key, value, expiry, restoreOptions));
111111
}
112112

113113
public async Task<bool> KeyTouchAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
114114
{
115-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
115+
GuardClauses.ThrowIfCommandFlags(flags);
116116
return await Command(Request.KeyTouchAsync(key));
117117
}
118118

119119
public async Task<long> KeyTouchAsync(ValkeyKey[] keys, CommandFlags flags = CommandFlags.None)
120120
{
121-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
121+
GuardClauses.ThrowIfCommandFlags(flags);
122122
return await Command(Request.KeyTouchAsync(keys));
123123
}
124124

125125
public async Task<DateTime?> KeyExpireTimeAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
126126
{
127-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
127+
GuardClauses.ThrowIfCommandFlags(flags);
128128
return await Command(Request.KeyExpireTimeAsync(key));
129129
}
130130

131131
public async Task<string?> KeyEncodingAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
132132
{
133-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
133+
GuardClauses.ThrowIfCommandFlags(flags);
134134
return await Command(Request.KeyEncodingAsync(key));
135135
}
136136

137137
public async Task<long?> KeyFrequencyAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
138138
{
139-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
139+
GuardClauses.ThrowIfCommandFlags(flags);
140140
return await Command(Request.KeyFrequencyAsync(key));
141141
}
142142

143143
public async Task<long?> KeyIdleTimeAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
144144
{
145-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
145+
GuardClauses.ThrowIfCommandFlags(flags);
146146
return await Command(Request.KeyIdleTimeAsync(key));
147147
}
148148

149149
public async Task<long?> KeyRefCountAsync(ValkeyKey key, CommandFlags flags = CommandFlags.None)
150150
{
151-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
151+
GuardClauses.ThrowIfCommandFlags(flags);
152152
return await Command(Request.KeyRefCountAsync(key));
153153
}
154154

155155
public async Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, bool replace = false, CommandFlags flags = CommandFlags.None)
156156
{
157-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
157+
GuardClauses.ThrowIfCommandFlags(flags);
158158
return await Command(Request.KeyCopyAsync(sourceKey, destinationKey, replace));
159159
}
160160

161161
public async Task<bool> KeyMoveAsync(ValkeyKey key, int database, CommandFlags flags = CommandFlags.None)
162162
{
163-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
163+
GuardClauses.ThrowIfCommandFlags(flags);
164164
return await Command(Request.KeyMoveAsync(key, database));
165165
}
166166

167167
public async Task<bool> KeyCopyAsync(ValkeyKey sourceKey, ValkeyKey destinationKey, int destinationDatabase, bool replace = false, CommandFlags flags = CommandFlags.None)
168168
{
169-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
169+
GuardClauses.ThrowIfCommandFlags(flags);
170170
return await Command(Request.KeyCopyAsync(sourceKey, destinationKey, destinationDatabase, replace));
171171
}
172172
public async Task<string?> KeyRandomAsync(CommandFlags flags = CommandFlags.None)
173173
{
174-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
174+
GuardClauses.ThrowIfCommandFlags(flags);
175175
return await Command(Request.KeyRandomAsync());
176176
}
177177

178178
public async Task<ValkeyValue[]> SortAsync(ValkeyKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, ValkeyValue by = default, ValkeyValue[]? get = null, CommandFlags flags = CommandFlags.None)
179179
{
180-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
180+
GuardClauses.ThrowIfCommandFlags(flags);
181181
return await Command(Request.SortAsync(key, skip, take, order, sortType, by, get, await GetServerVersionAsync()));
182182
}
183183

184184
public async Task<long> SortAndStoreAsync(ValkeyKey destination, ValkeyKey key, long skip = 0, long take = -1, Order order = Order.Ascending, SortType sortType = SortType.Numeric, ValkeyValue by = default, ValkeyValue[]? get = null, CommandFlags flags = CommandFlags.None)
185185
{
186-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
186+
GuardClauses.ThrowIfCommandFlags(flags);
187187
return await Command(Request.SortAndStoreAsync(destination, key, skip, take, order, sortType, by, get));
188188
}
189189

190190
public async Task<long> WaitAsync(long numreplicas, long timeout, CommandFlags flags = CommandFlags.None)
191191
{
192-
Utils.Requires<NotImplementedException>(flags == CommandFlags.None, "Command flags are not supported by GLIDE");
192+
GuardClauses.ThrowIfCommandFlags(flags);
193193
return await Command(Request.WaitAsync(numreplicas, timeout));
194194
}
195195

0 commit comments

Comments
 (0)