Skip to content

Commit c5bb927

Browse files
committed
Introduce Command Flags
Add command flags to be able to correctly determine which commands can be safely broadcasted to replicas instead of sending all broadcasting commands to primaries.
1 parent 84bcf8b commit c5bb927

File tree

3 files changed

+3792
-1668
lines changed

3 files changed

+3792
-1668
lines changed

src/main/java/redis/clients/jedis/CommandObject.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,76 @@
11
package redis.clients.jedis;
22

3+
import java.util.EnumSet;
34
import java.util.Iterator;
45
import redis.clients.jedis.args.Rawable;
56

67
public class CommandObject<T> {
78

9+
/**
10+
* Command flags based on command flags exposed by Redis.
11+
* See <a href="https://redis.io/docs/latest/commands/command/#flags">Command flags</a> for more details.
12+
*
13+
* Flags description:
14+
* - READONLY: Command doesn't modify data
15+
* - WRITE: Command may modify data
16+
* - DENYOOM: Command may increase memory usage (deny if out of memory)
17+
* - ADMIN: Administrative command
18+
* - PUBSUB: Pub/Sub related command
19+
* - NOSCRIPT: Command not allowed in scripts
20+
* - RANDOM: Command has random output for same input
21+
* - SORT_FOR_SCRIPT: Command output needs sorting for scripts
22+
* - LOADING: Command allowed while database is loading
23+
* - STALE: Command allowed on stale replicas
24+
* - SKIP_MONITOR: Command not shown in MONITOR output
25+
* - SKIP_SLOWLOG: Command not shown in slowlog
26+
* - ASKING: Command allowed in cluster ASKING state
27+
* - FAST: Command has O(1) time complexity
28+
* - MOVABLEKEYS: Command key positions may vary
29+
* - MODULE: Module command
30+
* - BLOCKING: Command may block the client
31+
* - NO_AUTH: Command allowed without authentication
32+
* - NO_ASYNC_LOADING: Command not allowed during async loading
33+
* - NO_MULTI: Command not allowed in MULTI/EXEC
34+
* - NO_MANDATORY_KEYS: Command may work without keys
35+
* - ALLOW_BUSY: Command allowed when server is busy
36+
*/
37+
public enum CommandFlag {
38+
READONLY,
39+
WRITE,
40+
DENYOOM,
41+
ADMIN,
42+
PUBSUB,
43+
NOSCRIPT,
44+
SORT_FOR_SCRIPT,
45+
LOADING,
46+
STALE,
47+
SKIP_MONITOR,
48+
ASKING,
49+
FAST,
50+
MOVABLEKEYS,
51+
MODULE,
52+
BLOCKING,
53+
NO_AUTH,
54+
NO_ASYNC_LOADING,
55+
NO_MULTI,
56+
NO_MANDATORY_KEYS,
57+
ALLOW_BUSY
58+
}
59+
860
private final CommandArguments arguments;
961
private final Builder<T> builder;
62+
private EnumSet<CommandFlag> flags;
1063

1164
public CommandObject(CommandArguments args, Builder<T> builder) {
1265
this.arguments = args;
1366
this.builder = builder;
67+
this.flags = EnumSet.noneOf(CommandFlag.class);
68+
}
69+
70+
public CommandObject(CommandArguments args, Builder<T> builder, EnumSet<CommandFlag> commandFlags) {
71+
this.arguments = args;
72+
this.builder = builder;
73+
this.flags = commandFlags;
1474
}
1575

1676
public CommandArguments getArguments() {
@@ -21,6 +81,10 @@ public Builder<T> getBuilder() {
2181
return builder;
2282
}
2383

84+
public EnumSet<CommandFlag> getFlags() {
85+
return flags;
86+
}
87+
2488
@Override
2589
public int hashCode() {
2690
int hashCode = 1;

0 commit comments

Comments
 (0)