Skip to content

Latest commit

 

History

History
158 lines (135 loc) · 4.39 KB

README.zh_CN.md

File metadata and controls

158 lines (135 loc) · 4.39 KB

Perfect-Redis English

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

Redis 数据库连接器 - Perfect 软件框架

问题报告、内容贡献和客户支持

我们目前正在过渡到使用JIRA来处理所有源代码资源合并申请、修复漏洞以及其它有关问题。因此,GitHub 的“issues”问题报告功能已经被禁用了。

如果您发现了问题,或者希望为改进本文提供意见和建议,请在这里指出.

在您开始之前,请参阅目前待解决的问题清单.

快速上手

通过默认参数获得Redis连接:

RedisClient.getClient(withIdentifier: RedisClientIdentifier()) {
	c in
	do {
		let client = try c()
		...
	} catch {
		...
	}
}

测试数据库连接效果:

client.ping {
	response in
	defer {
		RedisClient.releaseClient(client)
	}
	guard case .simpleString(let s) = response else {
		...
		return
	}
	XCTAssert(s == "PONG", "响应无效: \(response)")
}

设置变量和值

let (key, value) = ("mykey", "myvalue")
client.set(key: key, value: .string(value)) {
	response in
	guard case .simpleString(let s) = response else {
		...
		return
	}
	client.get(key: key) {
		response in
		defer {
			RedisClient.releaseClient(client)
		}
		guard case .bulkString = response else {
			...
			return
		}
		let s = response.toString()
		XCTAssert(s == value, "响应无效: \(response)")
	}
}

发布/订阅:

RedisClient.getClient(withIdentifier: RedisClientIdentifier()) {
	c in
	do {
		let client1 = try c()
		RedisClient.getClient(withIdentifier: RedisClientIdentifier()) {
			c in
			do {
				let client2 = try c()
				client1.subscribe(channels: ["foo"]) {
					response in
					client2.publish(channel: "foo", message: .string("Hello!")) {
						response in
						client1.readPublished(timeoutSeconds: 5.0) {
							response in
							guard case .array(let array) = response else {
								...
								return
							}
							XCTAssert(array.count == 3, "Invalid array elements")
							XCTAssert(array[0].toString() == "message")
							XCTAssert(array[1].toString() == "foo")
							XCTAssert(array[2].toString() == "Hello!")
						}
					}
				}
			} catch {
				...
			}
		}
	} catch {
		...
	}
}

编译

请在Package.swift 文件中增加依存关系:

.Package(url: "https://github.com/PerfectlySoft/Perfect-Redis.git", majorVersion: 2)

更多信息:

关于本项目更多信息,请参考Perfect 官网:perfect.org.