Skip to content

Commit 229f957

Browse files
committed
Update README
1 parent 3867d44 commit 229f957

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

README.md

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,38 @@
1-
# NIORedis: A Redis Driver built on SwiftNIO
1+
[![License](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
2+
[![Build](https://img.shields.io/circleci/project/github/Mordil/nio-redis/master.svg?logo=circleci)](https://circleci.com/gh/Mordil/nio-redis/tree/master)
3+
[![Swift](https://img.shields.io/badge/Swift-5.0-brightgreen.svg?colorA=orange&colorB=4E4E4E)](https://swift.org)
24

3-
* Pitch discussion: [Swift Server Forums](https://forums.swift.org/t/swiftnio-redis-client/19325/13)
5+
# NIORedis
46

5-
> **NOTE: This this is written against SwiftNIO 2.0, and as such requires Swift 5.0!**
7+
* Pitch discussion: [Swift Server Forums](https://forums.swift.org/t/swiftnio-redis-client/19325)
8+
* Proposal: [SSWG-0004](https://github.com/swift-server/sswg/blob/56a26b50ade45d624b54abe13c7d1f88526f9bb1/proposals/0004-nio-redis.md)
69

7-
This is to take advantage of the [`Result`](https://github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md) type in the `DispatchRedis` module,
8-
and to stay ahead of development of the next version of SwiftNIO.
10+
## Installation
11+
12+
To install `NIORedis`, just add the package as a dependency in your [**Package.swift**](https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescriptionV4.md#dependencies)
913

1014
```swift
11-
import NIORedis
15+
dependencies: [
16+
.package(url: "https://github.com/Mordil/nio-redis.git", .upToNextMinor(from: "0.2.0")
17+
]
18+
```
1219

13-
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
14-
let driver = RedisDriver(ownershipModel: .external(elg))
20+
and run the following command: `swift package resolve`
1521

16-
// connections
22+
## Getting Started
1723

18-
// passing a value to 'password' will automatically authenticate with Redis before resolving the connection
19-
let connection = try redis.makeConnection(
20-
hostname: "localhost", // this is the default
21-
port: 6379, // this is the default
22-
password: "MY_PASS" // default is 'nil'
23-
).wait()
24+
`NIORedis` is ready to use right after installation.
2425

25-
// convenience methods for commands
26+
```swift
27+
import NIORedis
2628

27-
let result = try conneciton.set("my_key", to: "some value")
28-
.then { return connection.get("my_key")}
29-
.wait()
30-
print(result) // Optional("some value")
29+
let driver = NIORedisDriver(ownershipModel: .internal(threadCount: 2))
3130

32-
// raw commands
31+
let connection = try driver.makeConnection().wait()
3332

34-
let keyCount = try connection.command("DEL", [RESPValue(bulk: "my_key")])
35-
.thenThrowing { response in
36-
guard case let .integer(count) else {
37-
// throw error
38-
}
39-
return count
40-
}
33+
let result = try connection.set("my_key", to: "some value")
34+
.flatMap { return connection.get("my_key" }
4135
.wait()
42-
print(keyCount) // 1
43-
44-
// cleanup
4536

46-
connection.close()
47-
.thenThrowing { try redis.terminate() }
48-
.whenSuccess { try elg.syncShutdownGracefully() }
37+
print(result) // Optional("some value")
4938
```
50-
51-
### RESPValue & RESPValueConvertible
52-
This is a 1:1 mapping enum of the `RESP` types: `Simple String`, `Bulk String`, `Array`, `Integer` and `Error`.
53-
54-
Conforming to `RESPValueConvertible` allows Swift types to more easily convert between `RESPValue` and native types.
55-
56-
`Array`, `Data`, `Float`, `Double`, `FixedWidthInteger`, `String`, and of course `RESPValue` all conform in this package.

0 commit comments

Comments
 (0)