@@ -19,15 +19,30 @@ public enum NatsKVStorageType
19
19
/// </summary>
20
20
public class NatsKVContext : INatsKVContext
21
21
{
22
- private const string KvStreamNamePrefix = "KV_" ;
22
+ internal const string KvStreamNamePrefix = "KV_" ;
23
23
private static readonly int KvStreamNamePrefixLen = KvStreamNamePrefix . Length ;
24
24
private static readonly Regex ValidBucketRegex = new ( pattern : @"\A[a-zA-Z0-9_-]+\z" , RegexOptions . Compiled ) ;
25
+ private readonly NatsKVOpts _opts ;
25
26
26
27
/// <summary>
27
28
/// Create a new Key Value Store context
28
29
/// </summary>
29
30
/// <param name="context">JetStream context</param>
30
- public NatsKVContext ( INatsJSContext context ) => JetStreamContext = context ;
31
+ /// <param name="opts">Context options</param>
32
+ public NatsKVContext ( INatsJSContext context , NatsKVOpts opts )
33
+ {
34
+ JetStreamContext = context ;
35
+ _opts = opts ;
36
+ }
37
+
38
+ /// <summary>
39
+ /// Create a new Key Value Store context
40
+ /// </summary>
41
+ /// <param name="context">JetStream context</param>
42
+ public NatsKVContext ( INatsJSContext context )
43
+ : this ( context , NatsKVOpts . Default )
44
+ {
45
+ }
31
46
32
47
/// <inheritdoc />
33
48
public INatsJSContext JetStreamContext { get ; }
@@ -45,7 +60,7 @@ public async ValueTask<INatsKVStore> CreateStoreAsync(NatsKVConfig config, Cance
45
60
46
61
var stream = await JetStreamContext . CreateStreamAsync ( streamConfig , cancellationToken ) ;
47
62
48
- return new NatsKVStore ( config . Bucket , JetStreamContext , stream ) ;
63
+ return new NatsKVStore ( config . Bucket , JetStreamContext , stream , _opts ) ;
49
64
}
50
65
51
66
/// <inheritdoc />
@@ -61,7 +76,7 @@ public async ValueTask<INatsKVStore> GetStoreAsync(string bucket, CancellationTo
61
76
}
62
77
63
78
// TODO: KV mirror
64
- return new NatsKVStore ( bucket , JetStreamContext , stream ) ;
79
+ return new NatsKVStore ( bucket , JetStreamContext , stream , _opts ) ;
65
80
}
66
81
67
82
/// <inheritdoc />
@@ -73,7 +88,7 @@ public async ValueTask<INatsKVStore> UpdateStoreAsync(NatsKVConfig config, Cance
73
88
74
89
var stream = await JetStreamContext . UpdateStreamAsync ( streamConfig , cancellationToken ) ;
75
90
76
- return new NatsKVStore ( config . Bucket , JetStreamContext , stream ) ;
91
+ return new NatsKVStore ( config . Bucket , JetStreamContext , stream , _opts ) ;
77
92
}
78
93
79
94
/// <inheritdoc />
@@ -85,7 +100,7 @@ public async ValueTask<INatsKVStore> CreateOrUpdateStoreAsync(NatsKVConfig confi
85
100
86
101
var stream = await JetStreamContext . CreateOrUpdateStreamAsync ( streamConfig , cancellationToken ) ;
87
102
88
- return new NatsKVStore ( config . Bucket , JetStreamContext , stream ) ;
103
+ return new NatsKVStore ( config . Bucket , JetStreamContext , stream , _opts ) ;
89
104
}
90
105
91
106
/// <inheritdoc />
@@ -252,3 +267,10 @@ private static StreamConfig CreateStreamConfig(NatsKVConfig config)
252
267
return streamConfig ;
253
268
}
254
269
}
270
+
271
+ public class NatsKVOpts
272
+ {
273
+ public static readonly NatsKVOpts Default = new ( ) ;
274
+
275
+ public bool UseDirectGetApiWithKeysInSubject { get ; init ; }
276
+ }
0 commit comments