• 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

90.24
/src/main/java/com/moilioncircle/redis/replicator/cmd/parser/XTrimParser.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.XTrimCommand;
32

33
/**
34
 * @author Leon Chen
35
 * @since 2.6.0
36
 */
37
public class XTrimParser implements CommandParser<XTrimCommand> {
1✔
38
    @Override
39
    public XTrimCommand parse(Object[] command) {
40
        int idx = 1;
1✔
41
        byte[] key = toBytes(command[idx]);
1✔
42
        idx++;
1✔
43
        MaxLen maxLen = null;
1✔
44
        MinId minId = null;
1✔
45
        Limit limit = null;
1✔
46
        DeletionPolicy policy = null;
1✔
47
        for (; idx < command.length; idx++) {
1✔
48
            String token = toRune(command[idx]);
1✔
49
            if (isEquals(token, "MAXLEN")) {
1✔
50
                idx++;
1✔
51
                boolean approximation = false;
1✔
52
                if (Objects.equals(toRune(command[idx]), "~")) {
1✔
53
                    approximation = true;
1✔
54
                    idx++;
1✔
55
                } else if (Objects.equals(toRune(command[idx]), "=")) {
1✔
56
                    idx++;
1✔
57
                }
58
                long count = toLong(command[idx]);
1✔
59
                maxLen = new MaxLen(approximation, count);
1✔
60
            } else if (isEquals(token, "MINID")) {
1✔
61
                idx++;
1✔
62
                boolean approximation = false;
1✔
63
                if (Objects.equals(toRune(command[idx]), "~")) {
1✔
64
                    approximation = true;
×
65
                    idx++;
×
66
                } else if (Objects.equals(toRune(command[idx]), "=")) {
1✔
67
                    idx++;
1✔
68
                }
69
                byte[] mid = toBytes(command[idx]);
1✔
70
                minId = new MinId(approximation, mid);
1✔
71
            } else if (isEquals(token, "LIMIT")) {
1✔
72
                idx++;
1✔
73
                long count = toLong(command[idx]);
1✔
74
                limit = new Limit(0, count);
1✔
75
            } else if (isEquals(token, "KEEPREF")) {
1✔
76
                policy = DeletionPolicy.KEEPREF;
×
77
            } else if (isEquals(token, "DELREF")) {
1✔
78
                policy = DeletionPolicy.DELREF;
×
79
            } else if (isEquals(token, "ACKED")) {
1✔
80
                policy = DeletionPolicy.ACKED;
1✔
81
            }
82
        }
83
        
84
        return new XTrimCommand(key, maxLen, minId, limit, policy);
1✔
85
    }
86
}
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