Skip to content

Commit 1e9d693

Browse files
committed
Unix time fixes
1 parent 9d53704 commit 1e9d693

14 files changed

+173
-153
lines changed

Sources/RESP/RESPRenderable.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import Foundation
1615
import NIOCore
1716

1817
/// Type that can be rendered into a RESP buffer
@@ -67,14 +66,6 @@ extension Double: RESPRenderable {
6766
}
6867
}
6968

70-
extension Date: RESPRenderable {
71-
@inlinable
72-
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
73-
buffer.writeBulkString(String(self.timeIntervalSince1970))
74-
return 1
75-
}
76-
}
77-
7869
extension ByteBuffer {
7970
public mutating func writeRESP3TypeIdentifier(_ identifier: RESPTypeIdentifier) {
8071
self.writeInteger(identifier.rawValue)

Sources/Redis/RedisRenderableHelpers.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,38 @@
1515
import NIOCore
1616
import RESP
1717

18-
public struct RedisPureToken: RESPRenderable {
18+
@usableFromInline
19+
package struct RedisPureToken: RESPRenderable {
1920
@usableFromInline
2021
let token: String?
2122
@inlinable
22-
public init(_ token: String, _ value: Bool) {
23+
package init(_ token: String, _ value: Bool) {
2324
if value {
2425
self.token = token
2526
} else {
2627
self.token = nil
2728
}
2829
}
2930
@inlinable
30-
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
31+
package func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
3132
self.token.writeToRESPBuffer(&buffer)
3233
}
3334
}
3435

35-
public struct RESPWithToken<Value: RESPRenderable>: RESPRenderable {
36+
@usableFromInline
37+
package struct RESPWithToken<Value: RESPRenderable>: RESPRenderable {
3638
@usableFromInline
3739
let value: Value?
3840
@usableFromInline
3941
let token: String
4042

4143
@inlinable
42-
public init(_ token: String, _ value: Value?) {
44+
package init(_ token: String, _ value: Value?) {
4345
self.value = value
4446
self.token = token
4547
}
4648
@inlinable
47-
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
49+
package func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
4850
if let value {
4951
let writerIndex = buffer.writerIndex
5052
_ = self.token.writeToRESPBuffer(&buffer)
@@ -60,16 +62,17 @@ public struct RESPWithToken<Value: RESPRenderable>: RESPRenderable {
6062
}
6163
}
6264

63-
public struct RESPArrayWithCount<Element: RESPRenderable>: RESPRenderable {
65+
@usableFromInline
66+
package struct RESPArrayWithCount<Element: RESPRenderable>: RESPRenderable {
6467
@usableFromInline
6568
let array: [Element]
6669

6770
@inlinable
68-
public init(_ array: [Element]) {
71+
package init(_ array: [Element]) {
6972
self.array = array
7073
}
7174
@inlinable
72-
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
75+
package func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
7376
_ = array.count.writeToRESPBuffer(&buffer)
7477
let count = array.writeToRESPBuffer(&buffer)
7578
return count + 1

Sources/RedisCommands/BitmapCommands.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// This file is autogenerated by RedisCommandsBuilder
1616

1717
import NIOCore
18-
import Redis
1918
import RESP
19+
import Redis
2020

2121
#if canImport(FoundationEssentials)
2222
import FoundationEssentials
@@ -45,9 +45,9 @@ extension RESPCommand {
4545
@inlinable
4646
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
4747
var count = 0
48-
count += self.start.writeToRESPBuffer(&buffer)
49-
count += self.end.writeToRESPBuffer(&buffer)
50-
count += self.unit.writeToRESPBuffer(&buffer)
48+
count += start.writeToRESPBuffer(&buffer)
49+
count += end.writeToRESPBuffer(&buffer)
50+
count += unit.writeToRESPBuffer(&buffer)
5151
return count
5252
}
5353
}
@@ -70,8 +70,8 @@ extension RESPCommand {
7070
@inlinable
7171
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
7272
var count = 0
73-
count += self.encoding.writeToRESPBuffer(&buffer)
74-
count += self.offset.writeToRESPBuffer(&buffer)
73+
count += encoding.writeToRESPBuffer(&buffer)
74+
count += offset.writeToRESPBuffer(&buffer)
7575
return count
7676
}
7777
}
@@ -97,9 +97,9 @@ extension RESPCommand {
9797
@inlinable
9898
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
9999
var count = 0
100-
count += self.encoding.writeToRESPBuffer(&buffer)
101-
count += self.offset.writeToRESPBuffer(&buffer)
102-
count += self.value.writeToRESPBuffer(&buffer)
100+
count += encoding.writeToRESPBuffer(&buffer)
101+
count += offset.writeToRESPBuffer(&buffer)
102+
count += value.writeToRESPBuffer(&buffer)
103103
return count
104104
}
105105
}
@@ -111,9 +111,9 @@ extension RESPCommand {
111111
@inlinable
112112
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
113113
var count = 0
114-
count += self.encoding.writeToRESPBuffer(&buffer)
115-
count += self.offset.writeToRESPBuffer(&buffer)
116-
count += self.increment.writeToRESPBuffer(&buffer)
114+
count += encoding.writeToRESPBuffer(&buffer)
115+
count += offset.writeToRESPBuffer(&buffer)
116+
count += increment.writeToRESPBuffer(&buffer)
117117
return count
118118
}
119119
}
@@ -137,7 +137,7 @@ extension RESPCommand {
137137
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
138138
var count = 0
139139
count += RESPWithToken("OVERFLOW", overflowBlock).writeToRESPBuffer(&buffer)
140-
count += self.writeOperation.writeToRESPBuffer(&buffer)
140+
count += writeOperation.writeToRESPBuffer(&buffer)
141141
return count
142142
}
143143
}
@@ -188,8 +188,8 @@ extension RESPCommand {
188188
@inlinable
189189
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
190190
var count = 0
191-
count += self.encoding.writeToRESPBuffer(&buffer)
192-
count += self.offset.writeToRESPBuffer(&buffer)
191+
count += encoding.writeToRESPBuffer(&buffer)
192+
count += offset.writeToRESPBuffer(&buffer)
193193
return count
194194
}
195195
}
@@ -276,8 +276,8 @@ extension RESPCommand {
276276
@inlinable
277277
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
278278
var count = 0
279-
count += self.end.writeToRESPBuffer(&buffer)
280-
count += self.unit.writeToRESPBuffer(&buffer)
279+
count += end.writeToRESPBuffer(&buffer)
280+
count += unit.writeToRESPBuffer(&buffer)
281281
return count
282282
}
283283
}
@@ -288,8 +288,8 @@ extension RESPCommand {
288288
@inlinable
289289
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
290290
var count = 0
291-
count += self.start.writeToRESPBuffer(&buffer)
292-
count += self.endUnitBlock.writeToRESPBuffer(&buffer)
291+
count += start.writeToRESPBuffer(&buffer)
292+
count += endUnitBlock.writeToRESPBuffer(&buffer)
293293
return count
294294
}
295295
}
@@ -302,13 +302,13 @@ extension RESPCommand {
302302
/// - Response: One of the following:
303303
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the position of the first bit set to 1 or 0 according to the request
304304
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `-1`. In case the `bit` argument is 1 and the string is empty or composed of just zero bytes
305-
///
305+
///
306306
/// If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is returned.
307-
///
307+
///
308308
/// If we look for clear bits (the bit argument is 0) and the string only contains bits set to 1, the function returns the first bit not part of the string on the right. So if the string is three bytes set to the value `0xff` the command `BITPOS key 0` will return 24, since up to bit 23 all the bits are 1.
309-
///
309+
///
310310
/// The function considers the right of the string as padded with zeros if you look for clear bits and specify no range or the _start_ argument **only**.
311-
///
311+
///
312312
/// However, this behavior changes if you are looking for clear bits and specify a range with both _start_ and _end_.
313313
/// If a clear bit isn't found in the specified range, the function returns -1 as the user specified a clear range and there are no 0 bits in that range.
314314
@inlinable
@@ -442,13 +442,13 @@ extension RedisConnection {
442442
/// - Returns: One of the following:
443443
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): the position of the first bit set to 1 or 0 according to the request
444444
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `-1`. In case the `bit` argument is 1 and the string is empty or composed of just zero bytes
445-
///
445+
///
446446
/// If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is returned.
447-
///
447+
///
448448
/// If we look for clear bits (the bit argument is 0) and the string only contains bits set to 1, the function returns the first bit not part of the string on the right. So if the string is three bytes set to the value `0xff` the command `BITPOS key 0` will return 24, since up to bit 23 all the bits are 1.
449-
///
449+
///
450450
/// The function considers the right of the string as padded with zeros if you look for clear bits and specify no range or the _start_ argument **only**.
451-
///
451+
///
452452
/// However, this behavior changes if you are looking for clear bits and specify a range with both _start_ and _end_.
453453
/// If a clear bit isn't found in the specified range, the function returns -1 as the user specified a clear range and there are no 0 bits in that range.
454454
@inlinable

Sources/RedisCommands/ClusterCommands.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ extension RESPCommand {
6868
@inlinable
6969
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
7070
var count = 0
71-
count += self.startSlot.writeToRESPBuffer(&buffer)
72-
count += self.endSlot.writeToRESPBuffer(&buffer)
71+
count += startSlot.writeToRESPBuffer(&buffer)
72+
count += endSlot.writeToRESPBuffer(&buffer)
7373
return count
7474
}
7575
}
@@ -166,8 +166,8 @@ extension RESPCommand {
166166
@inlinable
167167
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
168168
var count = 0
169-
count += self.startSlot.writeToRESPBuffer(&buffer)
170-
count += self.endSlot.writeToRESPBuffer(&buffer)
169+
count += startSlot.writeToRESPBuffer(&buffer)
170+
count += endSlot.writeToRESPBuffer(&buffer)
171171
return count
172172
}
173173
}

Sources/RedisCommands/ConnectionCommands.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ extension RESPCommand {
481481
@inlinable
482482
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
483483
var count = 0
484-
count += self.username.writeToRESPBuffer(&buffer)
485-
count += self.password.writeToRESPBuffer(&buffer)
484+
count += username.writeToRESPBuffer(&buffer)
485+
count += password.writeToRESPBuffer(&buffer)
486486
return count
487487
}
488488
}
@@ -494,7 +494,7 @@ extension RESPCommand {
494494
@inlinable
495495
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
496496
var count = 0
497-
count += self.protover.writeToRESPBuffer(&buffer)
497+
count += protover.writeToRESPBuffer(&buffer)
498498
count += RESPWithToken("AUTH", auth).writeToRESPBuffer(&buffer)
499499
count += RESPWithToken("SETNAME", clientname).writeToRESPBuffer(&buffer)
500500
return count

Sources/RedisCommands/GenericCommands.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ extension RESPCommand {
158158
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `1` if the timeout was set.
159159
@inlinable
160160
public static func expireat(key: RedisKey, unixTimeSeconds: Date, condition: EXPIREATCondition? = nil) -> RESPCommand {
161-
RESPCommand("EXPIREAT", key, unixTimeSeconds, condition)
161+
RESPCommand("EXPIREAT", key, Int(unixTimeSeconds.timeIntervalSince1970), condition)
162162
}
163163

164164
/// Returns the expiration time of a key as a Unix timestamp.
@@ -207,8 +207,8 @@ extension RESPCommand {
207207
@inlinable
208208
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
209209
var count = 0
210-
count += self.username.writeToRESPBuffer(&buffer)
211-
count += self.password.writeToRESPBuffer(&buffer)
210+
count += username.writeToRESPBuffer(&buffer)
211+
count += password.writeToRESPBuffer(&buffer)
212212
return count
213213
}
214214
}
@@ -405,7 +405,7 @@ extension RESPCommand {
405405
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation was skipped due to the provided arguments.
406406
@inlinable
407407
public static func pexpireat(key: RedisKey, unixTimeMilliseconds: Date, condition: PEXPIREATCondition? = nil) -> RESPCommand {
408-
RESPCommand("PEXPIREAT", key, unixTimeMilliseconds, condition)
408+
RESPCommand("PEXPIREAT", key, Int(unixTimeMilliseconds.timeIntervalSince1970 * 1000), condition)
409409
}
410410

411411
/// Returns the expiration time of a key as a Unix milliseconds timestamp.
@@ -511,8 +511,8 @@ extension RESPCommand {
511511
@inlinable
512512
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
513513
var count = 0
514-
count += self.offset.writeToRESPBuffer(&buffer)
515-
count += self.count.writeToRESPBuffer(&buffer)
514+
count += offset.writeToRESPBuffer(&buffer)
515+
count += count.writeToRESPBuffer(&buffer)
516516
return count
517517
}
518518
}
@@ -561,8 +561,8 @@ extension RESPCommand {
561561
@inlinable
562562
public func writeToRESPBuffer(_ buffer: inout ByteBuffer) -> Int {
563563
var count = 0
564-
count += self.offset.writeToRESPBuffer(&buffer)
565-
count += self.count.writeToRESPBuffer(&buffer)
564+
count += offset.writeToRESPBuffer(&buffer)
565+
count += count.writeToRESPBuffer(&buffer)
566566
return count
567567
}
568568
}
@@ -807,7 +807,7 @@ extension RedisConnection {
807807
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `1` if the timeout was set.
808808
@inlinable
809809
public func expireat(key: RedisKey, unixTimeSeconds: Date, condition: RESPCommand.EXPIREATCondition? = nil) async throws -> Int {
810-
try await send("EXPIREAT", key, unixTimeSeconds, condition).converting()
810+
try await send("EXPIREAT", key, Int(unixTimeSeconds.timeIntervalSince1970), condition).converting()
811811
}
812812

813813
/// Returns the expiration time of a key as a Unix timestamp.
@@ -986,7 +986,7 @@ extension RedisConnection {
986986
/// * [Integer](https:/redis.io/docs/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation was skipped due to the provided arguments.
987987
@inlinable
988988
public func pexpireat(key: RedisKey, unixTimeMilliseconds: Date, condition: RESPCommand.PEXPIREATCondition? = nil) async throws -> Int {
989-
try await send("PEXPIREAT", key, unixTimeMilliseconds, condition).converting()
989+
try await send("PEXPIREAT", key, Int(unixTimeMilliseconds.timeIntervalSince1970 * 1000), condition).converting()
990990
}
991991

992992
/// Returns the expiration time of a key as a Unix milliseconds timestamp.

0 commit comments

Comments
 (0)