|
| 1 | +/* |
| 2 | + * Copyright 2026 otheng03 |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.moilioncircle.redis.replicator.cmd.parser; |
| 18 | + |
| 19 | +import static com.moilioncircle.redis.replicator.cmd.CommandParsers.toBytes; |
| 20 | +import static com.moilioncircle.redis.replicator.cmd.CommandParsers.toLong; |
| 21 | +import static com.moilioncircle.redis.replicator.cmd.CommandParsers.toRune; |
| 22 | +import static com.moilioncircle.redis.replicator.util.Strings.isEquals; |
| 23 | + |
| 24 | +import com.moilioncircle.redis.replicator.cmd.CommandParser; |
| 25 | +import com.moilioncircle.redis.replicator.cmd.impl.CompareType; |
| 26 | +import com.moilioncircle.redis.replicator.cmd.impl.ExistType; |
| 27 | +import com.moilioncircle.redis.replicator.cmd.impl.HExpireAtCommand; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author otheng03 |
| 31 | + * @since 3.12.0 |
| 32 | + */ |
| 33 | +public class HExpireAtParser implements CommandParser<HExpireAtCommand> { |
| 34 | + |
| 35 | + @Override |
| 36 | + public HExpireAtCommand parse(Object[] command) { |
| 37 | + int idx = 1; |
| 38 | + byte[] key = toBytes(command[idx]); |
| 39 | + idx++; |
| 40 | + long ex = toLong(command[idx++]); |
| 41 | + |
| 42 | + ExistType existType = ExistType.NONE; |
| 43 | + CompareType compareType = CompareType.NONE; |
| 44 | + while (idx < command.length) { |
| 45 | + String param = toRune(command[idx]); |
| 46 | + if (isEquals(param, "NX")) { |
| 47 | + existType = ExistType.NX; |
| 48 | + } else if (isEquals(param, "XX")) { |
| 49 | + existType = ExistType.XX; |
| 50 | + } else if (isEquals(param, "GT")) { |
| 51 | + compareType = CompareType.GT; |
| 52 | + } else if (isEquals(param, "LT")) { |
| 53 | + compareType = CompareType.LT; |
| 54 | + } else if (isEquals(param, "FIELDS")) { |
| 55 | + break; |
| 56 | + } |
| 57 | + idx++; |
| 58 | + } |
| 59 | + |
| 60 | + idx += 2; // skip FIELDS numFields |
| 61 | + byte[][] fields = new byte[command.length - idx][]; |
| 62 | + for (int i = idx, j = 0; i < command.length; i++, j++) { |
| 63 | + fields[j] = toBytes(command[i]); |
| 64 | + } |
| 65 | + return new HExpireAtCommand(key, fields, ex, existType, compareType); |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments