1818 */
1919package dev .noah .perplayerkit .storage ;
2020
21- import dev .noah .perplayerkit .PerPlayerKit ;
2221import org .bukkit .plugin .Plugin ;
2322import redis .clients .jedis .Jedis ;
2423import redis .clients .jedis .JedisPool ;
@@ -62,7 +61,7 @@ public boolean isConnected() {
6261 try (Jedis jedis = getConnection ()) {
6362 return "PONG" .equals (jedis .ping ());
6463 } catch (Exception e ) {
65- e . printStackTrace ( );
64+ logRedisFailure ( "connectivity check" , e );
6665 return false ;
6766 }
6867 }
@@ -84,7 +83,7 @@ public void keepAlive() {
8483 try (Jedis jedis = getConnection ()) {
8584 jedis .ping ();
8685 } catch (Exception e ) {
87- e . printStackTrace ( );
86+ logRedisFailure ( "keepalive" , e );
8887 }
8988 }
9089
@@ -93,7 +92,7 @@ public void saveKitDataByID(String kitID, String data) {
9392 try (Jedis jedis = getConnection ()) {
9493 jedis .set (kitID , data );
9594 } catch (Exception e ) {
96- e . printStackTrace ( );
95+ logRedisFailure ( "save operation for kit ID " + kitID , e );
9796 }
9897 }
9998
@@ -103,7 +102,7 @@ public String getKitDataByID(String kitID) {
103102 String data = jedis .get (kitID );
104103 return data == null ? "Error" : data ;
105104 } catch (Exception e ) {
106- e . printStackTrace ( );
105+ logRedisFailure ( "read operation for kit ID " + kitID , e );
107106 return "Error" ;
108107 }
109108 }
@@ -113,7 +112,7 @@ public boolean doesKitExistByID(String kitID) {
113112 try (Jedis jedis = getConnection ()) {
114113 return jedis .exists (kitID );
115114 } catch (Exception e ) {
116- e . printStackTrace ( );
115+ logRedisFailure ( "existence check for kit ID " + kitID , e );
117116 return false ;
118117 }
119118 }
@@ -123,7 +122,7 @@ public void deleteKitByID(String kitID) {
123122 try (Jedis jedis = getConnection ()) {
124123 jedis .del (kitID );
125124 } catch (Exception e ) {
126- e . printStackTrace ( );
125+ logRedisFailure ( "delete operation for kit ID " + kitID , e );
127126 }
128127 }
129128
@@ -140,8 +139,15 @@ public Set<String> getAllKitIDs() {
140139 try (Jedis jedis = getConnection ()) {
141140 kitIDs .addAll (jedis .keys ("*" ));
142141 } catch (Exception e ) {
143- e . printStackTrace ( );
142+ logRedisFailure ( "list operation" , e );
144143 }
145144 return kitIDs ;
146145 }
146+
147+ private void logRedisFailure (String operation , Exception exception ) {
148+ if (plugin == null || plugin .getLogger () == null ) {
149+ return ;
150+ }
151+ plugin .getLogger ().fine ("Redis " + operation + " failed: " + exception .getMessage ());
152+ }
147153}
0 commit comments