https://github.com/ZewoGraveyard/Redis
Redis client for (pure) Swift
https://github.com/ZewoGraveyard/Redis
Last synced: 5 months ago
JSON representation
Redis client for (pure) Swift
- Host: GitHub
- URL: https://github.com/ZewoGraveyard/Redis
- Owner: ZewoGraveyard
- License: mit
- Created: 2016-02-19T20:27:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-26T17:09:39.000Z (over 8 years ago)
- Last Synced: 2024-05-18T22:53:19.516Z (11 months ago)
- Language: Swift
- Size: 31.3 KB
- Stars: 48
- Watchers: 5
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- TheList - Zewo Redis client - Redis client for (pure) Swift. (Database Connectors / Redis)
README
Redis
======
[](https://swift.org)
[](https://tldrlegal.com/license/mit-license)
[](https://zewo-slackin.herokuapp.com)
[](https://travis-ci.org/Zewo/Redis)A pure Swift client for Redis.
## Features
- [x] Pub/Sub
- [x] Pipeline with `DISCARD`
- [ ] Scripts
- [ ] All commands## Installation
Add `Redis` to your `Package.swift`
```swift
import PackageDescriptionlet package = Package(
dependencies: [
.Package(url: "https://github.com/Zewo/Redis", majorVersion: 0, minor: 3)
]
)
```## Using
```swift
let redis = try Redis("127.0.0.1", 6379)
try redis.command(.SET("foo", "bar"))
```All commands and its parameters are defined in `CommandTypeEnum` enum, with parameters in the same order as Redis docs. The `command` function returns the same response from Redis.
Commands with milliseconds (`SETEX/PSETEX`, `EXPIRE/PEXPIRE`, etc) have a `Bool` parameter to send or return in milliseconds.
It's always the last parameter.At this time, there is some commands exceptions:
* `SORT` - To be implemented
* `MIGRATE`, `WAIT`, `SCAN` - These are commands to manage the server. A discussion could be opened to implement it or don't.
* `Server` commands - Same as above### Pipeline
Pipeline works by issuing commands inside a closure:
```swift
try redis.pipeline {
try redis.command(.SET("foobar", "foo bar"))
try redis.command(.SET("foo", "bar"))
}
```If you need to `WATCH` a key, use the first argument. In case of an error, it'll be returned as `nil`.
```swift
try redis.pipeline(["foo"]) {
try redis.command(.SET("foobar", "foo bar"))
try redis.command(.SET("foo", "bar"))
}
```### PubSub
__WARNING:__ This is a first draft and the syntax is open to discussion. Beware of changes.
PubSub can subscribe to multiple channels at once, but you have to unsubscribe one at time.
```swift
let redis = try Redis("127.0.0.1", 6379)let pubsub = PubSub(conn: redis)
try pubsub.subscribe(["foo-channel", "bar-channel"]) { message in
if message["data"] as? String == "stop" {
print("Stahp \(message["channel"])!")
pubsub.unsubscribe(message["channel"] as! String)
} else {
print("Keep walking \(message["channel"])...")
}
}
```## Contributing
Pull requests are welcome, there is a lot to do.
We recommend using the [Vagrant from redis-py](https://github.com/andymccurdy/redis-py/tree/master/vagrant) to test everything.
## Community
[](https://zewo-slackin.herokuapp.com)
Join us on [Slack](https://zewo-slackin.herokuapp.com).
License
-------**Redis** is released under the MIT license. See LICENSE for details.