Commit Graph
309 Commits
Author SHA1 Message Date
Cory Benfield 2211dbf36b Detect and throw on invalid integer.
Motivation:

parseInteger did not distinguish between not having enough bytes for an
integer and not being able to parse the integer that was present. This
was a bit tricky for code internally, where some call sites had extra
code looking for spooky action at a distance in order to determine if
the integer failed to parse.

This is unnecessary: parseInteger is sufficiently aware of what's going
on to address this problem itself.

Modifications:

- Added a new parser error (acceptable as we haven't tagged 1.0 yet).
- Throw it from parseInteger if the integer is invalid.

Result:

parseInteger clearly communicates if the integer failed to parse.
2020-05-27 16:00:20 +00:00
Cory Benfield 638fbb0754 Clean up indexing of ByteBufferView
Motivation:

ByteBufferView is not zero indexed, but parseSimpleString assumes it is.

Modifications:

- Correctly compute on the distance between two indices.
- New, somewhat contrived, test case.

Result:

No functional change: because RediStack assumes the remote peer will
always correctly terminate with /r/n, there is no point at which this
code could misbehave in the current implementation. However, with small
changes it is possible to trigger it, as the new test demonstrates.
2020-05-27 10:44:38 +01:00
Cory Benfield f9579373f5 Avoid creating temporary arrays
Motivation:

When we only want the first byte, rather than create temporary
intermediate arrays we can just ask NIO to give us the first byte. This
avoids unnecessary allocations.

Modifications:

- Replace `readBytes(length: 1).first` with `readInteger(as:
  UInt8.self)`

Results:

11% performance improvement in load testing due to reduced allocator
pressure on the hot path.
2020-05-26 18:11:01 +00:00
Cory Benfield dd08685566 Avoid transient ByteBufferView
Motivation:

When attempting to locate a single byte, creating a transient
ByteBufferView is an excessively heavyweight operation compared to a
simple getInteger. In particular, a BBV requires retain/release
operations to enforce the CoW invariants, as well as requires jumps
through substantial amounts of generic Collection code. While this can
be specialized, so can getInteger, and getInteger has much less code in
the way to cause costs.

Modifications:

- Replace temporary view creation with getInteger.

Results:

5% performance improvement on raw throughput tests.
2020-05-26 15:43:11 +01:00
Nathan Harris 20848b8093 Move quality checks to be after unit tests 2020-05-08 16:16:10 -07:00
Nathan Harris c699aca17c Add CI for nightly trunk images of new linux platforms 2020-05-08 16:14:47 -07:00
Nathan Harris b3bc95f118 Add CI jobs for Swift 5.3 development snapshots 2020-04-23 20:38:31 -07:00
Nathan Harris 86d5466584 Make ActiveConnectionGauge.currentCount public 2020-04-20 02:22:52 +00:00
Nathan Harris b462bdcf3f Update CodeClimate badge for renamed project 1.0.0-alpha.9 2020-03-27 14:28:21 -07:00
Nathan Harris 851c81ae79 Update CI to use official Swift 5.2 images and update README for current testing matrix 2020-03-27 14:19:27 -07:00
Nathan Harris c1ba671097 Reduce RESPValue initialization complexities and simplify RedisKey implementation
Motivation:

`RESPValue` exposes a fair amount of complexity on how to intialize a single instance with the various overloads.

This aims to simplify the complexity for developers by providing a single initializer and relying on `RESPValueConvertible` to handle the complexities.

In addition, the Swift complier synthesizes a lot of default conformances that `RedisKey` has manually written, which is just unnecessary code.

Modifications:

- Rename: `RESPValue.init(_:)` to `RESPValue.init(from:)`
- Change: `RESPValue.init` `String?` and `FixedWidthInteger` overloads from `public` to `internal`
- Remove: Unnecessary code for various protocol conformances for `RedisKey`

Result:

Developers should have a direct and guided way of making instances of `RESPValue`
2020-03-19 22:20:47 -07:00
Nathan Harris 3e1a3d5e74 Add GitHub pull request template to direct devs to GitLab 2020-03-19 20:39:12 -07:00
Nathan Harris 543e27bde0 Move GitLab CI files to .gitlab 2020-03-19 20:39:12 -07:00
Nathan Harris ad00b0c582 Add GitHub Sponsor funding file 2020-03-19 20:39:11 -07:00
Nathan Harris 7850dee562 Add code owners file 2020-03-19 20:39:11 -07:00
Nathan Harris 9425c39d44 Add issue templates 2020-03-19 20:39:11 -07:00
Nathan Harris 8d19354e07 Add merge request templates 2020-03-19 20:39:11 -07:00
Nathan Harris fb921f2a62 Update CONTRIBUTING guide 2020-03-19 20:39:06 -07:00
Nathan Harris 83f8b78c2e Disable additional scan command unit tests until #23 is fixed 2020-03-19 19:43:21 -07:00
Nathan Harris 41f9377d31 Refine Redis Command API
Motivation:

It was noticed that many of the commands are cumbersome to use with boilerplate type casting for each use that can be simplified within the library
by doing type conversion before returning the value to an end user.

Modifications:

Many APIs that return a `RESPValue` now have overloads to provide a `RESPValueConvertible` type that the value will be turned into before being returned.

For a few APIs that returned `RESPValue`, they did so as an Optional. Those APIs have been changed to always provide a `RESPValue` and return `.null` in cases where `nil` was returned.

In addition, the `@inlinable` attribute has been removed from any non-generic command API.

Result:

Developers should have less code boilerplate for turning values from `RESPValue` to their desired type with many commands.
2020-03-19 19:30:54 -07:00
Nathan Harris 86f2eb69c9 Disable Scan command unit test until #23 is completed 2020-03-19 16:17:35 -07:00
Nathan Harris ea781e1bd4 73 -- Remove isConnected property requirement from RedisClient 2020-03-19 15:53:39 -07:00
Nathan Harris b08ad5461a Rename Package to "RediStack"
Motivation:

SwiftPM as of Swift 5.2 introduces a new package dependency graph and package description that makes the current naming of RediStack awkward to pull in.

Modifications:

- Change: Package.name to be "RediStack"

The git repo will be renamed to "mordil/redistack" in addition to this change.

Result:

Fixes #72 and makes it seamless to pull in RediStack as a Swift package dependency.
1.0.0-alpha.8
2020-03-11 20:35:15 -07:00
Nathan Harris 973a9162af 70 -- Update SwiftMetrics for ecosystem compatability 2020-03-06 03:13:19 +00:00
Nathan Harris fb161021a9 Rename ELF.convertFromRESPValue to be an overload of map 2020-02-19 20:59:11 -08:00
Nathan Harris 6bd5df7d93 Add map overloads for casting RESPValue elements in a Collection 2020-02-19 20:44:27 -08:00
Nathan Harris 17fa5dad0a Cleanup Extensions by placing code in more appropriate places 2020-02-19 20:41:41 -08:00
Nathan Harris f2fb726904 Use latest Redis 5 in dev Docker Compose 2020-02-17 16:00:24 -08:00
Nathan Harris bd4a0dab84 Add documentation coverage badge to README 2020-02-04 23:10:18 -08:00
Nathan Harris b8bac7e896 Exclude Code Climate CI job for schedules 2020-02-04 22:45:39 -08:00
Nathan Harris 21d0a3120b Add code quality tracking from Code Climate 2020-02-04 22:33:33 -08:00
Nathan Harris a0b21e7b81 Update test matrix in README 2020-01-26 13:57:07 -08:00
Nathan Harris 02f3fb760c Update nightlies to use 'official' nightlies on all linux platforms 2020-01-26 13:16:10 -08:00
Nathan Harris 8e48e939e0 Update README to clarify Redis version support 2020-01-16 10:15:02 -08:00
Nathan Harris 4b2729c0ac Add Swift 5.2 branch testing to CI f10d6a0 Nathan Harris <nathan@mordil.info> Jan 16, 2020 at 08:08 2020-01-16 09:28:07 -08:00
Nathan Harris 6e45f56e00 Merge branch 'range-api' into 'master'
Rework SortedSet and List range APIs

See merge request Mordil/swift-redi-stack!98
2019-12-31 01:22:20 +00:00
Nathan Harris 249999851e Rework SortedSet and List range APIs
Motivation:

The SortedSet and List range commands (LTRIM, LRANGE, ZRANGE, etc.) are stringly-based and not flexible with Swift syntax.

Modifications:

- Add overloads of LTRIM that support the gambit of Range Standard Library types
- Rework LRANGE to mirror LTRIM method signatures
- Rework ZScore Range based commands to be more type-safe with `RedisZScoreBound` enum
- Rework ZLex Range based commands to be more type-safe with `RedisZLexBound` enum
- Rework ZCOUNT, ZLEXCOUNT, ZRANGE, ZREVRANGE, ZREMRANGEBYLEX, ZREMRANGEBYRANK, ZREMRANGEBYSCORE methods to be more type-safe and support Swift Range syntax

Result:

Working with SortedSet ranges should be much more type safe, and expressive with Swift's Range syntax.
2019-12-30 17:17:25 -08:00
Nathan Harris 47480b8074 Update Linux test manifest 2019-12-30 17:17:24 -08:00
Nathan Harris 346d37d636 Merge branch 'revisit-zadd' into 'master'
Revisit the SortedSet `zadd` command API

See merge request Mordil/swift-redi-stack!97
2019-12-28 07:58:24 +00:00
Nathan Harris 8e3d8f6faf Revisit the SortedSet zadd command API
Motivation:

While reviewing the API, the current design does not read well, and still has room for misunderstanding the actual end result of a ZADD operation.

Modifications:

- Rename `RedisSortedSetAddOption` to `RedisZaddInsertBehavior` and update cases to match desired use site syntax.
- Add `RedisZaddReturnBehavior` enum to define how `zadd` should calculate the return value.
- Update `zadd` and its overloads to support the two new enums in the form of `zadd(_:to:inserting:returning:)`

Result:

The more "Swifty" API will make it much more clear to developers at the call site what the actual behavior of the ZADD command will be.
2019-12-27 23:49:44 -08:00
Nathan Harris 4350e01097 Merge branch 'blocking-timeamount' into 'master'
Use `TimeAmount` for any `timeout` command arguments

See merge request Mordil/swift-redi-stack!96
2019-12-28 06:35:14 +00:00
Nathan Harris 1ef315e255 Use TimeAmount for any timeout command arguments
Motivation:

The goal is to have a strong-typed API for type-safety in arbitrary values, such as trying to use
Int to represent time - as '3' could mean any unit of time, leaving many places for errors and bugs.

Modifications:

Switch all current APIs that accept a `timeout` argument to use `NIO.TimeAmount` instead of a plain `Int`.

Result:

Developers will have an easier time reasoning about their own code as to what values might mean when working with
timeouts in Redis APIs.
2019-12-27 22:29:28 -08:00
Nathan Harris 0007a08697 Merge branch 'isconnected-req' into 'master'
Add `isConnected` property to `RedisClient` protocol

See merge request Mordil/swift-redi-stack!95
2019-12-28 06:13:16 +00:00
Nathan Harris a50a4d555d Add isConnected property to RedisClient protocol
Motivation:

It it pretty common as a developer when working with connections and "database" clients to want to know
if the connection is currently open before doing any work.

Modifications:

Add `var isConnected: Bool { get }` requirement to the `RedisClient` protocol

Result:

Developers should now have access to the connectivity state of any `RedisClient`
2019-12-27 21:52:20 -08:00
Nathan Harris a5f9d76cac Merge branch 'typed-keys' into 'master'
Add type-safe representation of Redis keys

See merge request Mordil/swift-redi-stack!93
2019-12-28 05:42:08 +00:00
Nathan Harris ea6f427993 Add type-safe representation of Redis keys
Motivation:

Inspired by Swift by Sundell's article on type-safe identifers, the goal of this commit is to have the compiler
assist in preventing incorrect Redis key values from being used in API calls.

See https://www.swiftbysundell.com/articles/type-safe-identifiers-in-swift/ for the inspiration.

Modifications:

- Add new `RedisKey` struct that wraps around a single `String` value that conforms to several expected protocols
  (Hashable, Comparable, Codable, etc.)
- Change all command APIs to require `RedisKey` rather than plain strings

Result:

When encountering an API requiring a RedisKey, it should be much more apparant at the use site what form a value should take.
2019-12-27 21:38:35 -08:00
Nathan Harris 5d6c3d3f28 Merge branch 'authorize' into 'master'
Add authorize command

See merge request Mordil/swift-redi-stack!94
2019-12-25 08:28:40 +00:00
Nathan Harris 435cdb2ab0 Add authorize command
Motivation:

The library provides command implementations for almost every single Redis command, authorize is no different.

Modifications:

Add `authorize(with:)` command method on `RedisClient`
Replace the implementation in `RedisConnection.connect(...)`

Result:

Developers should now have independent access to the `AUTH` Redis command on `RedisClient` implementations.
2019-12-25 00:23:09 -08:00
Nathan Harris 8d85cb2bfa Update to use new NIOAtomic over deprecated Atomic 1.0.0-alpha.7.1 2019-12-16 15:47:03 -08:00
Nathan Harris 9747cf2e2b Merge branch 'custom-logging' into 'master'
Revist user Logging configuration for connections and clients

See merge request Mordil/swift-redi-stack!92
1.0.0-alpha.7
2019-12-13 23:47:32 +00:00