Skip to content

Commit

Permalink
Merge pull request #4 from westboy/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
westboy authored Dec 5, 2022
2 parents 22074b0 + 2db0be5 commit 4f3d8ff
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 237 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

![Screenshot](screenshot/redisfront-win11.png)

RedisFront 是基于 Swing 和 Lettuce 开发的跨平台 Redis 桌面客户端工具, 支持 Redis 单机模式, 集群模式, 哨兵模式以及 SSH 隧道连接, 可轻松管理Redis数据.
RedisFront 是一款开源免费的跨平台 Redis 桌面客户端工具, 支持单机模式, 集群模式, 哨兵模式以及 SSH 隧道连接, 可轻松管理Redis缓存数据.

### 下载

Expand Down
3 changes: 2 additions & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

![Screenshot](screenshot/redisfront-win11.png)

RedisFront is a cross-platform redis desktop client tool developed based on swing and lattice supports redis stand-alone mode, cluster mode, sentinel mode and SSH tunnel connection, and can easily manage redis data
RedisFront is an open source and free cross platform Redis desktop client tool, which supports stand-alone mode, cluster mode, sentinel mode and SSH tunnel connection, and can easily manage Redis cache data

### Download

[https://github.com/westboy/RedisFront/releases](https://github.com/westboy/RedisFront/releases)
Expand Down
2 changes: 1 addition & 1 deletion assets/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "1.0.4"}
{"version": "1.0.5"}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ buildscript {

plugins.apply("io.github.fvarrui.javapackager.plugin")

version = "1.0.4"
version = "1.0.5"

val flatlafVersion = "2.4"
val hutoolVersion = "5.8.7"
Expand Down
Binary file modified screenshot/redisfront-win11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/java/com/redisfront/commons/constant/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ public class Const {
public static final String LOG_FILE_PATH = Const.DATA_PATH + File.separator + "logs" + File.separator + "redis-front.log";

public static final String DERBY_LOG_FILE = Const.DATA_PATH + File.separator + "derby" + File.separator + "derby.log";
public static final String CURRENT_DIR_DERBY_LOG_FILE = "." + File.separator + "derby" + File.separator + "derby.log";
public static final String DERBY_LOG_FILE_PATH = Const.DATA_PATH + File.separator + "derby";
public static final String CURRENT_DIR_DERBY_LOG_FILE_PATH = "." + File.separator + "derby";
public static final String DERBY_DATA_PATH = Const.DATA_PATH + File.separator + "derby" + File.separator + "data;";

public static final String CURRENT_DIR_DERBY_DATA_PATH = "." + File.separator + "derby" + File.separator + "data;";

public static final String LOG_FILE = "LOG_FILE";

public static final String PACKAGE_NAME = "com.redisfront";
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/redisfront/commons/util/DerbyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ public static DerbyUtils getInstance() {

public static void init() {
try {
var derbyFolder = new File(Const.DERBY_LOG_FILE_PATH);
var isCurrentDir = FileUtil.exist(Const.CURRENT_DIR_DERBY_LOG_FILE_PATH);
var derbyFolder = new File(isCurrentDir ? Const.CURRENT_DIR_DERBY_LOG_FILE_PATH : Const.DERBY_LOG_FILE_PATH);
if (FileUtil.isEmpty(derbyFolder)) {
var dirCreated = derbyFolder.mkdir();
log.info("create Derby Log dir created: {}", dirCreated);
var fileCreated = new File(Const.DERBY_LOG_FILE).createNewFile();
var fileCreated = new File(isCurrentDir ? Const.CURRENT_DIR_DERBY_LOG_FILE : Const.DERBY_LOG_FILE).createNewFile();
log.info("create Derby Log File created: {}", fileCreated);
}
if (Arrays.stream(Objects.requireNonNull(derbyFolder.listFiles())).noneMatch(file -> Fn.equal(file.getName().toLowerCase(), "data"))) {
PrefUtils.getState().put(Const.KEY_APP_DATABASE_INIT, Boolean.TRUE.toString());
}
System.setProperty("derby.stream.error.file", Const.DERBY_LOG_FILE);
System.setProperty("derby.stream.error.file", (isCurrentDir ? Const.CURRENT_DIR_DERBY_LOG_FILE : Const.DERBY_LOG_FILE));
Class.forName("org.apache.derby.iapi.jdbc.InternalDriver");
conn = DriverManager.getConnection("jdbc:derby:" + Const.DERBY_DATA_PATH + "create=true");
conn = DriverManager.getConnection("jdbc:derby:" + (isCurrentDir ? Const.CURRENT_DIR_DERBY_DATA_PATH : Const.DERBY_DATA_PATH) + "create=true");
} catch (Exception e) {
log.error("Derby init failed - {}", e.getMessage());
throw new RedisFrontException(e, true);
Expand Down
50 changes: 39 additions & 11 deletions src/main/java/com/redisfront/commons/util/LettuceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.redisfront.commons.constant.Enum;
import com.redisfront.commons.func.Fn;
import com.redisfront.model.ConnectInfo;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.StaticCredentialsProvider;
import io.lettuce.core.*;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.ClusterClientOptions;
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions;
Expand All @@ -16,6 +14,7 @@
import io.lettuce.core.sentinel.api.sync.RedisSentinelCommands;
import io.netty.util.internal.StringUtil;

import java.io.File;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -39,12 +38,24 @@ private synchronized static RedisClusterClient getRedisClusterClient(RedisURI re
.enableAdaptiveRefreshTrigger(ClusterTopologyRefreshOptions.RefreshTrigger.MOVED_REDIRECT, ClusterTopologyRefreshOptions.RefreshTrigger.PERSISTENT_RECONNECTS)
.enablePeriodicRefresh(Duration.ofMinutes(30))
.build();
var clusterClientOptions = ClusterClientOptions.builder()
var clientOptions = ClusterClientOptions.builder()
.topologyRefreshOptions(clusterTopologyRefreshOptions)
.build();
clusterClient.setOptions(clusterClientOptions);
var isSSH = connectInfo.connectMode().equals(Enum.Connect.SSH);
if (isSSH) {

if (connectInfo.ssl()) {
if (Fn.isNotEmpty(connectInfo.sslConfig().getPassword()) || Fn.isNotEmpty(connectInfo.sslConfig().getPublicKeyFilePath())) {
clientOptions = clientOptions
.mutate()
.sslOptions(SslOptions.builder()
.jdkSslProvider()
.truststore(new File(connectInfo.sslConfig().getPublicKeyFilePath()), connectInfo.sslConfig().getPassword())
.build())
.build();
}
}

clusterClient.setOptions(clientOptions);
if (Fn.equal(connectInfo.connectMode(), Enum.Connect.SSH)) {
Map<Integer, Integer> clusterTempPort = new HashMap<>();
for (RedisClusterNode partition : clusterClient.getPartitions()) {
var remotePort = partition.getUri().getPort();
Expand Down Expand Up @@ -130,6 +141,15 @@ public synchronized static <T> T sentinelExec(ConnectInfo connectInfo, Function<
public synchronized static void run(ConnectInfo connectInfo, Consumer<RedisCommands<String, String>> consumer) {
var redisURI = getRedisURI(connectInfo);
var redisClient = RedisClient.create(redisURI);
if (connectInfo.ssl()) {
if (Fn.isNotEmpty(connectInfo.sslConfig().getPassword()) || Fn.isNotEmpty(connectInfo.sslConfig().getPublicKeyFilePath())) {
var sslOptions = SslOptions.builder()
.jdkSslProvider()
.truststore(new File(connectInfo.sslConfig().getPublicKeyFilePath()), connectInfo.sslConfig().getPassword())
.build();
redisClient.setOptions(ClientOptions.builder().sslOptions(sslOptions).build());
}
}
try {
JschUtils.openSession(connectInfo);
try (var connection = redisClient.connect()) {
Expand All @@ -149,6 +169,15 @@ public synchronized static void run(ConnectInfo connectInfo, Consumer<RedisComma
public synchronized static <T> T exec(ConnectInfo connectInfo, Function<RedisCommands<String, String>, T> function) {
var redisURI = getRedisURI(connectInfo);
var redisClient = RedisClient.create(redisURI);
if (connectInfo.ssl()) {
if (Fn.isNotEmpty(connectInfo.sslConfig().getPassword()) || Fn.isNotEmpty(connectInfo.sslConfig().getPublicKeyFilePath())) {
var sslOptions = SslOptions.builder()
.jdkSslProvider()
.truststore(new File(connectInfo.sslConfig().getPublicKeyFilePath()), connectInfo.sslConfig().getPassword())
.build();
redisClient.setOptions(ClientOptions.builder().sslOptions(sslOptions).build());
}
}
try {
JschUtils.openSession(connectInfo);
try (var connection = redisClient.connect()) {
Expand All @@ -166,8 +195,7 @@ public synchronized static <T> T exec(ConnectInfo connectInfo, Function<RedisCom


public synchronized static RedisURI getRedisURI(ConnectInfo connectInfo) {
var isSSH = connectInfo.connectMode().equals(Enum.Connect.SSH);
if (isSSH) {
if (Fn.equal(connectInfo.connectMode(), Enum.Connect.SSH)) {
connectInfo.setLocalHost("127.0.0.1");
connectInfo.setLocalPort(RandomUtil.randomInt(32768, 65535));
}
Expand All @@ -181,8 +209,8 @@ public synchronized static RedisURI getRedisURI(ConnectInfo connectInfo) {
}

var redisURI = RedisURI.builder()
.withHost(isSSH ? connectInfo.getLocalHost() : host)
.withPort(isSSH ? connectInfo.getLocalPort() : connectInfo.port())
.withHost(Fn.equal(connectInfo.connectMode(), Enum.Connect.SSH) ? connectInfo.getLocalHost() : host)
.withPort(Fn.equal(connectInfo.connectMode(), Enum.Connect.SSH) ? connectInfo.getLocalPort() : connectInfo.port())
.withSsl(connectInfo.ssl())
.withDatabase(connectInfo.database())
.withTimeout(Duration.ofMinutes(1))
Expand Down
91 changes: 0 additions & 91 deletions src/main/java/com/redisfront/commons/util/SslUtils.java

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/java/com/redisfront/commons/util/TreeUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.redisfront.commons.util;

import cn.hutool.core.util.StrUtil;
import com.redisfront.commons.func.Fn;
import com.redisfront.model.TreeNodeInfo;

Expand Down Expand Up @@ -39,8 +40,21 @@ public static synchronized DefaultTreeModel toTreeModel(Set<String> rows, String
public static StringTreeMap toStringTreeMap(Set<String> rows, String delim) {
var root = new StringTreeMap();
for (var row : rows.stream().parallel().sorted().toList()) {

var node = root;
var cells = row.split(delim);

var keyLength = (StrUtil.join("", (Object) cells).toCharArray().length + cells.length - 1);

if (row.contains(delim) && row.toCharArray().length - keyLength >= 2) {
var lastStr = StrUtil.sub(row, keyLength, row.toCharArray().length - 1);
ArrayList<String> tmpList = new ArrayList<>(Arrays.asList(cells));
tmpList.add(lastStr);
cells = tmpList.toArray(new String[]{});
} else if (Fn.endsWith(row, delim)) {
cells[cells.length - 1] = cells[cells.length - 1].concat(delim);
}

for (int i = 0; i < cells.length; i++) {
String cell = cells[i];
var child = node.get(cell);
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/redisfront/ui/component/MainMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void updateUI() {
setMnemonic(LocaleUtils.getMenu("Menu.File.Open").mnemonic());
}
};
openConnectMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() | KeyEvent.CTRL_DOWN_MASK));
openConnectMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx() | KeyEvent.CTRL_DOWN_MASK));
openConnectMenu.addActionListener(e -> OpenConnectDialog.showOpenConnectDialog(
//打开连接回调
((connectInfo) -> MainWindowForm.getInstance().addTabActionPerformed(connectInfo)),
Expand Down Expand Up @@ -176,6 +176,23 @@ public void updateUI() {

aboutMenuItem.addActionListener((e) -> FutureUtils.runAsync(this::aboutActionPerformed));
aboutMenu.add(aboutMenuItem);

aboutMenu.add(new JSeparator());
var aliYunItem = new JMenuItem() {
@Override
public void updateUI() {
super.updateUI();
setText("<html><b color=\"red\">阿里云</b><i color=\"orange\">~新人特惠</i></html>");
}
};
aliYunItem.addActionListener((e) -> FutureUtils.runAsync(() -> {
try {
Desktop.getDesktop().browse(new URI("https://www.aliyun.com/daily-act/ecs/activity_selection?userCode=fdfwuy9i"));
} catch (IOException | URISyntaxException ex) {
}
}));
aboutMenu.add(aliYunItem);

add(aboutMenu);

add(Box.createGlue());
Expand Down
Loading

0 comments on commit 4f3d8ff

Please sign in to comment.