• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leonchen83 / redis-replicator / #2570

11 Oct 2025 04:55AM UTC coverage: 72.201% (-0.005%) from 72.206%
#2570

push

chenby
redis-8.2

7241 of 10029 relevant lines covered (72.2%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.36
/src/main/java/com/moilioncircle/redis/replicator/cmd/parser/XAddParser.java
1
/*
2
 * Copyright 2016-2018 Leon Chen
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 java.util.Objects;
25

26
import com.moilioncircle.redis.replicator.cmd.CommandParser;
27
import com.moilioncircle.redis.replicator.cmd.impl.DeletionPolicy;
28
import com.moilioncircle.redis.replicator.cmd.impl.Limit;
29
import com.moilioncircle.redis.replicator.cmd.impl.MaxLen;
30
import com.moilioncircle.redis.replicator.cmd.impl.MinId;
31
import com.moilioncircle.redis.replicator.cmd.impl.XAddCommand;
32
import com.moilioncircle.redis.replicator.util.ByteArrayMap;
33

34
/**
35
 * @author Leon Chen
36
 * @since 2.6.0
37
 */
38
public class XAddParser implements CommandParser<XAddCommand> {
1✔
39
    @Override
40
    public XAddCommand parse(Object[] command) {
41
        int idx = 1;
1✔
42
        byte[] key = toBytes(command[idx]);
1✔
43
        idx++;
1✔
44
        DeletionPolicy policy = null;
1✔
45
        MaxLen maxLen = null;
1✔
46
        MinId minId = null;
1✔
47
        Limit limit = null;
1✔
48
        boolean nomkstream = false;
1✔
49
        byte[] id = null;
1✔
50
        ByteArrayMap fields = new ByteArrayMap();
1✔
51
        for (; idx < command.length; idx++) {
1✔
52
            String token = toRune(command[idx]);
1✔
53
            if (isEquals(token, "KEEPREF")) {
1✔
54
                policy = DeletionPolicy.KEEPREF;
1✔
55
            } else if (isEquals(token, "DELREF")) {
1✔
56
                policy = DeletionPolicy.DELREF;
×
57
            } else if (isEquals(token, "ACKED")) {
1✔
58
                policy = DeletionPolicy.ACKED;
×
59
            } else if (isEquals(token, "MAXLEN")) {
1✔
60
                idx++;
1✔
61
                boolean approximation = false;
1✔
62
                if (Objects.equals(toRune(command[idx]), "~")) {
1✔
63
                    approximation = true;
1✔
64
                    idx++;
1✔
65
                } else if (Objects.equals(toRune(command[idx]), "=")) {
1✔
66
                    idx++;
1✔
67
                }
68
                long count = toLong(command[idx]);
1✔
69
                maxLen = new MaxLen(approximation, count);
1✔
70
            } else if (isEquals(token, "MINID")) {
1✔
71
                idx++;
1✔
72
                boolean approximation = false;
1✔
73
                if (Objects.equals(toRune(command[idx]), "~")) {
1✔
74
                    approximation = true;
1✔
75
                    idx++;
1✔
76
                } else if (Objects.equals(toRune(command[idx]), "=")) {
1✔
77
                    idx++;
1✔
78
                }
79
                byte[] mid = toBytes(command[idx]);
1✔
80
                minId = new MinId(approximation, mid);
1✔
81
            } else if (isEquals(token, "LIMIT")) {
1✔
82
                idx++;
1✔
83
                long count = toLong(command[idx]);
1✔
84
                limit = new Limit(0, count);
1✔
85
            } else if (isEquals(token, "NOMKSTREAM")) {
1✔
86
                nomkstream = true;
1✔
87
            } else {
88
                id = toBytes(command[idx]);
1✔
89
                idx++;
1✔
90
                while (idx < command.length) {
1✔
91
                    byte[] field = toBytes(command[idx]);
1✔
92
                    idx++;
1✔
93
                    byte[] value = idx == command.length ? null : toBytes(command[idx]);
1✔
94
                    idx++;
1✔
95
                    fields.put(field, value);
1✔
96
                }
1✔
97
            }
98
        }
99
    
100
        return new XAddCommand(key, policy, maxLen, minId, limit, nomkstream, id, fields);
1✔
101
    }
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc