Skip to content

Commit e04ff36

Browse files
committed
✨ feat: add a lot of functions wrapper response #5
1 parent 02f6eb3 commit e04ff36

File tree

3 files changed

+482
-2
lines changed

3 files changed

+482
-2
lines changed

plugin/src/main/groovy/org/redis4j/common/Redis4j.java

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ public static long increaseKey(String key) {
12431243
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
12441244
* @return The incremented value of the key, or -1 if an error occurs.
12451245
*/
1246-
public static long increaseKey( String key, Redis4jWrapCallback callback) {
1246+
public static long increaseKey(String key, Redis4jWrapCallback callback) {
12471247
Redis4jService e = jProvider();
12481248
if (e == null) {
12491249
return -1;
@@ -1284,6 +1284,24 @@ public static long decreaseKey(String key) {
12841284
return e.decreaseKey(dispatch(), key);
12851285
}
12861286

1287+
/**
1288+
* Decreases the value of a numeric key in Redis, with an optional callback for handling exceptions.
1289+
* If the dispatch template or key is null or empty, returns -1 indicating failure.
1290+
* Uses Redis execute method to atomically decrement the key value.
1291+
* Logs any exceptions that occur during the operation.
1292+
*
1293+
* @param key The key whose value is to be decremented.
1294+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1295+
* @return The decremented value of the key, or -1 if an error occurs.
1296+
*/
1297+
public static long decreaseKey(String key, Redis4jWrapCallback callback) {
1298+
Redis4jService e = jProvider();
1299+
if (e == null) {
1300+
return -1;
1301+
}
1302+
return e.decreaseKey(dispatch(), key, callback);
1303+
}
1304+
12871305
/**
12881306
* Decreases the value of a numeric key in Redis.
12891307
* If the dispatch template or key is null or empty, returns -1 indicating failure.
@@ -1318,6 +1336,25 @@ public static long increaseKeyBy(String key, long value) {
13181336
return e.increaseKeyBy(dispatch(), key, value);
13191337
}
13201338

1339+
/**
1340+
* Increases the value of a numeric key in Redis by a specified increment, with an optional callback for handling exceptions.
1341+
* If the dispatch template, key, or increment value is invalid (null, empty, negative), returns -1 indicating failure.
1342+
* Uses Redis execute method with a callback to atomically increment the key value by the specified amount.
1343+
* Logs any exceptions that occur during the operation.
1344+
*
1345+
* @param key The key whose value is to be incremented.
1346+
* @param value The amount by which to increment the key's value.
1347+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1348+
* @return The incremented value of the key, or -1 if an error occurs.
1349+
*/
1350+
public static long increaseKeyBy(String key, long value, Redis4jWrapCallback callback) {
1351+
Redis4jService e = jProvider();
1352+
if (e == null) {
1353+
return -1;
1354+
}
1355+
return e.increaseKeyBy(dispatch(), key, value, callback);
1356+
}
1357+
13211358
/**
13221359
* Increases the value of a numeric key in Redis by a specified increment.
13231360
* If the dispatch template, key, or increment value is invalid (null, empty, negative), returns -1 indicating failure.
@@ -1353,6 +1390,25 @@ public static long decreaseKeyBy(String key, long value) {
13531390
return e.decreaseKeyBy(dispatch(), key, value);
13541391
}
13551392

1393+
/**
1394+
* Decreases the value of a numeric key in Redis by a specified decrement, with an optional callback for handling exceptions.
1395+
* If the dispatch template, key, or decrement value is invalid (null, empty, negative), returns -1 indicating failure.
1396+
* Uses Redis execute method with a callback to atomically decrement the key value by the specified amount.
1397+
* Logs any exceptions that occur during the operation.
1398+
*
1399+
* @param key The key whose value is to be decremented.
1400+
* @param value The amount by which to decrement the key's value.
1401+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1402+
* @return The decremented value of the key, or -1 if an error occurs.
1403+
*/
1404+
public static long decreaseKeyBy(String key, long value, Redis4jWrapCallback callback) {
1405+
Redis4jService e = jProvider();
1406+
if (e == null) {
1407+
return -1;
1408+
}
1409+
return e.decreaseKeyBy(dispatch(), key, value, callback);
1410+
}
1411+
13561412
/**
13571413
* Decreases the value of a numeric key in Redis by a specified decrement.
13581414
* If the dispatch template, key, or decrement value is invalid (null, empty, negative), returns -1 indicating failure.
@@ -1388,6 +1444,26 @@ public static long increaseKeyEx(String key, long timeout, TimeUnit unit) {
13881444
return e.increaseKeyEx(dispatch(), key, timeout, unit);
13891445
}
13901446

1447+
/**
1448+
* Increases the value of a numeric key in Redis and sets an expiration time for the key, with an optional callback for handling exceptions.
1449+
* If the dispatch template, key, timeout, or time unit is invalid (null, empty, negative), returns -1 indicating failure.
1450+
* Uses the {@link #increaseKey} method to increment the key's value and then sets an expiration using the provided timeout and unit.
1451+
* Logs any exceptions that occur during the operation.
1452+
*
1453+
* @param key The key whose value is to be incremented and set with expiration.
1454+
* @param timeout The duration after which the key should expire.
1455+
* @param unit The time unit of the expiration timeout.
1456+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1457+
* @return The incremented value of the key, or -1 if an error occurs.
1458+
*/
1459+
public static long increaseKeyEx(String key, long timeout, TimeUnit unit, Redis4jWrapCallback callback) {
1460+
Redis4jService e = jProvider();
1461+
if (e == null) {
1462+
return -1;
1463+
}
1464+
return e.increaseKeyEx(dispatch(), key, timeout, unit, callback);
1465+
}
1466+
13911467
/**
13921468
* Increases the value of a numeric key in Redis and sets an expiration time for the key.
13931469
* If the dispatch template, key, timeout, or time unit is invalid (null, empty, negative), returns -1 indicating failure.
@@ -1423,6 +1499,26 @@ public static long decreaseKeyEx(String key, long timeout, TimeUnit unit) {
14231499
return e.decreaseKeyEx(dispatch(), key, timeout, unit);
14241500
}
14251501

1502+
/**
1503+
* Decreases the value of a numeric key in Redis and sets an expiration time for the key, with an optional callback for handling exceptions.
1504+
* If the dispatch template, key, timeout, or time unit is invalid (null, empty, negative), returns -1 indicating failure.
1505+
* Uses the {@link #decreaseKey} method to decrement the key's value and then sets an expiration using the provided timeout and unit.
1506+
* Logs any exceptions that occur during the operation.
1507+
*
1508+
* @param key The key whose value is to be decremented and set with expiration.
1509+
* @param timeout The duration after which the key should expire.
1510+
* @param unit The time unit of the expiration timeout.
1511+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1512+
* @return The decremented value of the key, or -1 if an error occurs.
1513+
*/
1514+
public static long decreaseKeyEx(String key, long timeout, TimeUnit unit, Redis4jWrapCallback callback) {
1515+
Redis4jService e = jProvider();
1516+
if (e == null) {
1517+
return -1;
1518+
}
1519+
return e.decreaseKeyEx(dispatch(), key, timeout, unit, callback);
1520+
}
1521+
14261522
/**
14271523
* Decreases the value of a numeric key in Redis and sets an expiration time for the key.
14281524
* If the dispatch template, key, timeout, or time unit is invalid (null, empty, negative), returns -1 indicating failure.
@@ -1459,6 +1555,27 @@ public static long increaseKeyByEx(String key, long value, long timeout, TimeUni
14591555
return e.increaseKeyByEx(dispatch(), key, value, timeout, unit);
14601556
}
14611557

1558+
/**
1559+
* Increases the value of a numeric key in Redis by a specified increment and sets an expiration time for the key, with an optional callback for handling exceptions.
1560+
* If the dispatch template, key, timeout, unit, or value is invalid (null, empty, negative), returns -1 indicating failure.
1561+
* Uses the {@link #increaseKeyBy} method to increment the key's value by the specified amount and then sets an expiration using the provided timeout and unit.
1562+
* Logs any exceptions that occur during the operation.
1563+
*
1564+
* @param key The key whose value is to be incremented and set with expiration.
1565+
* @param value The amount by which to increment the key's value.
1566+
* @param timeout The duration after which the key should expire.
1567+
* @param unit The time unit of the expiration timeout.
1568+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1569+
* @return The incremented value of the key, or -1 if an error occurs.
1570+
*/
1571+
public static long increaseKeyByEx(String key, long value, long timeout, TimeUnit unit, Redis4jWrapCallback callback) {
1572+
Redis4jService e = jProvider();
1573+
if (e == null) {
1574+
return -1;
1575+
}
1576+
return e.increaseKeyByEx(dispatch(), key, value, timeout, unit, callback);
1577+
}
1578+
14621579
/**
14631580
* Increases the value of a numeric key in Redis by a specified increment and sets an expiration time for the key.
14641581
* If the dispatch template, key, timeout, unit, or value is invalid (null, empty, negative), returns -1 indicating failure.
@@ -1496,6 +1613,27 @@ public static long decreaseKeyByEx(String key, long value, long timeout, TimeUni
14961613
return e.decreaseKeyByEx(dispatch(), key, value, timeout, unit);
14971614
}
14981615

1616+
/**
1617+
* Decreases the value of a numeric key in Redis by a specified decrement and sets an expiration time for the key, with an optional callback for handling exceptions.
1618+
* If the dispatch template, key, timeout, unit, or value is invalid (null, empty, negative), returns -1 indicating failure.
1619+
* Uses the {@link #decreaseKeyBy} method to decrement the key's value by the specified amount and then sets an expiration using the provided timeout and unit.
1620+
* Logs any exceptions that occur during the operation.
1621+
*
1622+
* @param key The key whose value is to be decremented and set with expiration.
1623+
* @param value The amount by which to decrement the key's value.
1624+
* @param timeout The duration after which the key should expire.
1625+
* @param unit The time unit of the expiration timeout.
1626+
* @param callback An optional callback for handling exceptions, an instance of {@link Redis4jWrapCallback}.
1627+
* @return The decremented value of the key, or -1 if an error occurs.
1628+
*/
1629+
public static long decreaseKeyByEx(String key, long value, long timeout, TimeUnit unit, Redis4jWrapCallback callback) {
1630+
Redis4jService e = jProvider();
1631+
if (e == null) {
1632+
return -1;
1633+
}
1634+
return e.decreaseKeyByEx(dispatch(), key, value, timeout, unit, callback);
1635+
}
1636+
14991637
/**
15001638
* Decreases the value of a numeric key in Redis by a specified decrement and sets an expiration time for the key.
15011639
* If the dispatch template, key, timeout, unit, or value is invalid (null, empty, negative), returns -1 indicating failure.
@@ -1961,7 +2099,9 @@ public static WrapResponse<?> wget(String key) {
19612099
case "zset":
19622100
return new HttpWrapBuilder<>().ok(command.zrange(key, 0, -1)).customFields("redis_key_type_stored", "zset").build();
19632101
default:
1964-
return new HttpWrapBuilder<>().message(String.format("unsupported type: %s", type)).statusCode(HttpStatusBuilder.UN_PROCESSABLE_ENTITY).customFields("redis_key_type_stored_unsupported", type).build();
2102+
return new HttpWrapBuilder<>().message(String.format("unsupported type: %s", type))
2103+
.statusCode(HttpStatusBuilder.UN_PROCESSABLE_ENTITY)
2104+
.customFields("redis_key_type_stored_unsupported", type).build();
19652105
}
19662106
}
19672107
}

0 commit comments

Comments
 (0)