@@ -5,7 +5,7 @@ final class BasicCommandsTests: XCTestCase {
5
5
private let redis = RedisDriver ( ownershipModel: . internal( threadCount: 1 ) )
6
6
deinit { try ? redis. terminate ( ) }
7
7
8
- private var connection : RedisConnection ?
8
+ private var connection : RedisConnection !
9
9
10
10
override func setUp( ) {
11
11
do {
@@ -16,222 +16,113 @@ final class BasicCommandsTests: XCTestCase {
16
16
}
17
17
18
18
override func tearDown( ) {
19
- _ = try ? connection? . send ( command: " FLUSHALL " ) . wait ( )
20
- connection? . close ( )
19
+ _ = try ? connection. send ( command: " FLUSHALL " ) . wait ( )
20
+ connection. close ( )
21
21
connection = nil
22
22
}
23
23
24
24
func test_select( ) {
25
- XCTAssertNoThrow ( try connection? . select ( database: 3 ) . wait ( ) )
25
+ XCTAssertNoThrow ( try connection. select ( database: 3 ) . wait ( ) )
26
26
}
27
27
28
28
func test_delete( ) throws {
29
29
let keys = [ #function + " 1 " , #function + " 2 " , #function + " 3 " ]
30
- try connection? . set ( keys [ 0 ] , to: " value " ) . wait ( )
31
- try connection? . set ( keys [ 1 ] , to: " value " ) . wait ( )
32
- try connection? . set ( keys [ 2 ] , to: " value " ) . wait ( )
30
+ try connection. set ( keys [ 0 ] , to: " value " ) . wait ( )
31
+ try connection. set ( keys [ 1 ] , to: " value " ) . wait ( )
32
+ try connection. set ( keys [ 2 ] , to: " value " ) . wait ( )
33
33
34
- let first = try connection? . delete ( keys [ 0 ] ) . wait ( )
34
+ let first = try connection. delete ( [ keys [ 0 ] ] ) . wait ( )
35
35
XCTAssertEqual ( first, 1 )
36
36
37
- let second = try connection? . delete ( keys [ 0 ] ) . wait ( )
37
+ let second = try connection. delete ( [ keys [ 0 ] ] ) . wait ( )
38
38
XCTAssertEqual ( second, 0 )
39
39
40
- let third = try connection? . delete ( keys [ 1 ] , keys [ 2 ] ) . wait ( )
40
+ let third = try connection. delete ( [ keys [ 1 ] , keys [ 2 ] ] ) . wait ( )
41
41
XCTAssertEqual ( third, 2 )
42
42
}
43
43
44
- func test_set( ) {
45
- XCTAssertNoThrow ( try connection? . set ( #function, to: " value " ) . wait ( ) )
46
- }
47
-
48
- func test_get( ) throws {
49
- try connection? . set ( #function, to: " value " ) . wait ( )
50
- let result = try connection? . get ( #function) . wait ( )
51
- XCTAssertEqual ( result, " value " )
52
- }
53
-
54
44
func test_expire( ) throws {
55
- try connection? . set ( #function, to: " value " ) . wait ( )
56
- let before = try connection? . get ( #function) . wait ( )
45
+ try connection. set ( #function, to: " value " ) . wait ( )
46
+ let before = try connection. get ( #function) . wait ( )
57
47
XCTAssertNotNil ( before)
58
48
59
- let result = try connection? . expire ( #function, after: 0 ) . wait ( )
49
+ let result = try connection. expire ( #function, after: . nanoseconds ( 1 ) ) . wait ( )
60
50
XCTAssertEqual ( result, true )
61
51
62
- let after = try connection? . get ( #function) . wait ( )
52
+ let after = try connection. get ( #function) . wait ( )
63
53
XCTAssertNil ( after)
64
54
}
65
55
66
56
func test_ping( ) throws {
67
- let first = try connection? . ping ( ) . wait ( )
57
+ let first = try connection. ping ( ) . wait ( )
68
58
XCTAssertEqual ( first, " PONG " )
69
59
70
- let second = try connection? . ping ( with: " My message " ) . wait ( )
60
+ let second = try connection. ping ( with: " My message " ) . wait ( )
71
61
XCTAssertEqual ( second, " My message " )
72
62
}
73
63
74
64
func test_echo( ) throws {
75
- let response = try connection? . echo ( " FIZZ_BUZZ " ) . wait ( )
65
+ let response = try connection. echo ( " FIZZ_BUZZ " ) . wait ( )
76
66
XCTAssertEqual ( response, " FIZZ_BUZZ " )
77
67
}
78
68
79
- func test_swapdb ( ) throws {
80
- try connection? . set ( " first " , to: " 3 " ) . wait ( )
81
- var first = try connection? . get ( " first " ) . wait ( )
69
+ func test_swapDatabase ( ) throws {
70
+ try connection. set ( " first " , to: " 3 " ) . wait ( )
71
+ var first = try connection. get ( " first " ) . wait ( )
82
72
XCTAssertEqual ( first, " 3 " )
83
73
84
- try connection? . select ( database: 1 ) . wait ( )
85
- var second = try connection? . get ( " first " ) . wait ( )
74
+ try connection. select ( database: 1 ) . wait ( )
75
+ var second = try connection. get ( " first " ) . wait ( )
86
76
XCTAssertEqual ( second, nil )
87
77
88
- try connection? . set ( " second " , to: " 100 " ) . wait ( )
89
- second = try connection? . get ( " second " ) . wait ( )
78
+ try connection. set ( " second " , to: " 100 " ) . wait ( )
79
+ second = try connection. get ( " second " ) . wait ( )
90
80
XCTAssertEqual ( second, " 100 " )
91
81
92
- let success = try connection? . swapdb ( firstIndex : 0 , secondIndex : 1 ) . wait ( )
82
+ let success = try connection. swapDatabase ( 0 , with : 1 ) . wait ( )
93
83
XCTAssertEqual ( success, true )
94
84
95
- second = try connection? . get ( " first " ) . wait ( )
85
+ second = try connection. get ( " first " ) . wait ( )
96
86
XCTAssertEqual ( second, " 3 " )
97
87
98
- try connection? . select ( database: 0 ) . wait ( )
99
- first = try connection? . get ( " second " ) . wait ( )
88
+ try connection. select ( database: 0 ) . wait ( )
89
+ first = try connection. get ( " second " ) . wait ( )
100
90
XCTAssertEqual ( first, " 100 " )
101
91
}
102
92
103
- func test_increment( ) throws {
104
- var result = try connection? . increment ( #function) . wait ( )
105
- XCTAssertEqual ( result, 1 )
106
- result = try connection? . increment ( #function) . wait ( )
107
- XCTAssertEqual ( result, 2 )
108
- }
109
-
110
- func test_incrementBy( ) throws {
111
- var result = try connection? . increment ( #function, by: 10 ) . wait ( )
112
- XCTAssertEqual ( result, 10 )
113
- result = try connection? . increment ( #function, by: - 3 ) . wait ( )
114
- XCTAssertEqual ( result, 7 )
115
- result = try connection? . increment ( #function, by: 0 ) . wait ( )
116
- XCTAssertEqual ( result, 7 )
117
- }
118
-
119
- func test_incrementByFloat( ) throws {
120
- var float = try connection? . increment ( #function, by: Float ( 3.0 ) ) . wait ( )
121
- XCTAssertEqual ( float, 3.0 )
122
- float = try connection? . increment ( #function, by: Float ( - 10.135901 ) ) . wait ( )
123
- XCTAssertEqual ( float, - 7.135901 )
124
-
125
- var double = try connection? . increment ( #function, by: Double ( 10.2839 ) ) . wait ( )
126
- XCTAssertEqual ( double, 3.147999 )
127
- double = try connection? . increment ( #function, by: Double ( 15.2938 ) ) . wait ( )
128
- XCTAssertEqual ( double, 18.441799 )
129
- }
130
-
131
- func test_decrement( ) throws {
132
- var result = try connection? . decrement ( #function) . wait ( )
133
- XCTAssertEqual ( result, - 1 )
134
- result = try connection? . decrement ( #function) . wait ( )
135
- XCTAssertEqual ( result, - 2 )
136
- }
137
-
138
- func test_decrementBy( ) throws {
139
- var result = try connection? . decrement ( #function, by: - 10 ) . wait ( )
140
- XCTAssertEqual ( result, 10 )
141
- result = try connection? . decrement ( #function, by: 3 ) . wait ( )
142
- XCTAssertEqual ( result, 7 )
143
- result = try connection? . decrement ( #function, by: 0 ) . wait ( )
144
- XCTAssertEqual ( result, 7 )
145
- }
146
-
147
- func test_mget( ) throws {
148
- let keys = [ " one " , " two " ]
149
- try keys. forEach { _ = try connection? . set ( $0, to: $0) . wait ( ) }
150
-
151
- let values = try connection? . mget ( keys + [ " empty " ] ) . wait ( )
152
- XCTAssertEqual ( values? . count, 3 )
153
- XCTAssertEqual ( values ? [ 0 ] . string, " one " )
154
- XCTAssertEqual ( values ? [ 1 ] . string, " two " )
155
- XCTAssertEqual ( values ? [ 2 ] . isNull, true )
156
-
157
- XCTAssertEqual ( try connection? . mget ( [ " empty " , #function] ) . wait ( ) . count, 2 )
158
- }
159
-
160
- func test_mset( ) throws {
161
- let data = [
162
- " first " : 1 ,
163
- " second " : 2
164
- ]
165
- XCTAssertNoThrow ( try connection? . mset ( data) . wait ( ) )
166
- let values = try connection? . mget ( [ " first " , " second " ] ) . wait ( ) . compactMap { $0. string }
167
- XCTAssertEqual ( values? . count, 2 )
168
- XCTAssertEqual ( values ? [ 0 ] , " 1 " )
169
- XCTAssertEqual ( values ? [ 1 ] , " 2 " )
170
-
171
- XCTAssertNoThrow ( try connection? . mset ( [ " first " : 10 ] ) . wait ( ) )
172
- let val = try connection? . get ( " first " ) . wait ( )
173
- XCTAssertEqual ( val, " 10 " )
174
- }
175
-
176
- func test_msetnx( ) throws {
177
- let data = [
178
- " first " : 1 ,
179
- " second " : 2
180
- ]
181
- var success = try connection? . msetnx ( data) . wait ( )
182
- XCTAssertEqual ( success, true )
183
-
184
- success = try connection? . msetnx ( [ " first " : 10 , " second " : 20 ] ) . wait ( )
185
- XCTAssertEqual ( success, false )
186
-
187
- let values = try connection? . mget ( [ " first " , " second " ] ) . wait ( ) . compactMap { $0. string }
188
- XCTAssertEqual ( values ? [ 0 ] , " 1 " )
189
- XCTAssertEqual ( values ? [ 1 ] , " 2 " )
190
- }
191
-
192
93
func test_scan( ) throws {
193
94
var dataset : [ String ] = . init( repeating: " " , count: 10 )
194
95
for index in 1 ... 15 {
195
96
let key = " key \( index) \( index % 2 == 0 ? " _even " : " _odd " ) "
196
97
dataset. append ( key)
197
- _ = try connection? . set ( key, to: " \( index) " ) . wait ( )
98
+ _ = try connection. set ( key, to: " \( index) " ) . wait ( )
198
99
}
199
100
200
- var ( cursor, keys) = try connection? . scan ( count: 5 ) . wait ( ) ?? ( 0 , [ ] )
101
+ var ( cursor, keys) = try connection. scan ( count: 5 ) . wait ( )
201
102
XCTAssertGreaterThanOrEqual ( cursor, 0 )
202
103
XCTAssertGreaterThanOrEqual ( keys. count, 5 )
203
104
204
- ( _, keys) = try connection? . scan ( startingFrom: cursor, count: 8 ) . wait ( ) ?? ( 0 , [ ] )
105
+ ( _, keys) = try connection. scan ( startingFrom: cursor, count: 8 ) . wait ( )
205
106
XCTAssertGreaterThanOrEqual ( keys. count, 8 )
206
107
207
- ( cursor, keys) = try connection? . scan ( matching: " *_odd " ) . wait ( ) ?? ( 0 , [ ] )
108
+ ( cursor, keys) = try connection. scan ( matching: " *_odd " ) . wait ( )
208
109
XCTAssertGreaterThanOrEqual ( cursor, 0 )
209
110
XCTAssertGreaterThanOrEqual ( keys. count, 1 )
210
111
XCTAssertLessThanOrEqual ( keys. count, 7 )
211
112
212
- ( cursor, keys) = try connection? . scan ( matching: " *_even* " ) . wait ( ) ?? ( 0 , [ ] )
113
+ ( cursor, keys) = try connection. scan ( matching: " *_even* " ) . wait ( )
213
114
XCTAssertGreaterThanOrEqual ( cursor, 0 )
214
115
XCTAssertGreaterThanOrEqual ( keys. count, 1 )
215
116
XCTAssertLessThanOrEqual ( keys. count, 7 )
216
117
}
217
118
218
119
static var allTests = [
219
120
( " test_select " , test_select) ,
220
- ( " test_set " , test_set) ,
221
- ( " test_get " , test_get) ,
222
121
( " test_expire " , test_expire) ,
223
122
( " test_delete " , test_delete) ,
224
123
( " test_ping " , test_ping) ,
225
124
( " test_echo " , test_echo) ,
226
- ( " test_swapdb " , test_swapdb) ,
227
- ( " test_increment " , test_increment) ,
228
- ( " test_incrementBy " , test_incrementBy) ,
229
- ( " test_incrementByFloat " , test_incrementByFloat) ,
230
- ( " test_decrement " , test_decrement) ,
231
- ( " test_decrementBy " , test_decrementBy) ,
232
- ( " test_mget " , test_mget) ,
233
- ( " test_mset " , test_mset) ,
234
- ( " test_msetnx " , test_msetnx) ,
125
+ ( " test_swapDatabase " , test_swapDatabase) ,
235
126
( " test_scan " , test_scan) ,
236
127
]
237
128
}
0 commit comments