Skip to content

Commit

Permalink
点击一个失败的链接,正常redis服务器也无法登录bug修复 #48
Browse files Browse the repository at this point in the history
  • Loading branch information
chengpan168 committed Aug 13, 2022
1 parent dc47d4a commit 225032f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
8 changes: 4 additions & 4 deletions redis-pro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_ASSET_PATHS = "\"redis-pro/Preview Content\"";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = "redis-pro/Info.plist";
Expand All @@ -1249,7 +1249,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.cmushroom.redis-pro";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -1265,7 +1265,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_ASSET_PATHS = "\"redis-pro/Preview Content\"";
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
Expand All @@ -1275,7 +1275,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.cmushroom.redis-pro";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion redis-pro/Common/RedisClient/RediStackClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RediStackClient {

var viewStore:ViewStore<GlobalState, GlobalAction>?

init(redisModel:RedisModel) {
init(_ redisModel:RedisModel) {
self.redisModel = redisModel
}

Expand Down
41 changes: 27 additions & 14 deletions redis-pro/Model/RedisInsanceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,42 @@ class RedisInstanceModel:ObservableObject, Identifiable {
self.viewStore = ViewStore(globalStore)
}

// get client
func getClient() -> RediStackClient {
if rediStackClient != nil {
return rediStackClient!
if let client = rediStackClient {
return client
}

logger.info("get new redis client ...")
rediStackClient = RediStackClient(redisModel:redisModel)
rediStackClient?.setGlobalStore(self.viewStore)
return rediStackClient!
return initRedisClient(self.redisModel)
}

func connect(redisModel:RedisModel) async -> Bool {
logger.info("connect to redis server: \(redisModel)")
// init redis client
func initRedisClient(_ redisModel: RedisModel) -> RediStackClient {

logger.info("init new redis client, redisModel: \(redisModel)")
self.redisModel = redisModel
let r = await self.getClient().initConnection()
return r
let client = RediStackClient(redisModel)
client.setGlobalStore(self.viewStore)

self.rediStackClient = client
return client
}

func connect(_ redisModel:RedisModel) async -> Bool {
logger.info("connect to redis server: \(redisModel)")

let client = initRedisClient(redisModel)

return await client.ping()
}

func testConnect(_ redisModel:RedisModel) async -> Bool {
self.redisModel = redisModel
let pong = await self.getClient().ping()
self.close()
return pong
defer {
self.close()
}

logger.info("test connect to redis server: \(redisModel)")
return await initRedisClient(redisModel).ping()
}

func close() -> Void {
Expand Down
2 changes: 1 addition & 1 deletion redis-pro/Store/FavoriteStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ let favoriteReducer = Reducer<FavoriteState, FavoriteAction, FavoriteEnvironment
logger.info("connect to redis server, name: \(redisModel.name), host: \(redisModel.host)")

return Effect<FavoriteAction, Never>.task {
let r = await env.redisInstanceModel.connect(redisModel:redisModel)
let r = await env.redisInstanceModel.connect(redisModel)
logger.info("on connect to redis server: \(redisModel) , result: \(r)")
RedisDefaults.saveLastUse(redisModel)
return r ? .connectSuccess(redisModel) : .none
Expand Down
6 changes: 3 additions & 3 deletions redis-pro/Store/LoginStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum LoginAction:BindableAction,Equatable {
case save
case testConnect
case connect
case ping(Bool)
case setPingR(Bool)
case none
case binding(BindingAction<LoginState>)
}
Expand Down Expand Up @@ -100,11 +100,11 @@ let loginReducer = Reducer<LoginState, LoginAction, LoginEnvironment> {

return Effect<LoginAction, Never>.task {
let r = await env.redisInstanceModel.testConnect(redis)
return .ping(r)
return .setPingR(r)
}
.receive(on: env.mainQueue)
.eraseToEffect()
case let .ping(r):
case let .setPingR(r):
state.pingR = r ? "Connect successed!" : "Connect fail! "
state.loading = false
return .none
Expand Down

0 comments on commit 225032f

Please sign in to comment.