Skip to content

Commit

Permalink
Merge pull request #26 from cmushroom/dev
Browse files Browse the repository at this point in the history
1.4.3
  • Loading branch information
chengpan168 authored Feb 7, 2022
2 parents 3a2c205 + b93c3b0 commit 3d987a7
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 37 deletions.
14 changes: 9 additions & 5 deletions redis-pro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
621EFD8E276CC52E0079D1E3 /* NPasswordField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621EFD8D276CC52E0079D1E3 /* NPasswordField.swift */; };
6237D032275C954A000ACD6A /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 6237D031275C954A000ACD6A /* Logging */; };
6237D034275CFF1F000ACD6A /* NIntField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6237D033275CFF1F000ACD6A /* NIntField.swift */; };
626E10EA27B11398007ED968 /* RedisClientTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 626E10E927B11398007ED968 /* RedisClientTest.swift */; };
62CB3D722619AE050061E8C3 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62CB3D712619AE050061E8C3 /* HomeView.swift */; };
62CB3D752619AEC20061E8C3 /* RedisKeysListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62CB3D742619AEC20061E8C3 /* RedisKeysListView.swift */; };
62CB3D792619AEEB0061E8C3 /* RedisKeyRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62CB3D782619AEEB0061E8C3 /* RedisKeyRowView.swift */; };
Expand Down Expand Up @@ -307,6 +308,7 @@
621EFD8B276CB7510079D1E3 /* NTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NTable.swift; sourceTree = "<group>"; };
621EFD8D276CC52E0079D1E3 /* NPasswordField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NPasswordField.swift; sourceTree = "<group>"; };
6237D033275CFF1F000ACD6A /* NIntField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIntField.swift; sourceTree = "<group>"; };
626E10E927B11398007ED968 /* RedisClientTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedisClientTest.swift; sourceTree = "<group>"; };
62CB3D712619AE050061E8C3 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
62CB3D742619AEC20061E8C3 /* RedisKeysListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedisKeysListView.swift; sourceTree = "<group>"; };
62CB3D782619AEEB0061E8C3 /* RedisKeyRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedisKeyRowView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -626,9 +628,9 @@
430A09E125C1559400B60DFC /* FormLabel.swift */,
4313576E263ABB1C0077EE46 /* FormWrapper.swift */,
430A09E525C155F800B60DFC /* FormItemText.swift */,
43DFEF3625C29288006EF535 /* FormItemInt.swift */,
43BCCD3626A91E85000BE45F /* FormItemPassword.swift */,
4313576A263AB6400077EE46 /* FormItemTextArea.swift */,
43DFEF3625C29288006EF535 /* FormItemInt.swift */,
436BB6962644EED8008B4866 /* FormItemDouble.swift */,
CE83D51B2758E8D1000DF09D /* NTextField.swift */,
CEF000FE2771B6640020A27E /* NTextEditor.swift */,
Expand All @@ -649,6 +651,7 @@
CE0290D4278707280058442B /* redis-proTests */ = {
isa = PBXGroup;
children = (
626E10E927B11398007ED968 /* RedisClientTest.swift */,
CE0290D5278707280058442B /* redis_proTests.swift */,
);
path = "redis-proTests";
Expand Down Expand Up @@ -920,6 +923,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
626E10EA27B11398007ED968 /* RedisClientTest.swift in Sources */,
CE0290D6278707280058442B /* redis_proTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1073,7 +1077,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_ASSET_PATHS = "\"redis-pro/Preview Content\"";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "redis-pro/Info.plist";
Expand All @@ -1082,7 +1086,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.cmushroom.redis-pro";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -1098,7 +1102,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_ASSET_PATHS = "\"redis-pro/Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand All @@ -1108,7 +1112,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.cmushroom.redis-pro";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Binary file not shown.
25 changes: 15 additions & 10 deletions redis-pro/Common/RediStackClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class RediStackClient {
var sshServer:PortForwardingServer?

// 递归查询每页大小
private var recursionSize:Int = 500
private var recursionSize:Int = 2000
private var recursionCountSize:Int = 5000

init(redisModel:RedisModel) {
self.redisModel = redisModel
Expand Down Expand Up @@ -447,7 +448,7 @@ extension RediStackClient {
self.logger.info("recursion scan get keys enough, max count: \(maxCount), current count: \(keys.count)")
return (cursor, keys)
} else {
let res = try await keyScan(cursor: cursor, keywords: keywords, count: 3000)
let res = try await keyScan(cursor: cursor, keywords: keywords, count: recursionSize)
let newKeys = keys + res.keys

if res.cursor == 0 {
Expand All @@ -462,7 +463,7 @@ extension RediStackClient {
}

private func scanTotal(_ keywords:String?, cursor:Int, total:Int) async throws -> Int {
let res = try await keyScan(cursor: cursor, keywords: keywords, count: recursionSize)
let res = try await keyScan(cursor: cursor, keywords: keywords, count: recursionCountSize)
let newTotal:Int = total + res.keys.count
if res.cursor == 0 {
self.logger.info("recursion scan total reach end, total: \(newTotal)")
Expand Down Expand Up @@ -519,17 +520,21 @@ extension RediStackClient {
do {
// 带有占位符的情况,使用
if isScan {
let total = try await recursionScanTotal(match)
page.total = total
let res = try await self.recursionScan(match, cursor: cursor, maxCount: total, keys: keys)
// async let total = recursionScanTotal(match)

async let res = self.recursionScan(match, cursor: cursor, maxCount: page.size, keys: keys)

// page.total = try await total
let keys = try await res.keys

let start = (page.current - 1) * page.size

if res.keys.count <= start {
if keys.count <= start {
return []
}

let end = min(start + page.size - 1, res.keys.count)
let pageData:[String] = Array(res.keys[start..<end])
let end = min(start + page.size - 1, keys.count)
let pageData:[String] = Array(keys[start..<end])

return await self.toRedisKeyModels(pageData)
} else {
Expand Down Expand Up @@ -818,7 +823,7 @@ extension RediStackClient {
self.logger.info("recursion zscan get items enough, max count: \(maxCount), current count: \(items.count)")
return (cursor, items)
} else {
let res = try await zscanAsync(key, keywords: keywords, cursor: cursor, count: 1000)
let res = try await zscanAsync(key, keywords: keywords, cursor: cursor, count: recursionSize)
let newItems:[(String, Double)?] = items + res.1

if res.0 == 0 {
Expand Down
1 change: 1 addition & 0 deletions redis-pro/Views/Components/Form/MPasswordField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct MPasswordField: View {
textField
} else {
secureField
.textContentType(.password)
}
}

Expand Down
18 changes: 9 additions & 9 deletions redis-pro/Views/Login/LoginForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ struct LoginForm: View {
Form {
Section {
VStack(alignment: .leading, spacing: 12) {
FormItemText(label: "Name", placeholder: "name", value: $redisModel.name).focusable()
FormItemText(label: "Host", placeholder: "host", value: $redisModel.host).focusable()
FormItemInt(label: "Port", placeholder: "port", value: $redisModel.port).focusable()
FormItemPassword(label: "Password", value: $redisModel.password).focusable()
FormItemInt(label: "Database", value: $redisModel.database).focusable()
FormItemText(label: "Name", placeholder: "name", value: $redisModel.name)
FormItemText(label: "Host", placeholder: "host", value: $redisModel.host)
FormItemInt(label: "Port", placeholder: "port", value: $redisModel.port)
FormItemPassword(label: "Password", value: $redisModel.password)
FormItemInt(label: "Database", value: $redisModel.database)
}
}

Section() {
Divider().padding(.vertical, 2)

VStack(alignment: .leading, spacing: 12) {
FormItemText(label: "SSH Host", placeholder: "name", value: $redisModel.sshHost).focusable()
FormItemInt(label: "SSH Port", placeholder: "port", value: $redisModel.sshPort).focusable()
FormItemText(label: "SSH User", placeholder: "host", value: $redisModel.sshUser).focusable()
FormItemPassword(label: "SSH Pass", value: $redisModel.sshPass).focusable()
FormItemText(label: "SSH Host", placeholder: "name", value: $redisModel.sshHost)
FormItemInt(label: "SSH Port", placeholder: "port", value: $redisModel.sshPort)
FormItemText(label: "SSH User", placeholder: "host", value: $redisModel.sshUser)
FormItemPassword(label: "SSH Pass", value: $redisModel.sshPass)
}
}
footer
Expand Down
2 changes: 1 addition & 1 deletion redis-pro/Views/RedisEditorView/HashEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension HashEditorView {
datasource.removeAll()
return
}

page.reset()
queryHashPage(redisKeyModel)
}

Expand Down
9 changes: 5 additions & 4 deletions redis-pro/Views/RedisEditorView/ListEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ struct ListEditorView: View {

}
}
.onChange(of: redisKeyModel, perform: { value in
.onChange(of: redisKeyModel.id, perform: { value in
logger.info("redis string value editor view change \(value)")
onLoad(value)
onLoad()
})
.onAppear {
logger.info("redis string value editor view init...")
onLoad(redisKeyModel)
onLoad()
}
}

Expand Down Expand Up @@ -163,12 +163,13 @@ struct ListEditorView: View {
}
}

func onLoad(_ redisKeyModel:RedisKeyModel) -> Void {
func onLoad() -> Void {

if redisKeyModel.type != RedisKeyTypeEnum.LIST.rawValue {
return
}

page.reset()
Task {
await queryPage(redisKeyModel)
}
Expand Down
9 changes: 5 additions & 4 deletions redis-pro/Views/RedisEditorView/SetEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ struct SetEditorView: View {
}
}
}
.onChange(of: redisKeyModel, perform: { value in
.onChange(of: redisKeyModel.id, perform: { value in
logger.info("redis set value editor view change \(value)")
onLoad(value)
onLoad()
})
.onAppear {
logger.info("redis set value editor view init...")
onLoad(redisKeyModel)
onLoad()
}
}

Expand Down Expand Up @@ -134,12 +134,13 @@ struct SetEditorView: View {
queryPage(redisKeyModel)
}

func onLoad(_ redisKeyModel:RedisKeyModel) -> Void {
func onLoad() -> Void {

if redisKeyModel.type != RedisKeyTypeEnum.SET.rawValue {
return
}

page.reset()
queryPage(redisKeyModel)
}

Expand Down
9 changes: 5 additions & 4 deletions redis-pro/Views/RedisEditorView/ZSetEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ struct ZSetEditorView: View {
}
}
}
.onChange(of: redisKeyModel, perform: { value in
.onChange(of: redisKeyModel.id, perform: { value in
logger.info("redis zset value editor view change \(value)")
onLoad(value)
onLoad()
})
.onAppear {
logger.info("redis zset value editor view init...")
onLoad(redisKeyModel)
onLoad()
}

}
Expand Down Expand Up @@ -140,11 +140,12 @@ struct ZSetEditorView: View {
queryPage(redisKeyModel)
}

func onLoad(_ redisKeyModel:RedisKeyModel) -> Void {
func onLoad() -> Void {

if redisKeyModel.isNew || redisKeyModel.type != RedisKeyTypeEnum.ZSET.rawValue {
return
}
page.reset()
queryPage(redisKeyModel)
}

Expand Down
56 changes: 56 additions & 0 deletions redis-proTests/RedisClientTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// RedisClientTest.swift
// redis-proTests
//
// Created by chengpan on 2022/2/7.
//

import XCTest
@testable import redis_pro

class RedisClientTest: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.

let redisModel = RedisModel()
redisModel.host = "101.35.200.189"
redisModel.port = 11379
redisModel.password = "zaqwedxRTY123456"
redisModel.database = 0

let redisInstance = RedisInstanceModel(redisModel: redisModel)

Task {
let _ = await redisInstance.connect(redisModel: redisModel)

for index in 10000...100000 {
// let _ = await redisInstance.getClient().hset("hash_perf", field: "k_\(index)", value: "\(index)")
// let _ = await redisInstance.getClient().zadd("zset_perf", score: Double(index), ele: "e_\(index)")
let _ = await redisInstance.getClient().set("string_\(index)", value: "\(index)", ex: -1)
}
}

sleep(1000000)
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}

0 comments on commit 3d987a7

Please sign in to comment.