Skip to content

Commit 6ce5d72

Browse files
authoredMar 24, 2025
Support for new HFE API, hgetdel hgetex hsetex commands (#4095)
* support for hgetdel hgetex hsetex * add commands to wordlist * changes for review from @ggivo - make base class abstract package private - deprecate keepttl * adding java doc for elements in new HFE API * unifiedjedis java doc for new hfe api * fix test cases for new HFE API * move javadoc to interface
1 parent 680cf7f commit 6ce5d72

19 files changed

+1091
-168
lines changed
 

‎.github/wordlist.txt

+3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ hincrByFloat
176176
hiredis
177177
hlen
178178
hset
179+
hgetdel
180+
hgetex
181+
hsetex
179182
hsetnx
180183
hstrlen
181184
http

‎src/main/java/redis/clients/jedis/CommandObjects.java

+40-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import redis.clients.jedis.commands.ProtocolCommand;
2222
import redis.clients.jedis.json.*;
2323
import redis.clients.jedis.json.JsonProtocol.JsonCommand;
24-
import redis.clients.jedis.json.DefaultGsonObjectMapper;
25-
import redis.clients.jedis.json.JsonObjectMapper;
2624
import redis.clients.jedis.params.*;
2725
import redis.clients.jedis.resps.*;
2826
import redis.clients.jedis.search.*;
@@ -1020,10 +1018,30 @@ public final CommandObject<Long> hset(String key, Map<String, String> hash) {
10201018
return new CommandObject<>(addFlatMapArgs(commandArguments(HSET).key(key), hash), BuilderFactory.LONG);
10211019
}
10221020

1021+
public final CommandObject<Long> hsetex(String key, HSetExParams params, String field, String value) {
1022+
return new CommandObject<>(commandArguments(HSETEX).key(key)
1023+
.addParams(params).add(FIELDS).add(1).add(field).add(value), BuilderFactory.LONG);
1024+
}
1025+
1026+
public final CommandObject<Long> hsetex(String key, HSetExParams params, Map<String, String> hash) {
1027+
return new CommandObject<>(addFlatMapArgs(commandArguments(HSETEX).key(key)
1028+
.addParams(params).add(FIELDS).add(hash.size()), hash), BuilderFactory.LONG);
1029+
}
1030+
10231031
public final CommandObject<String> hget(String key, String field) {
10241032
return new CommandObject<>(commandArguments(HGET).key(key).add(field), BuilderFactory.STRING);
10251033
}
10261034

1035+
public final CommandObject<List<String>> hgetex(String key, HGetExParams params, String... fields) {
1036+
return new CommandObject<>(commandArguments(Command.HGETEX).key(key)
1037+
.addParams(params).add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.STRING_LIST);
1038+
}
1039+
1040+
public final CommandObject<List<String>> hgetdel(String key, String... fields) {
1041+
return new CommandObject<>(commandArguments(HGETDEL).key(key)
1042+
.add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.STRING_LIST);
1043+
}
1044+
10271045
public final CommandObject<Long> hsetnx(String key, String field, String value) {
10281046
return new CommandObject<>(commandArguments(HSETNX).key(key).add(field).add(value), BuilderFactory.LONG);
10291047
}
@@ -1044,10 +1062,30 @@ public final CommandObject<Long> hset(byte[] key, Map<byte[], byte[]> hash) {
10441062
return new CommandObject<>(addFlatMapArgs(commandArguments(HSET).key(key), hash), BuilderFactory.LONG);
10451063
}
10461064

1065+
public final CommandObject<Long> hsetex(byte[] key, HSetExParams params, byte[] field, byte[] value) {
1066+
return new CommandObject<>(commandArguments(HSETEX).key(key)
1067+
.addParams(params).add(FIELDS).add(1).add(field).add(value), BuilderFactory.LONG);
1068+
}
1069+
1070+
public final CommandObject<Long> hsetex(byte[] key, HSetExParams params, Map<byte[], byte[]> hash) {
1071+
return new CommandObject<>(addFlatMapArgs(commandArguments(HSETEX).key(key)
1072+
.addParams(params).add(FIELDS).add(hash.size()), hash), BuilderFactory.LONG);
1073+
}
1074+
10471075
public final CommandObject<byte[]> hget(byte[] key, byte[] field) {
10481076
return new CommandObject<>(commandArguments(HGET).key(key).add(field), BuilderFactory.BINARY);
10491077
}
10501078

1079+
public final CommandObject<List<byte[]>> hgetex(byte[] key, HGetExParams params, byte[]... fields) {
1080+
return new CommandObject<>(commandArguments(Command.HGETEX).key(key)
1081+
.addParams(params).add(FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.BINARY_LIST);
1082+
}
1083+
1084+
public final CommandObject<List<byte[]>> hgetdel(byte[] key, byte[]... fields) {
1085+
return new CommandObject<>(commandArguments(HGETDEL).key(key).add(FIELDS)
1086+
.add(fields.length).addObjects((Object[]) fields), BuilderFactory.BINARY_LIST);
1087+
}
1088+
10511089
public final CommandObject<Long> hsetnx(byte[] key, byte[] field, byte[] value) {
10521090
return new CommandObject<>(commandArguments(HSETNX).key(key).add(field).add(value), BuilderFactory.LONG);
10531091
}

‎src/main/java/redis/clients/jedis/Jedis.java

+48
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,18 @@ public long hset(final byte[] key, final Map<byte[], byte[]> hash) {
11671167
return connection.executeCommand(commandObjects.hset(key, hash));
11681168
}
11691169

1170+
@Override
1171+
public long hsetex(byte[] key, HSetExParams params, byte[] field, byte[] value) {
1172+
checkIsInMultiOrPipeline();
1173+
return connection.executeCommand(commandObjects.hsetex(key, params, field, value));
1174+
}
1175+
1176+
@Override
1177+
public long hsetex(byte[] key, HSetExParams params, Map<byte[], byte[]> hash){
1178+
checkIsInMultiOrPipeline();
1179+
return connection.executeCommand(commandObjects.hsetex(key, params, hash));
1180+
}
1181+
11701182
/**
11711183
* If key holds a hash, retrieve the value associated to the specified field.
11721184
* <p>
@@ -1183,6 +1195,18 @@ public byte[] hget(final byte[] key, final byte[] field) {
11831195
return connection.executeCommand(commandObjects.hget(key, field));
11841196
}
11851197

1198+
@Override
1199+
public List<byte[]> hgetex(byte[] key, HGetExParams params, byte[]... fields){
1200+
checkIsInMultiOrPipeline();
1201+
return connection.executeCommand(commandObjects.hgetex(key, params, fields));
1202+
}
1203+
1204+
@Override
1205+
public List<byte[]> hgetdel(byte[] key, byte[]... fields){
1206+
checkIsInMultiOrPipeline();
1207+
return connection.executeCommand(commandObjects.hgetdel(key, fields));
1208+
}
1209+
11861210
/**
11871211
* Set the specified hash field to the specified value if the field not exists. <b>Time
11881212
* complexity:</b> O(1)
@@ -5687,6 +5711,18 @@ public long hset(final String key, final Map<String, String> hash) {
56875711
return connection.executeCommand(commandObjects.hset(key, hash));
56885712
}
56895713

5714+
@Override
5715+
public long hsetex(String key, HSetExParams params, String field, String value) {
5716+
checkIsInMultiOrPipeline();
5717+
return connection.executeCommand(commandObjects.hsetex(key, params, field, value));
5718+
}
5719+
5720+
@Override
5721+
public long hsetex(String key, HSetExParams params, Map<String, String> hash) {
5722+
checkIsInMultiOrPipeline();
5723+
return connection.executeCommand(commandObjects.hsetex(key, params, hash));
5724+
}
5725+
56905726
/**
56915727
* If key holds a hash, retrieve the value associated to the specified field.
56925728
* <p>
@@ -5703,6 +5739,18 @@ public String hget(final String key, final String field) {
57035739
return connection.executeCommand(commandObjects.hget(key, field));
57045740
}
57055741

5742+
@Override
5743+
public List<String> hgetex(String key, HGetExParams params, String... fields) {
5744+
checkIsInMultiOrPipeline();
5745+
return connection.executeCommand(commandObjects.hgetex(key, params, fields));
5746+
}
5747+
5748+
@Override
5749+
public List<String> hgetdel(String key, String... fields) {
5750+
checkIsInMultiOrPipeline();
5751+
return connection.executeCommand(commandObjects.hgetdel(key, fields));
5752+
}
5753+
57065754
/**
57075755
* Set the specified hash field to the specified value if the field not exists. <b>Time
57085756
* complexity:</b> O(1)

‎src/main/java/redis/clients/jedis/PipeliningBase.java

+132
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,77 @@ public Response<Long> hset(String key, Map<String, String> hash) {
625625
return appendCommand(commandObjects.hset(key, hash));
626626
}
627627

628+
/**
629+
* Sets the specified field in the hash stored at key to the specified value with additional parameters,
630+
* and optionally set their expiration. Use `HSetExParams` object to specify expiration parameters.
631+
* This command can overwrite any existing fields in the hash.
632+
* If key does not exist, a new key holding a hash is created.
633+
*
634+
* @param key the key of the hash
635+
* @param params additional parameters for the HSETEX command
636+
* @param field the field in the hash to set
637+
* @param value the value to set in the specified field
638+
* @return 0 if no fields were set, 1 if all the fields were set
639+
*
640+
* @see HSetExParams
641+
*/
642+
@Override
643+
public Response<Long> hsetex(String key, HSetExParams params, String field, String value) {
644+
return appendCommand(commandObjects.hsetex(key, params, field, value));
645+
}
646+
647+
/**
648+
* Sets the specified fields in the hash stored at key to the specified values with additional parameters,
649+
* and optionally set their expiration. Use `HSetExParams` object to specify expiration parameters.
650+
* This command can overwrite any existing fields in the hash.
651+
* If key does not exist, a new key holding a hash is created.
652+
*
653+
* @param key the key of the hash
654+
* @param params the parameters for the HSetEx command
655+
* @param hash the map containing field-value pairs to set in the hash
656+
* @return 0 if no fields were set, 1 if all the fields were set
657+
*
658+
* @see HSetExParams
659+
*/
660+
@Override
661+
public Response<Long> hsetex(String key, HSetExParams params, Map<String, String> hash) {
662+
return appendCommand(commandObjects.hsetex(key, params, hash));
663+
}
664+
628665
@Override
629666
public Response<String> hget(String key, String field) {
630667
return appendCommand(commandObjects.hget(key, field));
631668
}
632669

670+
/**
671+
* Retrieves the values associated with the specified fields in a hash stored at the given key
672+
* and optionally sets their expiration. Use `HGetExParams` object to specify expiration parameters.
673+
*
674+
* @param key the key of the hash
675+
* @param params additional parameters for the HGETEX command
676+
* @param fields the fields whose values are to be retrieved
677+
* @return a list of the value associated with each field or nil if the field doesn’t exist.
678+
*
679+
* @see HGetExParams
680+
*/
681+
@Override
682+
public Response<List<String>> hgetex(String key, HGetExParams params, String... fields) {
683+
return appendCommand(commandObjects.hgetex(key, params, fields));
684+
}
685+
686+
/**
687+
* Retrieves the values associated with the specified fields in the hash stored at the given key
688+
* and then deletes those fields from the hash.
689+
*
690+
* @param key the key of the hash
691+
* @param fields the fields whose values are to be retrieved and then deleted
692+
* @return a list of values associated with the specified fields before they were deleted
693+
*/
694+
@Override
695+
public Response<List<String>> hgetdel(String key, String... fields) {
696+
return appendCommand(commandObjects.hgetdel(key, fields));
697+
}
698+
633699
@Override
634700
public Response<Long> hsetnx(String key, String field, String value) {
635701
return appendCommand(commandObjects.hsetnx(key, field, value));
@@ -1971,10 +2037,76 @@ public Response<Long> hset(byte[] key, Map<byte[], byte[]> hash) {
19712037
return appendCommand(commandObjects.hset(key, hash));
19722038
}
19732039

2040+
/**
2041+
* Sets the specified field in the hash stored at key to the specified value with additional parameters,
2042+
* and optionally set their expiration. Use `HSetExParams` object to specify expiration parameters.
2043+
* This command can overwrite any existing fields in the hash.
2044+
* If key does not exist, a new key holding a hash is created.
2045+
*
2046+
* @param key the key of the hash
2047+
* @param params the parameters for the HSetEx command
2048+
* @param field the field in the hash to set
2049+
* @param value the value to set in the specified field
2050+
* @return 0 if no fields were set, 1 if all the fields were set
2051+
*
2052+
* @see HSetExParams
2053+
*/
2054+
@Override
2055+
public Response<Long> hsetex(byte[] key, HSetExParams params, byte[] field, byte[] value) {
2056+
return appendCommand(commandObjects.hsetex(key, params, field, value));
2057+
}
2058+
2059+
/**
2060+
* Sets the specified fields in the hash stored at key to the specified values with additional parameters,
2061+
* and optionally set their expiration. Use `HSetExParams` object to specify expiration parameters.
2062+
* This command can overwrite any existing fields in the hash.
2063+
* If key does not exist, a new key holding a hash is created.
2064+
*
2065+
* @param key the key of the hash
2066+
* @param params the parameters for the HSetEx command
2067+
* @param hash the map containing field-value pairs to set in the hash
2068+
* @return 0 if no fields were set, 1 if all the fields were set
2069+
*
2070+
* @see HSetExParams
2071+
*/
2072+
@Override
2073+
public Response<Long> hsetex(byte[] key, HSetExParams params, Map<byte[], byte[]> hash) {
2074+
return appendCommand(commandObjects.hsetex(key, params, hash));
2075+
}
2076+
19742077
@Override
19752078
public Response<byte[]> hget(byte[] key, byte[] field) {
19762079
return appendCommand(commandObjects.hget(key, field));
19772080
}
2081+
2082+
/**
2083+
* Retrieves the values associated with the specified fields in a hash stored at the given key
2084+
* and optionally sets their expiration. Use `HGetExParams` object to specify expiration parameters.
2085+
*
2086+
* @param key the key of the hash
2087+
* @param params additional parameters for the HGETEX command
2088+
* @param fields the fields whose values are to be retrieved
2089+
* @return a list of the value associated with each field or nil if the field doesn’t exist.
2090+
*
2091+
* @see HGetExParams
2092+
*/
2093+
@Override
2094+
public Response<List<byte[]>> hgetex(byte[] key, HGetExParams params, byte[]... fields) {
2095+
return appendCommand(commandObjects.hgetex(key, params, fields));
2096+
}
2097+
2098+
/**
2099+
* Retrieves the values associated with the specified fields in the hash stored at the given key
2100+
* and then deletes those fields from the hash.
2101+
*
2102+
* @param key the key of the hash
2103+
* @param fields the fields whose values are to be retrieved and then deleted
2104+
* @return a list of values associated with the specified fields before they were deleted
2105+
*/
2106+
@Override
2107+
public Response<List<byte[]>> hgetdel(byte[] key, byte[]... fields) {
2108+
return appendCommand(commandObjects.hgetdel(key, fields));
2109+
}
19782110

19792111
@Override
19802112
public Response<Long> hsetnx(byte[] key, byte[] field, byte[] value) {

‎src/main/java/redis/clients/jedis/Protocol.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public static enum Command implements ProtocolCommand {
292292
SETBIT, GETBIT, BITPOS, SETRANGE, GETRANGE, BITCOUNT, BITOP, BITFIELD, BITFIELD_RO, // <-- bit (string)
293293
HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, HSTRLEN,
294294
HEXPIRE, HPEXPIRE, HEXPIREAT, HPEXPIREAT, HTTL, HPTTL, HEXPIRETIME, HPEXPIRETIME, HPERSIST,
295-
HRANDFIELD, HINCRBYFLOAT, // <-- hash
295+
HRANDFIELD, HINCRBYFLOAT, HSETEX, HGETEX, HGETDEL, // <-- hash
296296
RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, BLPOP, BRPOP, LINSERT, LPOS,
297297
RPOPLPUSH, BRPOPLPUSH, BLMOVE, LMOVE, LMPOP, BLMPOP, LPUSHX, RPUSHX, // <-- list
298298
SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SRANDMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE,
@@ -339,7 +339,7 @@ public static enum Keyword implements Rawable {
339339
DELETE, LIBRARYNAME, WITHCODE, DESCRIPTION, GETKEYS, GETKEYSANDFLAGS, DOCS, FILTERBY, DUMP,
340340
MODULE, ACLCAT, PATTERN, DOCTOR, LATEST, HISTORY, USAGE, SAMPLES, PURGE, STATS, LOADEX, CONFIG,
341341
ARGS, RANK, NOW, VERSION, ADDR, SKIPME, USER, LADDR, FIELDS,
342-
CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NOVALUES, MAXAGE;
342+
CHANNELS, NUMPAT, NUMSUB, SHARDCHANNELS, SHARDNUMSUB, NOVALUES, MAXAGE, FXX, FNX;
343343

344344
private final byte[] raw;
345345

‎src/main/java/redis/clients/jedis/UnifiedJedis.java

+40
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,30 @@ public long hset(String key, Map<String, String> hash) {
14791479
return executeCommand(commandObjects.hset(key, hash));
14801480
}
14811481

1482+
@Override
1483+
public long hsetex(String key, HSetExParams params, String field, String value) {
1484+
return executeCommand(commandObjects.hsetex(key, params, field, value));
1485+
}
1486+
1487+
@Override
1488+
public long hsetex(String key, HSetExParams params, Map<String, String> hash) {
1489+
return executeCommand(commandObjects.hsetex(key, params, hash));
1490+
}
1491+
14821492
@Override
14831493
public String hget(String key, String field) {
14841494
return executeCommand(commandObjects.hget(key, field));
14851495
}
1496+
1497+
@Override
1498+
public List<String> hgetex(String key, HGetExParams params, String... fields) {
1499+
return executeCommand(commandObjects.hgetex(key, params, fields));
1500+
}
1501+
1502+
@Override
1503+
public List<String> hgetdel(String key, String... fields) {
1504+
return executeCommand(commandObjects.hgetdel(key, fields));
1505+
}
14861506

14871507
@Override
14881508
public long hsetnx(String key, String field, String value) {
@@ -1509,11 +1529,31 @@ public long hset(byte[] key, Map<byte[], byte[]> hash) {
15091529
return executeCommand(commandObjects.hset(key, hash));
15101530
}
15111531

1532+
@Override
1533+
public long hsetex(byte[] key, HSetExParams params, byte[] field, byte[] value) {
1534+
return executeCommand(commandObjects.hsetex(key, params, field, value));
1535+
}
1536+
1537+
@Override
1538+
public long hsetex(byte[] key, HSetExParams params, Map<byte[], byte[]> hash) {
1539+
return executeCommand(commandObjects.hsetex(key, params, hash));
1540+
}
1541+
15121542
@Override
15131543
public byte[] hget(byte[] key, byte[] field) {
15141544
return executeCommand(commandObjects.hget(key, field));
15151545
}
15161546

1547+
@Override
1548+
public List<byte[]> hgetex(byte[] key, HGetExParams params, byte[]... fields) {
1549+
return executeCommand(commandObjects.hgetex(key, params, fields));
1550+
}
1551+
1552+
@Override
1553+
public List<byte[]> hgetdel(byte[] key, byte[]... fields) {
1554+
return executeCommand(commandObjects.hgetdel(key, fields));
1555+
}
1556+
15171557
@Override
15181558
public long hsetnx(byte[] key, byte[] field, byte[] value) {
15191559
return executeCommand(commandObjects.hsetnx(key, field, value));

0 commit comments

Comments
 (0)
Please sign in to comment.