2
2
using NRedisStack . RedisStackCommands ;
3
3
using StackExchange . Redis ;
4
4
5
- namespace NRedisStack ;
6
-
7
- public static class Auxiliary
5
+ namespace NRedisStack
8
6
{
9
- private static string ? _libraryName = $ "NRedisStack(.NET_v{ Environment . Version } )";
10
- private static bool _setInfo = true ;
11
- public static void ResetInfoDefaults ( )
12
- {
13
- _setInfo = true ;
14
- _libraryName = $ "NRedisStack(.NET_v{ Environment . Version } )";
15
- }
16
- public static List < object > MergeArgs ( RedisKey key , params RedisValue [ ] items )
7
+ public static class Auxiliary
17
8
{
18
- var args = new List < object > ( items . Length + 1 ) { key } ;
19
- args . AddRange ( items . Cast < object > ( ) ) ;
20
- return args ;
21
- }
9
+ private static string ? _libraryName = $ "NRedisStack(.NET_v{ Environment . Version } )";
10
+ private static bool _setInfo = true ;
11
+ public static void ResetInfoDefaults ( )
12
+ {
13
+ _setInfo = true ;
14
+ _libraryName = $ "NRedisStack(.NET_v{ Environment . Version } )";
15
+ }
16
+ public static List < object > MergeArgs ( RedisKey key , params RedisValue [ ] items )
17
+ {
18
+ var args = new List < object > ( items . Length + 1 ) { key } ;
19
+ args . AddRange ( items . Cast < object > ( ) ) ;
20
+ return args ;
21
+ }
22
22
23
- public static object [ ] AssembleNonNullArguments ( params object ? [ ] arguments )
24
- {
25
- var args = new List < object > ( ) ;
26
- foreach ( var arg in arguments )
23
+ public static object [ ] AssembleNonNullArguments ( params object ? [ ] arguments )
27
24
{
28
- if ( arg != null )
25
+ var args = new List < object > ( ) ;
26
+ foreach ( var arg in arguments )
29
27
{
30
- args . Add ( arg ) ;
28
+ if ( arg != null )
29
+ {
30
+ args . Add ( arg ) ;
31
+ }
31
32
}
32
- }
33
33
34
- return args . ToArray ( ) ;
35
- }
34
+ return args . ToArray ( ) ;
35
+ }
36
36
37
- // TODO: add all the signatures of GetDatabase
38
- public static IDatabase GetDatabase ( this ConnectionMultiplexer redis ,
39
- string ? LibraryName )
40
- {
41
- var _db = redis . GetDatabase ( ) ;
42
- if ( LibraryName == null ) // the user wants to disable the library name and version sending
43
- _setInfo = false ;
37
+ // TODO: add all the signatures of GetDatabase
38
+ public static IDatabase GetDatabase ( this ConnectionMultiplexer redis ,
39
+ string ? LibraryName )
40
+ {
41
+ var _db = redis . GetDatabase ( ) ;
42
+ if ( LibraryName == null ) // the user wants to disable the library name and version sending
43
+ _setInfo = false ;
44
44
45
- else // the user set his own the library name
46
- _libraryName = $ "NRedisStack({ LibraryName } ;.NET_v{ Environment . Version } )";
45
+ else // the user set his own the library name
46
+ _libraryName = $ "NRedisStack({ LibraryName } ;.NET_v{ Environment . Version } )";
47
47
48
- return _db ;
49
- }
48
+ return _db ;
49
+ }
50
50
51
- internal static void SetInfoInPipeline ( this IDatabase db )
52
- {
53
- if ( _setInfo )
51
+ internal static void SetInfoInPipeline ( this IDatabase db )
54
52
{
55
- _setInfo = false ;
56
- if ( _libraryName == null ) return ;
57
- Pipeline pipeline = new ( db ) ;
58
- _ = pipeline . Db . ClientSetInfoAsync ( SetInfoAttr . LibraryName , _libraryName ) ;
59
- _ = pipeline . Db . ClientSetInfoAsync ( SetInfoAttr . LibraryVersion , GetNRedisStackVersion ( ) ) ;
60
- pipeline . Execute ( ) ;
53
+ if ( _setInfo )
54
+ {
55
+ _setInfo = false ;
56
+ if ( _libraryName == null ) return ;
57
+ Pipeline pipeline = new ( db ) ;
58
+ _ = pipeline . Db . ClientSetInfoAsync ( SetInfoAttr . LibraryName , _libraryName ) ;
59
+ _ = pipeline . Db . ClientSetInfoAsync ( SetInfoAttr . LibraryVersion , GetNRedisStackVersion ( ) ) ;
60
+ pipeline . Execute ( ) ;
61
+ }
61
62
}
62
- }
63
63
64
- public static RedisResult Execute ( this IDatabase db , SerializedCommand command )
65
- {
66
- db . SetInfoInPipeline ( ) ;
67
- return db . Execute ( command . Command , command . Args ) ;
68
- }
69
-
70
- public static async Task < RedisResult > ExecuteAsync ( this IDatabaseAsync db , SerializedCommand command )
71
- {
72
- ( ( IDatabase ) db ) . SetInfoInPipeline ( ) ;
73
- return await db . ExecuteAsync ( command . Command , command . Args ) ;
74
- }
64
+ public static RedisResult Execute ( this IDatabase db , SerializedCommand command )
65
+ {
66
+ db . SetInfoInPipeline ( ) ;
67
+ return db . Execute ( command . Command , command . Args ) ;
68
+ }
75
69
76
- public static List < RedisResult > ExecuteBroadcast ( this IDatabase db , string command )
77
- => db . ExecuteBroadcast ( new SerializedCommand ( command ) ) ;
70
+ public static async Task < RedisResult > ExecuteAsync ( this IDatabaseAsync db , SerializedCommand command )
71
+ {
72
+ ( ( IDatabase ) db ) . SetInfoInPipeline ( ) ;
73
+ return await db . ExecuteAsync ( command . Command , command . Args ) ;
74
+ }
78
75
79
- public static List < RedisResult > ExecuteBroadcast ( this IDatabase db , SerializedCommand command )
80
- {
81
- var redis = db . Multiplexer ;
82
- var endpoints = redis . GetEndPoints ( ) ;
83
- var results = new List < RedisResult > ( endpoints . Length ) ;
76
+ public static List < RedisResult > ExecuteBroadcast ( this IDatabase db , string command )
77
+ => db . ExecuteBroadcast ( new SerializedCommand ( command ) ) ;
84
78
85
- foreach ( var endPoint in endpoints )
79
+ public static List < RedisResult > ExecuteBroadcast ( this IDatabase db , SerializedCommand command )
86
80
{
87
- var server = redis . GetServer ( endPoint ) ;
81
+ var redis = db . Multiplexer ;
82
+ var endpoints = redis . GetEndPoints ( ) ;
83
+ var results = new List < RedisResult > ( endpoints . Length ) ;
88
84
89
- if ( server . IsReplica )
85
+ foreach ( var endPoint in endpoints )
90
86
{
91
- continue ; // Skip replica nodes
92
- }
93
- // Send your command to the master node
87
+ var server = redis . GetServer ( endPoint ) ;
94
88
95
- results . Add ( server . Multiplexer . GetDatabase ( ) . Execute ( command ) ) ;
96
- }
97
- return results ;
98
- }
89
+ if ( server . IsReplica )
90
+ {
91
+ continue ; // Skip replica nodes
92
+ }
93
+ // Send your command to the master node
99
94
100
- public static async Task < List < RedisResult > > ExecuteBroadcastAsync ( this IDatabaseAsync db , string command )
101
- => await db . ExecuteBroadcastAsync ( new SerializedCommand ( command ) ) ;
95
+ results . Add ( server . Multiplexer . GetDatabase ( ) . Execute ( command ) ) ;
96
+ }
97
+ return results ;
98
+ }
102
99
103
- private static async Task < List < RedisResult > > ExecuteBroadcastAsync ( this IDatabaseAsync db , SerializedCommand command )
104
- {
105
- var redis = db . Multiplexer ;
106
- var endpoints = redis . GetEndPoints ( ) ;
107
- var results = new List < RedisResult > ( endpoints . Length ) ;
100
+ public static async Task < List < RedisResult > > ExecuteBroadcastAsync ( this IDatabaseAsync db , string command )
101
+ => await db . ExecuteBroadcastAsync ( new SerializedCommand ( command ) ) ;
108
102
109
- foreach ( var endPoint in endpoints )
103
+ private static async Task < List < RedisResult > > ExecuteBroadcastAsync ( this IDatabaseAsync db , SerializedCommand command )
110
104
{
111
- var server = redis . GetServer ( endPoint ) ;
105
+ var redis = db . Multiplexer ;
106
+ var endpoints = redis . GetEndPoints ( ) ;
107
+ var results = new List < RedisResult > ( endpoints . Length ) ;
112
108
113
- if ( server . IsReplica )
109
+ foreach ( var endPoint in endpoints )
114
110
{
115
- continue ; // Skip replica nodes
116
- }
117
- // Send your command to the master node
111
+ var server = redis . GetServer ( endPoint ) ;
112
+
113
+ if ( server . IsReplica )
114
+ {
115
+ continue ; // Skip replica nodes
116
+ }
117
+ // Send your command to the master node
118
118
119
- results . Add ( await server . Multiplexer . GetDatabase ( ) . ExecuteAsync ( command ) ) ;
119
+ results . Add ( await server . Multiplexer . GetDatabase ( ) . ExecuteAsync ( command ) ) ;
120
+ }
121
+ return results ;
120
122
}
121
- return results ;
122
- }
123
123
124
- public static string GetNRedisStackVersion ( )
125
- {
126
- Version version = typeof ( Auxiliary ) . Assembly . GetName ( ) . Version ! ;
127
- return $ "{ version . Major } .{ version . Minor } .{ version . Build } ";
124
+ public static string GetNRedisStackVersion ( )
125
+ {
126
+ Version version = typeof ( Auxiliary ) . Assembly . GetName ( ) . Version ! ;
127
+ return $ "{ version . Major } .{ version . Minor } .{ version . Build } ";
128
+ }
128
129
}
129
130
}
0 commit comments