mirror of https://gitee.com/maxjhandsome/pig
fix: 确保RedisConnection总是关闭
This commit is contained in:
parent
2159e746cf
commit
bc1ffd321c
|
@ -33,16 +33,15 @@ public class PigRedisTokenStore extends RedisTokenStore {
|
|||
@Override
|
||||
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
|
||||
super.storeAccessToken(token, authentication);
|
||||
try (RedisConnection connection = connectionFactory.getConnection()) {
|
||||
// KEY
|
||||
byte[] key = StrUtil.bytes(CacheConstants.PROJECT_OAUTH_TOKEN + authentication.getName());
|
||||
// value
|
||||
byte[] tokenVal = StrUtil.bytes(token.getValue());
|
||||
// 获取redis连接
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
RedisStringCommands stringCommand = connection.stringCommands();
|
||||
stringCommand.set(key, tokenVal, Expiration.seconds(token.getExpiresIn()),
|
||||
RedisStringCommands.SetOption.SET_IF_ABSENT);
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,13 +51,12 @@ public class PigRedisTokenStore extends RedisTokenStore {
|
|||
@Override
|
||||
public void removeAccessToken(OAuth2AccessToken accessToken) {
|
||||
super.removeAccessToken(accessToken);
|
||||
try (RedisConnection connection = connectionFactory.getConnection()) {
|
||||
// KEY
|
||||
OAuth2Authentication authentication = readAuthentication(accessToken);
|
||||
byte[] key = StrUtil.bytes(CacheConstants.PROJECT_OAUTH_TOKEN + authentication.getName());
|
||||
// 获取redis连接
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
connection.del(key);
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue