@@ -164,35 +164,21 @@ open class RedisClient : RedisCommandTarget {
164
164
_ = bootstrap. channelOption ( ChannelOptions . reuseAddr, value: 1 )
165
165
166
166
_ = bootstrap. channelInitializer { [ weak self] channel in
167
- #if swift(>=5)
168
- return channel. pipeline
169
- . configureRedisPipeline ( )
170
- . flatMap { [ weak self] in
171
- guard let me = self else {
172
- //assert(self != nil, "bootstrap running, but client gone?!")
173
- let error = channel. eventLoop. makePromise ( of: Void . self)
174
- error. fail ( Error . internalInconsistency)
175
- return error. futureResult
176
- }
177
-
178
- return channel. pipeline
179
- . addHandler ( Handler ( client: me) ,
180
- name: " de.zeezide.nio.redis.client " )
181
- }
182
- #else
167
+
168
+ return channel. pipeline
169
+ . configureRedisPipeline ( )
170
+ . flatMap { [ weak self] in
171
+ guard let me = self else {
172
+ //assert(self != nil, "bootstrap running, but client gone?!")
173
+ let error = channel. eventLoop. makePromise ( of: Void . self)
174
+ error. fail ( Error . internalInconsistency)
175
+ return error. futureResult
176
+ }
177
+
183
178
return channel. pipeline
184
- . configureRedisPipeline ( )
185
- . thenThrowing { [ weak self] in
186
- guard let me = self else {
187
- //assert(self != nil, "bootstrap running, but client gone?!")
188
- throw Error . internalInconsistency
189
- }
190
-
191
- let handler = Handler ( client: me)
192
- _ = channel. pipeline. add ( name: " de.zeezide.nio.redis.client " ,
193
- handler: handler)
194
- }
195
- #endif
179
+ . addHandler ( Handler ( client: me) ,
180
+ name: " de.zeezide.nio.redis.client " )
181
+ }
196
182
}
197
183
}
198
184
#if false
@@ -353,13 +339,8 @@ open class RedisClient : RedisCommandTarget {
353
339
354
340
// MARK: - Commands
355
341
356
- #if swift(>=5)
357
342
var callQueue = CircularBuffer < RedisCommandCall > ( initialCapacity: 16 )
358
343
var pendingCalls = CircularBuffer < RedisCommandCall > ( initialCapacity: 16 )
359
- #else
360
- var callQueue = CircularBuffer < RedisCommandCall > ( initialRingCapacity: 16 )
361
- var pendingCalls = CircularBuffer < RedisCommandCall > ( initialRingCapacity: 16 )
362
- #endif
363
344
364
345
public func enqueueCommandCall( _ call: RedisCommandCall ) { // Q: any
365
346
guard eventLoop. inEventLoop else {
@@ -383,18 +364,10 @@ open class RedisClient : RedisCommandTarget {
383
364
_ = _connect ( host: options. hostname ?? " localhost " , port: options. port)
384
365
385
366
case . requestedQuit, . quit:
386
- #if swift(>=5)
387
- callQueue. forEach { $0. promise. fail ( Error . stopped) }
388
- #else
389
- callQueue. forEach { $0. promise. fail ( error: Error . stopped) }
390
- #endif
367
+ callQueue. forEach { $0. promise. fail ( Error . stopped) }
391
368
392
369
case . error( let error) :
393
- #if swift(>=5)
394
- callQueue. forEach { $0. promise. fail ( error) }
395
- #else
396
- callQueue. forEach { $0. promise. fail ( error: error) }
397
- #endif
370
+ callQueue. forEach { $0. promise. fail ( error) }
398
371
399
372
case . connecting, . authenticating: break
400
373
@@ -412,11 +385,7 @@ open class RedisClient : RedisCommandTarget {
412
385
channel. write ( call. command)
413
386
. map { self . pendingCalls. append ( call) }
414
387
. whenFailure {
415
- #if swift(>=5)
416
- call. promise. fail ( Error . writeError ( $0) )
417
- #else
418
- call. promise. fail ( error: Error . writeError ( $0) )
419
- #endif
388
+ call. promise. fail ( Error . writeError ( $0) )
420
389
}
421
390
}
422
391
channel. flush ( )
@@ -428,19 +397,11 @@ open class RedisClient : RedisCommandTarget {
428
397
if !pendingCalls. isEmpty {
429
398
let call = pendingCalls. removeFirst ( )
430
399
431
- #if swift(>=5)
432
- if !call. command. isSubscribe {
433
- call. promise. succeed ( value)
434
- return
435
- }
436
- call. promise. succeed ( . bulkString( nil ) ) // TBD
437
- #else
438
- if !call. command. isSubscribe {
439
- call. promise. succeed ( result: value)
440
- return
441
- }
442
- call. promise. succeed ( result: . bulkString( nil ) ) // TBD
443
- #endif
400
+ if !call. command. isSubscribe {
401
+ call. promise. succeed ( value)
402
+ return
403
+ }
404
+ call. promise. succeed ( . bulkString( nil ) ) // TBD
444
405
}
445
406
446
407
// PubSub handling
@@ -490,21 +451,12 @@ open class RedisClient : RedisCommandTarget {
490
451
var channel : Channel ? { @inline ( __always) get { return state. channel } }
491
452
492
453
public func quit( ) {
493
- #if swift(>=5)
494
- _enqueueCommandCall ( RedisCommandCall ( [ " QUIT " ] , eventLoop: eventLoop) )
495
- . whenComplete { _ in
496
- self . state = . quit
497
- self . subscribeListeners. removeAll ( )
498
- self . messageListeners. removeAll ( )
499
- }
500
- #else
501
- _enqueueCommandCall ( RedisCommandCall ( [ " QUIT " ] , eventLoop: eventLoop) )
502
- . whenComplete {
503
- self . state = . quit
504
- self . subscribeListeners. removeAll ( )
505
- self . messageListeners. removeAll ( )
506
- }
507
- #endif
454
+ _enqueueCommandCall ( RedisCommandCall ( [ " QUIT " ] , eventLoop: eventLoop) )
455
+ . whenComplete { _ in
456
+ self . state = . quit
457
+ self . subscribeListeners. removeAll ( )
458
+ self . messageListeners. removeAll ( )
459
+ }
508
460
_processQueue ( )
509
461
}
510
462
@@ -675,22 +627,6 @@ open class RedisClient : RedisCommandTarget {
675
627
self . client. handlerCaughtError ( error, in: context)
676
628
_ = context. close ( promise: nil )
677
629
}
678
-
679
- #if swift(>=5) // NIO 2 API - default
680
- #else // NIO 1 API Shims
681
- func channelInactive( ctx context: ChannelHandlerContext ) {
682
- channelInactive ( context: context)
683
- }
684
-
685
- func channelRead( ctx context: ChannelHandlerContext , data: NIOAny ) {
686
- channelRead ( context: context, data: data)
687
- }
688
-
689
- public func errorCaught( ctx context: ChannelHandlerContext , error: Error )
690
- {
691
- errorCaught ( context: context, error: error)
692
- }
693
- #endif // NIO 1 API Shims
694
630
}
695
631
696
632
}
0 commit comments