@@ -58,6 +58,7 @@ public interface ReactiveHashCommands {
5858 *
5959 * @author Christoph Strobl
6060 * @author Tihomir Mateev
61+ * @author Viktoriya Kutsarova
6162 */
6263class HashFieldsCommand extends KeyCommand {
6364
@@ -1255,4 +1256,255 @@ default Flux<Long> hpTtl(ByteBuffer key, List<ByteBuffer> fields) {
12551256 */
12561257Flux <NumericResponse <HashFieldsCommand , Long >> hpTtl (Publisher <HashFieldsCommand > commands );
12571258
1259+
1260+ /**
1261+ * {@literal HGETDEL} {@link Command}.
1262+ *
1263+ * @author Viktoriya Kutsarova
1264+ * @see <a href="https://redis.io/commands/hgetdel">Redis Documentation: HGETDEL</a>
1265+ */
1266+ class HGetDelCommand extends HashFieldsCommand {
1267+
1268+ private HGetDelCommand (@ Nullable ByteBuffer key , List <ByteBuffer > fields ) {
1269+ super (key , fields );
1270+ }
1271+
1272+ /**
1273+ * Creates a new {@link HGetDelCommand} given a {@link ByteBuffer field name}.
1274+ *
1275+ * @param field must not be {@literal null}.
1276+ * @return a new {@link HGetDelCommand} for a {@link ByteBuffer field name}.
1277+ */
1278+ public static HGetDelCommand field (ByteBuffer field ) {
1279+
1280+ Assert .notNull (field , "Field must not be null" );
1281+
1282+ return new HGetDelCommand (null , Collections .singletonList (field ));
1283+ }
1284+
1285+ /**
1286+ * Creates a new {@link HGetDelCommand} given a {@link Collection} of field names.
1287+ *
1288+ * @param fields must not be {@literal null}.
1289+ * @return a new {@link HGetDelCommand} for a {@link Collection} of field names.
1290+ */
1291+ public static HGetDelCommand fields (Collection <ByteBuffer > fields ) {
1292+
1293+ Assert .notNull (fields , "Fields must not be null" );
1294+
1295+ return new HGetDelCommand (null , new ArrayList <>(fields ));
1296+ }
1297+
1298+ /**
1299+ * Applies the hash {@literal key}. Constructs a new command instance with all previously configured properties.
1300+ *
1301+ * @param key must not be {@literal null}.
1302+ * @return a new {@link HGetDelCommand} with {@literal key} applied.
1303+ */
1304+ public HGetDelCommand from (ByteBuffer key ) {
1305+
1306+ Assert .notNull (key , "Key must not be null" );
1307+
1308+ return new HGetDelCommand (key , getFields ());
1309+ }
1310+ }
1311+
1312+
1313+ /**
1314+ * Get and delete the value of one or more {@literal fields} from hash at {@literal key}. Values are returned in the
1315+ * order of the requested keys. Absent field values are represented using {@literal null} in the resulting {@link List}.
1316+ * When the last field is deleted, the key will also be deleted.
1317+ *
1318+ * @param key must not be {@literal null}.
1319+ * @param fields must not be {@literal null}.
1320+ * @return never {@literal null}.
1321+ * @see <a href="https://redis.io/commands/hgetdel">Redis Documentation: HGETDEL</a>
1322+ */
1323+ default Mono <List <ByteBuffer >> hGetDel (ByteBuffer key , Collection <ByteBuffer > fields ) {
1324+
1325+ Assert .notNull (key , "Key must not be null" );
1326+ Assert .notNull (fields , "Fields must not be null" );
1327+
1328+ return hGetDel (Mono .just (HGetDelCommand .fields (fields ).from (key ))).next ().map (MultiValueResponse ::getOutput );
1329+ }
1330+
1331+ /**
1332+ * Get and delete the value of one or more {@literal fields} from hash at {@literal key}. Values are returned in the
1333+ * order of the requested keys. Absent field values are represented using {@literal null} in the resulting {@link List}.
1334+ * When the last field is deleted, the key will also be deleted.
1335+ *
1336+ * @param commands must not be {@literal null}.
1337+ * @return never {@literal null}.
1338+ * @see <a href="https://redis.io/commands/hgetdel">Redis Documentation: HGETDEL</a>
1339+ */
1340+ Flux <MultiValueResponse <HGetDelCommand , ByteBuffer >> hGetDel (Publisher <HGetDelCommand > commands );
1341+
1342+ class HGetExCommand extends HashFieldsCommand {
1343+
1344+ private final Expiration expiration ;
1345+
1346+ private HGetExCommand (@ Nullable ByteBuffer key , List <ByteBuffer > fields , Expiration expiration ) {
1347+
1348+ super (key , fields );
1349+
1350+ this .expiration = expiration ;
1351+ }
1352+
1353+ /**
1354+ * Creates a new {@link HGetExCommand}.
1355+ *
1356+ * @param fields the {@code fields} names to apply expiration to
1357+ * @param expiration the {@link Expiration} to apply to the given {@literal fields}.
1358+ * @return new instance of {@link HGetExCommand}.
1359+ */
1360+ public static HGetExCommand expire (List <ByteBuffer > fields , Expiration expiration ) {
1361+ return new HGetExCommand (null , fields , expiration );
1362+ }
1363+
1364+ /**
1365+ * @param key the {@literal key} from which to expire the {@literal fields} from.
1366+ * @return new instance of {@link HashExpireCommand}.
1367+ */
1368+ public HGetExCommand from (ByteBuffer key ) {
1369+ return new HGetExCommand (key , getFields (), expiration );
1370+ }
1371+
1372+ /**
1373+ * Creates a new {@link HGetExCommand}.
1374+ *
1375+ * @param fields the {@code fields} names to apply expiration to
1376+ * @return new instance of {@link HGetExCommand}.
1377+ */
1378+ public HGetExCommand fields (Collection <ByteBuffer > fields ) {
1379+ return new HGetExCommand (getKey (), new ArrayList <>(fields ), expiration );
1380+ }
1381+
1382+ public Expiration getExpiration () {
1383+ return expiration ;
1384+ }
1385+ }
1386+
1387+ /**
1388+ * Get the value of one or more {@literal fields} from hash at {@literal key} and optionally set expiration time or
1389+ * time-to-live (TTL) for given {@literal fields}.
1390+ *
1391+ * @param key must not be {@literal null}.
1392+ * @param fields must not be {@literal null}.
1393+ * @return never {@literal null}.
1394+ * @see <a href="https://redis.io/commands/hgetex">Redis Documentation: HGETEX</a>
1395+ */
1396+ default Mono <List <ByteBuffer >> hGetEx (ByteBuffer key , Expiration expiration , List <ByteBuffer > fields ) {
1397+
1398+ Assert .notNull (key , "Key must not be null" );
1399+ Assert .notNull (fields , "Fields must not be null" );
1400+
1401+ return hGetEx (Mono .just (HGetExCommand .expire (fields , expiration ).from (key ))).next ().map (MultiValueResponse ::getOutput );
1402+ }
1403+
1404+ /**
1405+ * Get the value of one or more {@literal fields} from hash at {@literal key} and optionally set expiration time or
1406+ * time-to-live (TTL) for given {@literal fields}.
1407+ *
1408+ * @param commands must not be {@literal null}.
1409+ * @return never {@literal null}.
1410+ * @see <a href="https://redis.io/commands/hgetex">Redis Documentation: HGETEX</a>
1411+ */
1412+ Flux <MultiValueResponse <HGetExCommand , ByteBuffer >> hGetEx (Publisher <HGetExCommand > commands );
1413+
1414+ /**
1415+ * {@literal HSETEX} {@link Command}.
1416+ *
1417+ * @author Viktoriya Kutsarova
1418+ * @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
1419+ */
1420+ class HSetExCommand extends KeyCommand {
1421+
1422+ private final Map <ByteBuffer , ByteBuffer > fieldValueMap ;
1423+ private final RedisHashCommands .HashFieldSetOption condition ;
1424+ private final Expiration expiration ;
1425+
1426+ private HSetExCommand (@ Nullable ByteBuffer key , Map <ByteBuffer , ByteBuffer > fieldValueMap ,
1427+ RedisHashCommands .HashFieldSetOption condition , Expiration expiration ) {
1428+ super (key );
1429+ this .fieldValueMap = fieldValueMap ;
1430+ this .condition = condition ;
1431+ this .expiration = expiration ;
1432+ }
1433+
1434+ /**
1435+ * Creates a new {@link HSetExCommand} for setting field-value pairs with condition and expiration.
1436+ *
1437+ * @param fieldValueMap the field-value pairs to set; must not be {@literal null}.
1438+ * @param condition the condition for setting fields; must not be {@literal null}.
1439+ * @param expiration the expiration to apply; must not be {@literal null}.
1440+ * @return new instance of {@link HSetExCommand}.
1441+ */
1442+ public static HSetExCommand setWithConditionAndExpiration (Map <ByteBuffer , ByteBuffer > fieldValueMap ,
1443+ RedisHashCommands .HashFieldSetOption condition , Expiration expiration ) {
1444+ return new HSetExCommand (null , fieldValueMap , condition , expiration );
1445+ }
1446+
1447+ /**
1448+ * Applies the hash {@literal key}. Constructs a new command instance with all previously configured properties.
1449+ *
1450+ * @param key must not be {@literal null}.
1451+ * @return a new {@link HSetExCommand} with {@literal key} applied.
1452+ */
1453+ public HSetExCommand from (ByteBuffer key ) {
1454+ Assert .notNull (key , "Key must not be null" );
1455+ return new HSetExCommand (key , fieldValueMap , condition , expiration );
1456+ }
1457+
1458+ /**
1459+ * @return the field-value map.
1460+ */
1461+ public Map <ByteBuffer , ByteBuffer > getFieldValueMap () {
1462+ return fieldValueMap ;
1463+ }
1464+
1465+ /**
1466+ * @return the condition for setting fields.
1467+ */
1468+ public RedisHashCommands .HashFieldSetOption getCondition () {
1469+ return condition ;
1470+ }
1471+
1472+ /**
1473+ * @return the expiration to apply.
1474+ */
1475+ public Expiration getExpiration () {
1476+ return expiration ;
1477+ }
1478+ }
1479+
1480+ /**
1481+ * Set field-value pairs in hash at {@literal key} with condition and expiration.
1482+ *
1483+ * @param key must not be {@literal null}.
1484+ * @param fieldValueMap the field-value pairs to set; must not be {@literal null}.
1485+ * @param condition the condition for setting fields; must not be {@literal null}.
1486+ * @param expiration the expiration to apply; must not be {@literal null}.
1487+ * @return never {@literal null}.
1488+ * @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
1489+ */
1490+ default Mono <Boolean > hSetEx (ByteBuffer key , Map <ByteBuffer , ByteBuffer > fieldValueMap ,
1491+ RedisHashCommands .HashFieldSetOption condition , Expiration expiration ) {
1492+
1493+ Assert .notNull (key , "Key must not be null" );
1494+ Assert .notNull (fieldValueMap , "Field-value map must not be null" );
1495+ Assert .notNull (condition , "Condition must not be null" );
1496+ Assert .notNull (expiration , "Expiration must not be null" );
1497+
1498+ return hSetEx (Mono .just (HSetExCommand .setWithConditionAndExpiration (fieldValueMap , condition , expiration ).from (key )))
1499+ .next ().map (CommandResponse ::getOutput );
1500+ }
1501+
1502+ /**
1503+ * Set field-value pairs in hash at {@literal key} with condition and expiration.
1504+ *
1505+ * @param commands must not be {@literal null}.
1506+ * @return never {@literal null}.
1507+ * @see <a href="https://redis.io/commands/hsetex">Redis Documentation: HSETEX</a>
1508+ */
1509+ Flux <BooleanResponse <HSetExCommand >> hSetEx (Publisher <HSetExCommand > commands );
12581510}
0 commit comments