Skip to content

Commit 4d3dcdc

Browse files
Support hash filed expiration commands
1 parent b631ea3 commit 4d3dcdc

14 files changed

+1916
-4
lines changed

src/main/java/io/valkey/CommandObjects.java

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import io.valkey.params.GeoRadiusStoreParam;
3434
import io.valkey.params.GeoSearchParam;
3535
import io.valkey.params.GetExParams;
36+
import io.valkey.params.HGetExParams;
37+
import io.valkey.params.HSetExParams;
3638
import io.valkey.params.LCSParams;
3739
import io.valkey.params.LPosParams;
3840
import io.valkey.params.MigrateParams;
@@ -1242,6 +1244,171 @@ public final CommandObject<ScanResult<byte[]>> hscanNoValues(byte[] key, byte[]
12421244
public final CommandObject<Long> hstrlen(byte[] key, byte[] field) {
12431245
return new CommandObject<>(commandArguments(Command.HSTRLEN).key(key).add(field), BuilderFactory.LONG);
12441246
}
1247+
1248+
public final CommandObject<Long> hsetex(String key, HSetExParams params, String field, String value) {
1249+
return new CommandObject<>(commandArguments(Command.HSETEX).key(key)
1250+
.addParams(params).add(Keyword.FIELDS).add(1).add(field).add(value), BuilderFactory.LONG);
1251+
}
1252+
1253+
public final CommandObject<Long> hsetex(String key, HSetExParams params, Map<String, String> hash) {
1254+
return new CommandObject<>(addFlatMapArgs(commandArguments(Command.HSETEX).key(key)
1255+
.addParams(params).add(Keyword.FIELDS).add(hash.size()), hash), BuilderFactory.LONG);
1256+
}
1257+
1258+
public final CommandObject<List<String>> hgetex(String key, HGetExParams params, String... fields) {
1259+
return new CommandObject<>(commandArguments(Command.HGETEX).key(key)
1260+
.addParams(params).add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.STRING_LIST);
1261+
}
1262+
1263+
public final CommandObject<Long> hsetex(byte[] key, HSetExParams params, byte[] field, byte[] value) {
1264+
return new CommandObject<>(commandArguments(Command.HSETEX).key(key)
1265+
.addParams(params).add(Keyword.FIELDS).add(1).add(field).add(value), BuilderFactory.LONG);
1266+
}
1267+
1268+
public final CommandObject<Long> hsetex(byte[] key, HSetExParams params, Map<byte[], byte[]> hash) {
1269+
return new CommandObject<>(addFlatMapArgs(commandArguments(Command.HSETEX).key(key)
1270+
.addParams(params).add(Keyword.FIELDS).add(hash.size()), hash), BuilderFactory.LONG);
1271+
}
1272+
1273+
public final CommandObject<List<byte[]>> hgetex(byte[] key, HGetExParams params, byte[]... fields) {
1274+
return new CommandObject<>(commandArguments(Command.HGETEX).key(key)
1275+
.addParams(params).add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.BINARY_LIST);
1276+
}
1277+
1278+
public final CommandObject<List<byte[]>> hgetdel(byte[] key, byte[]... fields) {
1279+
return new CommandObject<>(commandArguments(Command.HGETDEL).key(key).add(Keyword.FIELDS)
1280+
.add(fields.length).addObjects((Object[]) fields), BuilderFactory.BINARY_LIST);
1281+
}
1282+
1283+
public final CommandObject<List<Long>> hexpire(String key, long seconds, String... fields) {
1284+
return new CommandObject<>(commandArguments(Command.HEXPIRE).key(key).add(seconds)
1285+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1286+
}
1287+
1288+
public final CommandObject<List<Long>> hexpire(String key, long seconds, ExpiryOption condition, String... fields) {
1289+
return new CommandObject<>(commandArguments(Command.HEXPIRE).key(key).add(seconds).add(condition)
1290+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1291+
}
1292+
1293+
public final CommandObject<List<Long>> hpexpire(String key, long milliseconds, String... fields) {
1294+
return new CommandObject<>(commandArguments(Command.HPEXPIRE).key(key).add(milliseconds)
1295+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1296+
}
1297+
1298+
public final CommandObject<List<Long>> hpexpire(String key, long milliseconds, ExpiryOption condition, String... fields) {
1299+
return new CommandObject<>(commandArguments(Command.HPEXPIRE).key(key).add(milliseconds).add(condition)
1300+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1301+
}
1302+
1303+
public final CommandObject<List<Long>> hexpireAt(String key, long unixTimeSeconds, String... fields) {
1304+
return new CommandObject<>(commandArguments(Command.HEXPIREAT).key(key).add(unixTimeSeconds)
1305+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1306+
}
1307+
1308+
public final CommandObject<List<Long>> hexpireAt(String key, long unixTimeSeconds, ExpiryOption condition, String... fields) {
1309+
return new CommandObject<>(commandArguments(Command.HEXPIREAT).key(key).add(unixTimeSeconds).add(condition)
1310+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1311+
}
1312+
1313+
public final CommandObject<List<Long>> hpexpireAt(String key, long unixTimeMillis, String... fields) {
1314+
return new CommandObject<>(commandArguments(Command.HPEXPIREAT).key(key).add(unixTimeMillis)
1315+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1316+
}
1317+
1318+
public final CommandObject<List<Long>> hpexpireAt(String key, long unixTimeMillis, ExpiryOption condition, String... fields) {
1319+
return new CommandObject<>(commandArguments(Command.HPEXPIREAT).key(key).add(unixTimeMillis).add(condition)
1320+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1321+
}
1322+
1323+
public final CommandObject<List<Long>> hexpire(byte[] key, long seconds, byte[]... fields) {
1324+
return new CommandObject<>(commandArguments(Command.HEXPIRE).key(key).add(seconds)
1325+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1326+
}
1327+
1328+
public final CommandObject<List<Long>> hexpire(byte[] key, long seconds, ExpiryOption condition, byte[]... fields) {
1329+
return new CommandObject<>(commandArguments(Command.HEXPIRE).key(key).add(seconds).add(condition)
1330+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1331+
}
1332+
1333+
public final CommandObject<List<Long>> hpexpire(byte[] key, long milliseconds, byte[]... fields) {
1334+
return new CommandObject<>(commandArguments(Command.HPEXPIRE).key(key).add(milliseconds)
1335+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1336+
}
1337+
1338+
public final CommandObject<List<Long>> hpexpire(byte[] key, long milliseconds, ExpiryOption condition, byte[]... fields) {
1339+
return new CommandObject<>(commandArguments(Command.HPEXPIRE).key(key).add(milliseconds).add(condition)
1340+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1341+
}
1342+
1343+
public final CommandObject<List<Long>> hexpireAt(byte[] key, long unixTimeSeconds, byte[]... fields) {
1344+
return new CommandObject<>(commandArguments(Command.HEXPIREAT).key(key).add(unixTimeSeconds)
1345+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1346+
}
1347+
1348+
public final CommandObject<List<Long>> hexpireAt(byte[] key, long unixTimeSeconds, ExpiryOption condition, byte[]... fields) {
1349+
return new CommandObject<>(commandArguments(Command.HEXPIREAT).key(key).add(unixTimeSeconds).add(condition)
1350+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1351+
}
1352+
1353+
public final CommandObject<List<Long>> hpexpireAt(byte[] key, long unixTimeMillis, byte[]... fields) {
1354+
return new CommandObject<>(commandArguments(Command.HPEXPIREAT).key(key).add(unixTimeMillis)
1355+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1356+
}
1357+
1358+
public final CommandObject<List<Long>> hpexpireAt(byte[] key, long unixTimeMillis, ExpiryOption condition, byte[]... fields) {
1359+
return new CommandObject<>(commandArguments(Command.HPEXPIREAT).key(key).add(unixTimeMillis).add(condition)
1360+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1361+
}
1362+
1363+
public final CommandObject<List<Long>> hexpireTime(String key, String... fields) {
1364+
return new CommandObject<>(commandArguments(Command.HEXPIRETIME).key(key)
1365+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1366+
}
1367+
1368+
public final CommandObject<List<Long>> hpexpireTime(String key, String... fields) {
1369+
return new CommandObject<>(commandArguments(Command.HPEXPIRETIME).key(key)
1370+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1371+
}
1372+
1373+
public final CommandObject<List<Long>> httl(String key, String... fields) {
1374+
return new CommandObject<>(commandArguments(Command.HTTL).key(key)
1375+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1376+
}
1377+
1378+
public final CommandObject<List<Long>> hpttl(String key, String... fields) {
1379+
return new CommandObject<>(commandArguments(Command.HPTTL).key(key)
1380+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1381+
}
1382+
1383+
public final CommandObject<List<Long>> hexpireTime(byte[] key, byte[]... fields) {
1384+
return new CommandObject<>(commandArguments(Command.HEXPIRETIME).key(key)
1385+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1386+
}
1387+
1388+
public final CommandObject<List<Long>> hpexpireTime(byte[] key, byte[]... fields) {
1389+
return new CommandObject<>(commandArguments(Command.HPEXPIRETIME).key(key)
1390+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1391+
}
1392+
1393+
public final CommandObject<List<Long>> httl(byte[] key, byte[]... fields) {
1394+
return new CommandObject<>(commandArguments(Command.HTTL).key(key)
1395+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1396+
}
1397+
1398+
public final CommandObject<List<Long>> hpttl(byte[] key, byte[]... fields) {
1399+
return new CommandObject<>(commandArguments(Command.HPTTL).key(key)
1400+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1401+
}
1402+
1403+
public final CommandObject<List<Long>> hpersist(String key, String... fields) {
1404+
return new CommandObject<>(commandArguments(Command.HPERSIST).key(key)
1405+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1406+
}
1407+
1408+
public final CommandObject<List<Long>> hpersist(byte[] key, byte[]... fields) {
1409+
return new CommandObject<>(commandArguments(Command.HPERSIST).key(key)
1410+
.add(Keyword.FIELDS).add(fields.length).addObjects((Object[]) fields), BuilderFactory.LONG_LIST);
1411+
}
12451412
// Hash commands
12461413

12471414
// Set commands

src/main/java/io/valkey/Jedis.java

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import io.valkey.params.GeoRadiusStoreParam;
5959
import io.valkey.params.GeoSearchParam;
6060
import io.valkey.params.GetExParams;
61+
import io.valkey.params.HGetExParams;
62+
import io.valkey.params.HSetExParams;
6163
import io.valkey.params.LCSParams;
6264
import io.valkey.params.LPosParams;
6365
import io.valkey.params.LolwutParams;
@@ -4752,6 +4754,102 @@ public long hstrlen(final byte[] key, final byte[] field) {
47524754
return connection.executeCommand(commandObjects.hstrlen(key, field));
47534755
}
47544756

4757+
@Override
4758+
public List<byte[]> hgetex(byte[] key, HGetExParams params, byte[]... fields){
4759+
checkIsInMultiOrPipeline();
4760+
return connection.executeCommand(commandObjects.hgetex(key, params, fields));
4761+
}
4762+
4763+
@Override
4764+
public long hsetex(byte[] key, HSetExParams params, byte[] field, byte[] value) {
4765+
checkIsInMultiOrPipeline();
4766+
return connection.executeCommand(commandObjects.hsetex(key, params, field, value));
4767+
}
4768+
4769+
@Override
4770+
public long hsetex(byte[] key, HSetExParams params, Map<byte[], byte[]> hash){
4771+
checkIsInMultiOrPipeline();
4772+
return connection.executeCommand(commandObjects.hsetex(key, params, hash));
4773+
}
4774+
4775+
@Override
4776+
public List<Long> hexpire(byte[] key, long seconds, byte[]... fields) {
4777+
checkIsInMultiOrPipeline();
4778+
return connection.executeCommand(commandObjects.hexpire(key, seconds, fields));
4779+
}
4780+
4781+
@Override
4782+
public List<Long> hexpire(byte[] key, long seconds, ExpiryOption condition, byte[]... fields) {
4783+
checkIsInMultiOrPipeline();
4784+
return connection.executeCommand(commandObjects.hexpire(key, seconds, condition, fields));
4785+
}
4786+
4787+
@Override
4788+
public List<Long> hpexpire(byte[] key, long milliseconds, byte[]... fields) {
4789+
checkIsInMultiOrPipeline();
4790+
return connection.executeCommand(commandObjects.hpexpire(key, milliseconds, fields));
4791+
}
4792+
4793+
@Override
4794+
public List<Long> hpexpire(byte[] key, long milliseconds, ExpiryOption condition, byte[]... fields) {
4795+
checkIsInMultiOrPipeline();
4796+
return connection.executeCommand(commandObjects.hpexpire(key, milliseconds, condition, fields));
4797+
}
4798+
4799+
@Override
4800+
public List<Long> hexpireAt(byte[] key, long unixTimeSeconds, byte[]... fields) {
4801+
checkIsInMultiOrPipeline();
4802+
return connection.executeCommand(commandObjects.hexpireAt(key, unixTimeSeconds, fields));
4803+
}
4804+
4805+
@Override
4806+
public List<Long> hexpireAt(byte[] key, long unixTimeSeconds, ExpiryOption condition, byte[]... fields) {
4807+
checkIsInMultiOrPipeline();
4808+
return connection.executeCommand(commandObjects.hexpireAt(key, unixTimeSeconds, condition, fields));
4809+
}
4810+
4811+
@Override
4812+
public List<Long> hpexpireAt(byte[] key, long unixTimeMillis, byte[]... fields) {
4813+
checkIsInMultiOrPipeline();
4814+
return connection.executeCommand(commandObjects.hpexpireAt(key, unixTimeMillis, fields));
4815+
}
4816+
4817+
@Override
4818+
public List<Long> hpexpireAt(byte[] key, long unixTimeMillis, ExpiryOption condition, byte[]... fields) {
4819+
checkIsInMultiOrPipeline();
4820+
return connection.executeCommand(commandObjects.hpexpireAt(key, unixTimeMillis, condition, fields));
4821+
}
4822+
4823+
@Override
4824+
public List<Long> hexpireTime(byte[] key, byte[]... fields) {
4825+
checkIsInMultiOrPipeline();
4826+
return connection.executeCommand(commandObjects.hexpireTime(key, fields));
4827+
}
4828+
4829+
@Override
4830+
public List<Long> hpexpireTime(byte[] key, byte[]... fields) {
4831+
checkIsInMultiOrPipeline();
4832+
return connection.executeCommand(commandObjects.hpexpireTime(key, fields));
4833+
}
4834+
4835+
@Override
4836+
public List<Long> httl(byte[] key, byte[]... fields) {
4837+
checkIsInMultiOrPipeline();
4838+
return connection.executeCommand(commandObjects.httl(key, fields));
4839+
}
4840+
4841+
@Override
4842+
public List<Long> hpttl(byte[] key, byte[]... fields) {
4843+
checkIsInMultiOrPipeline();
4844+
return connection.executeCommand(commandObjects.hpttl(key, fields));
4845+
}
4846+
4847+
@Override
4848+
public List<Long> hpersist(byte[] key, byte[]... fields) {
4849+
checkIsInMultiOrPipeline();
4850+
return connection.executeCommand(commandObjects.hpersist(key, fields));
4851+
}
4852+
47554853
@Override
47564854
public List<Object> xread(XReadParams xReadParams, Entry<byte[], byte[]>... streams) {
47574855
checkIsInMultiOrPipeline();
@@ -9347,6 +9445,102 @@ public long hstrlen(final String key, final String field) {
93479445
return connection.executeCommand(commandObjects.hstrlen(key, field));
93489446
}
93499447

9448+
@Override
9449+
public long hsetex(String key, HSetExParams params, String field, String value) {
9450+
checkIsInMultiOrPipeline();
9451+
return connection.executeCommand(commandObjects.hsetex(key, params, field, value));
9452+
}
9453+
9454+
@Override
9455+
public long hsetex(String key, HSetExParams params, Map<String, String> hash) {
9456+
checkIsInMultiOrPipeline();
9457+
return connection.executeCommand(commandObjects.hsetex(key, params, hash));
9458+
}
9459+
9460+
@Override
9461+
public List<String> hgetex(String key, HGetExParams params, String... fields) {
9462+
checkIsInMultiOrPipeline();
9463+
return connection.executeCommand(commandObjects.hgetex(key, params, fields));
9464+
}
9465+
9466+
@Override
9467+
public List<Long> hexpire(String key, long seconds, String... fields) {
9468+
checkIsInMultiOrPipeline();
9469+
return connection.executeCommand(commandObjects.hexpire(key, seconds, fields));
9470+
}
9471+
9472+
@Override
9473+
public List<Long> hexpire(String key, long seconds, ExpiryOption condition, String... fields) {
9474+
checkIsInMultiOrPipeline();
9475+
return connection.executeCommand(commandObjects.hexpire(key, seconds, condition, fields));
9476+
}
9477+
9478+
@Override
9479+
public List<Long> hpexpire(String key, long milliseconds, String... fields) {
9480+
checkIsInMultiOrPipeline();
9481+
return connection.executeCommand(commandObjects.hpexpire(key, milliseconds, fields));
9482+
}
9483+
9484+
@Override
9485+
public List<Long> hpexpire(String key, long milliseconds, ExpiryOption condition, String... fields) {
9486+
checkIsInMultiOrPipeline();
9487+
return connection.executeCommand(commandObjects.hpexpire(key, milliseconds, condition, fields));
9488+
}
9489+
9490+
@Override
9491+
public List<Long> hexpireAt(String key, long unixTimeSeconds, String... fields) {
9492+
checkIsInMultiOrPipeline();
9493+
return connection.executeCommand(commandObjects.hexpireAt(key, unixTimeSeconds, fields));
9494+
}
9495+
9496+
@Override
9497+
public List<Long> hexpireAt(String key, long unixTimeSeconds, ExpiryOption condition, String... fields) {
9498+
checkIsInMultiOrPipeline();
9499+
return connection.executeCommand(commandObjects.hexpireAt(key, unixTimeSeconds, condition, fields));
9500+
}
9501+
9502+
@Override
9503+
public List<Long> hpexpireAt(String key, long unixTimeMillis, String... fields) {
9504+
checkIsInMultiOrPipeline();
9505+
return connection.executeCommand(commandObjects.hpexpireAt(key, unixTimeMillis, fields));
9506+
}
9507+
9508+
@Override
9509+
public List<Long> hpexpireAt(String key, long unixTimeMillis, ExpiryOption condition, String... fields) {
9510+
checkIsInMultiOrPipeline();
9511+
return connection.executeCommand(commandObjects.hpexpireAt(key, unixTimeMillis, condition, fields));
9512+
}
9513+
9514+
@Override
9515+
public List<Long> hexpireTime(String key, String... fields) {
9516+
checkIsInMultiOrPipeline();
9517+
return connection.executeCommand(commandObjects.hexpireTime(key, fields));
9518+
}
9519+
9520+
@Override
9521+
public List<Long> hpexpireTime(String key, String... fields) {
9522+
checkIsInMultiOrPipeline();
9523+
return connection.executeCommand(commandObjects.hpexpireTime(key, fields));
9524+
}
9525+
9526+
@Override
9527+
public List<Long> httl(String key, String... fields) {
9528+
checkIsInMultiOrPipeline();
9529+
return connection.executeCommand(commandObjects.httl(key, fields));
9530+
}
9531+
9532+
@Override
9533+
public List<Long> hpttl(String key, String... fields) {
9534+
checkIsInMultiOrPipeline();
9535+
return connection.executeCommand(commandObjects.hpttl(key, fields));
9536+
}
9537+
9538+
@Override
9539+
public List<Long> hpersist(String key, String... fields) {
9540+
checkIsInMultiOrPipeline();
9541+
return connection.executeCommand(commandObjects.hpersist(key, fields));
9542+
}
9543+
93509544
@Override
93519545
public String memoryDoctor() {
93529546
checkIsInMultiOrPipeline();

0 commit comments

Comments
 (0)