Skip to content

Commit c4ff3fc

Browse files
committed
Rename ELF extension map to tryConverting and make internal
Motivation: As originally pointed out in #48, the `map` prefix alone is not enough context into what the method actually does. Since it fails the future, and isn't a mapping function, the name should reflect this. But, this method as-is currently provides little value outside of the client context, so it should not be `public`. If users provide an adequate use case for having it outside of the package, then it can be made public again. Modifications: - Rename: ELF where Value == RESPValue extension `map` to `tryConverting` - Change: `tryConverting` from public to internal Result: A "problematic" method should no longer be available for API users to hurt themselves with.
1 parent 8b75ef7 commit c4ff3fc

File tree

7 files changed

+79
-79
lines changed

7 files changed

+79
-79
lines changed

Sources/RediStack/Commands/BasicCommands.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension RedisClient {
2323
public func echo(_ message: String) -> EventLoopFuture<String> {
2424
let args = [RESPValue(bulk: message)]
2525
return send(command: "ECHO", with: args)
26-
.map()
26+
.tryConverting()
2727
}
2828

2929
/// Pings the server, which will respond with a message.
@@ -36,7 +36,7 @@ extension RedisClient {
3636
? [.init(bulk: message!)] // safe because we did a nil pre-check
3737
: []
3838
return send(command: "PING", with: args)
39-
.map()
39+
.tryConverting()
4040
}
4141

4242
/// Select the Redis logical database having the specified zero-based numeric index.
@@ -64,7 +64,7 @@ extension RedisClient {
6464
.init(bulk: second)
6565
]
6666
return send(command: "SWAPDB", with: args)
67-
.map(to: String.self)
67+
.tryConverting(to: String.self)
6868
.map { return $0 == "OK" }
6969
}
7070

@@ -89,7 +89,7 @@ extension RedisClient {
8989

9090
let args = keys.map(RESPValue.init)
9191
return send(command: "DEL", with: args)
92-
.map()
92+
.tryConverting()
9393
}
9494

9595
/// Removes the specified keys. A key is ignored if it does not exist.
@@ -111,7 +111,7 @@ extension RedisClient {
111111
RESPValue(from: $0)
112112
}
113113
return self.send(command: "EXISTS", with: args)
114-
.map(to: Int.self)
114+
.tryConverting(to: Int.self)
115115
}
116116

117117
/// Checks the existence of the provided keys in the database.
@@ -137,7 +137,7 @@ extension RedisClient {
137137
.init(bulk: timeout.seconds)
138138
]
139139
return send(command: "EXPIRE", with: args)
140-
.map(to: Int.self)
140+
.tryConverting(to: Int.self)
141141
.map { return $0 == 1 }
142142
}
143143
}
@@ -153,7 +153,7 @@ extension RedisClient {
153153
public func ttl(_ key: RedisKey) -> EventLoopFuture<RedisKeyLifetime> {
154154
let args: [RESPValue] = [RESPValue(from: key)]
155155
return self.send(command: "TTL", with: args)
156-
.map(to: Int64.self)
156+
.tryConverting(to: Int64.self)
157157
.map { RedisKeyLifetime(seconds: $0) }
158158
}
159159

@@ -165,7 +165,7 @@ extension RedisClient {
165165
public func pttl(_ key: RedisKey) -> EventLoopFuture<RedisKeyLifetime> {
166166
let args: [RESPValue] = [RESPValue(from: key)]
167167
return self.send(command: "PTTL", with: args)
168-
.map(to: Int64.self)
168+
.tryConverting(to: Int64.self)
169169
.map { RedisKeyLifetime(milliseconds: $0) }
170170
}
171171
}
@@ -287,7 +287,7 @@ extension RedisClient {
287287
args.append(.init(bulk: c))
288288
}
289289

290-
let response = send(command: command, with: args).map(to: [RESPValue].self)
290+
let response = send(command: command, with: args).tryConverting(to: [RESPValue].self)
291291
let position = response.flatMapThrowing { result -> Int in
292292
guard
293293
let value = result[0].string,
@@ -299,7 +299,7 @@ extension RedisClient {
299299
}
300300
let elements = response
301301
.map { return $0[1] }
302-
.map(to: resultType)
302+
.tryConverting(to: resultType)
303303

304304
return position.and(elements)
305305
}

Sources/RediStack/Commands/HashCommands.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension RedisClient {
5656
args.append(convertingContentsOf: fields)
5757

5858
return send(command: "HDEL", with: args)
59-
.map()
59+
.tryConverting()
6060
}
6161

6262
/// Removes the specified fields from a hash.
@@ -83,7 +83,7 @@ extension RedisClient {
8383
.init(bulk: field)
8484
]
8585
return send(command: "HEXISTS", with: args)
86-
.map(to: Int.self)
86+
.tryConverting(to: Int.self)
8787
.map { return $0 == 1 }
8888
}
8989

@@ -95,7 +95,7 @@ extension RedisClient {
9595
public func hlen(of key: RedisKey) -> EventLoopFuture<Int> {
9696
let args = [RESPValue(from: key)]
9797
return send(command: "HLEN", with: args)
98-
.map()
98+
.tryConverting()
9999
}
100100

101101
/// Gets the string length of a hash field's value.
@@ -111,7 +111,7 @@ extension RedisClient {
111111
.init(bulk: field)
112112
]
113113
return send(command: "HSTRLEN", with: args)
114-
.map()
114+
.tryConverting()
115115
}
116116

117117
/// Gets all field names in a hash.
@@ -122,7 +122,7 @@ extension RedisClient {
122122
public func hkeys(in key: RedisKey) -> EventLoopFuture<[String]> {
123123
let args = [RESPValue(from: key)]
124124
return send(command: "HKEYS", with: args)
125-
.map()
125+
.tryConverting()
126126
}
127127

128128
/// Gets all values stored in a hash.
@@ -133,7 +133,7 @@ extension RedisClient {
133133
public func hvals(in key: RedisKey) -> EventLoopFuture<[RESPValue]> {
134134
let args = [RESPValue(from: key)]
135135
return send(command: "HVALS", with: args)
136-
.map()
136+
.tryConverting()
137137
}
138138

139139
/// Gets all values stored in a hash.
@@ -221,7 +221,7 @@ extension RedisClient {
221221
value.convertedToRESPValue()
222222
]
223223
return send(command: "HSET", with: args)
224-
.map(to: Int.self)
224+
.tryConverting(to: Int.self)
225225
.map { return $0 == 1 }
226226
}
227227

@@ -246,7 +246,7 @@ extension RedisClient {
246246
value.convertedToRESPValue()
247247
]
248248
return send(command: "HSETNX", with: args)
249-
.map(to: Int.self)
249+
.tryConverting(to: Int.self)
250250
.map { return $0 == 1 }
251251
}
252252

@@ -325,7 +325,7 @@ extension RedisClient {
325325
args.append(convertingContentsOf: fields)
326326

327327
return send(command: "HMGET", with: args)
328-
.map(to: [RESPValue].self)
328+
.tryConverting(to: [RESPValue].self)
329329
}
330330

331331
/// Gets the values of a hash for the fields specified as a specific type.
@@ -382,7 +382,7 @@ extension RedisClient {
382382
public func hgetall(from key: RedisKey) -> EventLoopFuture<[String: RESPValue]> {
383383
let args = [RESPValue(from: key)]
384384
return send(command: "HGETALL", with: args)
385-
.map(to: [RESPValue].self)
385+
.tryConverting(to: [RESPValue].self)
386386
.flatMapThrowing(Self._mapHashResponse)
387387
}
388388

@@ -453,6 +453,6 @@ extension RedisClient {
453453
amount.convertedToRESPValue()
454454
]
455455
return send(command: command, with: args)
456-
.map()
456+
.tryConverting()
457457
}
458458
}

Sources/RediStack/Commands/ListCommands.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension RedisClient {
2525
public func llen(of key: RedisKey) -> EventLoopFuture<Int> {
2626
let args = [RESPValue(from: key)]
2727
return send(command: "LLEN", with: args)
28-
.map()
28+
.tryConverting()
2929
}
3030

3131
/// Gets the element from a list stored at the provided index position.
@@ -104,7 +104,7 @@ extension RedisClient {
104104
value.convertedToRESPValue()
105105
]
106106
return send(command: "LREM", with: args)
107-
.map()
107+
.tryConverting()
108108
}
109109
}
110110

@@ -266,7 +266,7 @@ extension RedisClient {
266266
.init(bulk: lastIndex)
267267
]
268268
return send(command: "LRANGE", with: args)
269-
.map()
269+
.tryConverting()
270270
}
271271

272272
/// Gets all elements from a List within the the specified inclusive bounds of 0-based indices.
@@ -668,7 +668,7 @@ extension RedisClient {
668668
element.convertedToRESPValue()
669669
]
670670
return send(command: "LINSERT", with: args)
671-
.map()
671+
.tryConverting()
672672
}
673673
}
674674

@@ -714,7 +714,7 @@ extension RedisClient {
714714
args.append(convertingContentsOf: elements)
715715

716716
return send(command: "LPUSH", with: args)
717-
.map()
717+
.tryConverting()
718718
}
719719

720720
/// Pushes all of the provided elements into a list.
@@ -745,7 +745,7 @@ extension RedisClient {
745745
element.convertedToRESPValue()
746746
]
747747
return send(command: "LPUSHX", with: args)
748-
.map()
748+
.tryConverting()
749749
}
750750
}
751751

@@ -788,7 +788,7 @@ extension RedisClient {
788788
args.append(convertingContentsOf: elements)
789789

790790
return send(command: "RPUSH", with: args)
791-
.map()
791+
.tryConverting()
792792
}
793793

794794
/// Pushes all of the provided elements into a list.
@@ -818,7 +818,7 @@ extension RedisClient {
818818
element.convertedToRESPValue()
819819
]
820820
return send(command: "RPUSHX", with: args)
821-
.map()
821+
.tryConverting()
822822
}
823823
}
824824

Sources/RediStack/Commands/SetCommands.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension RedisClient {
2828
public func smembers(of key: RedisKey) -> EventLoopFuture<[RESPValue]> {
2929
let args = [RESPValue(from: key)]
3030
return send(command: "SMEMBERS", with: args)
31-
.map()
31+
.tryConverting()
3232
}
3333

3434
/// Gets all of the elements contained in a set.
@@ -61,7 +61,7 @@ extension RedisClient {
6161
element.convertedToRESPValue()
6262
]
6363
return send(command: "SISMEMBER", with: args)
64-
.map(to: Int.self)
64+
.tryConverting(to: Int.self)
6565
.map { return $0 == 1 }
6666
}
6767

@@ -73,7 +73,7 @@ extension RedisClient {
7373
public func scard(of key: RedisKey) -> EventLoopFuture<Int> {
7474
let args = [RESPValue(from: key)]
7575
return send(command: "SCARD", with: args)
76-
.map()
76+
.tryConverting()
7777
}
7878

7979
/// Adds elements to a set.
@@ -91,7 +91,7 @@ extension RedisClient {
9191
args.append(convertingContentsOf: elements)
9292

9393
return send(command: "SADD", with: args)
94-
.map()
94+
.tryConverting()
9595
}
9696

9797
/// Adds elements to a set.
@@ -121,7 +121,7 @@ extension RedisClient {
121121
args.append(convertingContentsOf: elements)
122122

123123
return send(command: "SREM", with: args)
124-
.map()
124+
.tryConverting()
125125
}
126126

127127
/// Removes elements from a set.
@@ -153,7 +153,7 @@ extension RedisClient {
153153
.init(bulk: count)
154154
]
155155
return send(command: "SPOP", with: args)
156-
.map()
156+
.tryConverting()
157157
}
158158

159159
/// Randomly selects and removes one or more elements in a set.
@@ -193,7 +193,7 @@ extension RedisClient {
193193
.init(bulk: count)
194194
]
195195
return send(command: "SRANDMEMBER", with: args)
196-
.map()
196+
.tryConverting()
197197
}
198198

199199
/// Randomly selects one or more elements in a set.
@@ -236,7 +236,7 @@ extension RedisClient {
236236
element.convertedToRESPValue()
237237
]
238238
return send(command: "SMOVE", with: args)
239-
.map()
239+
.tryConverting()
240240
.map { return $0 == 1 }
241241
}
242242

@@ -297,7 +297,7 @@ extension RedisClient {
297297

298298
let args = keys.map(RESPValue.init)
299299
return send(command: "SDIFF", with: args)
300-
.map()
300+
.tryConverting()
301301
}
302302

303303
/// Calculates the difference between two or more sets.
@@ -349,7 +349,7 @@ extension RedisClient {
349349
args.append(convertingContentsOf: keys)
350350

351351
return send(command: "SDIFFSTORE", with: args)
352-
.map()
352+
.tryConverting()
353353
}
354354
}
355355

@@ -366,7 +366,7 @@ extension RedisClient {
366366

367367
let args = keys.map(RESPValue.init)
368368
return send(command: "SINTER", with: args)
369-
.map()
369+
.tryConverting()
370370
}
371371

372372
/// Calculates the intersection of two or more sets.
@@ -418,7 +418,7 @@ extension RedisClient {
418418
args.append(convertingContentsOf: keys)
419419

420420
return send(command: "SINTERSTORE", with: args)
421-
.map()
421+
.tryConverting()
422422
}
423423
}
424424

@@ -435,7 +435,7 @@ extension RedisClient {
435435

436436
let args = keys.map(RESPValue.init)
437437
return send(command: "SUNION", with: args)
438-
.map()
438+
.tryConverting()
439439
}
440440

441441
/// Calculates the union of two or more sets.
@@ -487,6 +487,6 @@ extension RedisClient {
487487
args.append(convertingContentsOf: keys)
488488

489489
return send(command: "SUNIONSTORE", with: args)
490-
.map()
490+
.tryConverting()
491491
}
492492
}

0 commit comments

Comments
 (0)