Skip to content

Commit

Permalink
Capitalize enum.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Jan 22, 2024
1 parent c667763 commit 6cbc27f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
25 changes: 13 additions & 12 deletions java/client/src/main/java/glide/api/models/configuration/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,40 @@ public class Route {

public enum RouteType {
/** Route request to all nodes. */
AllNodes,
ALL_NODES,
/** Route request to all primary nodes. */
AllPrimaries,
ALL_PRIMARIES,
/** Route request to a random node. */
Random,
RANDOM,
/** Route request to the primary node that contains the slot with the given id. */
PrimarySlotId,
PRIMARY_SLOT_ID,
/** Route request to the replica node that contains the slot with the given id. */
ReplicaSlotId,
REPLICA_SLOT_ID,
/** Route request to the primary node that contains the slot that the given key matches. */
PrimarySlotKey,
PRIMARY_SLOT_KEY,
/** Route request to the replica node that contains the slot that the given key matches. */
ReplicaSlotKey,
REPLICA_SLOT_KEY,
}

/**
* Request routing configuration overrides the {@link ReadFrom} connection configuration.<br>
* If {@link RouteType#ReplicaSlotId} or {@link RouteType#ReplicaSlotKey} is used, the request
* If {@link RouteType#REPLICA_SLOT_ID} or {@link RouteType#REPLICA_SLOT_KEY} is used, the request
* will be routed to a replica, even if the strategy is {@link ReadFrom#PRIMARY}.
*/
private final RouteType routeType;

/**
* Slot number. There are 16384 slots in a redis cluster, and each shard manages a slot range.
* Unless the slot is known, it's better to route using {@link RouteType#PrimarySlotKey} or {@link
* RouteType#ReplicaSlotKey}.<br>
* Could be used with {@link RouteType#PrimarySlotId} or {@link RouteType#ReplicaSlotId} only.
* Unless the slot is known, it's better to route using {@link RouteType#PRIMARY_SLOT_KEY} or
* {@link RouteType#REPLICA_SLOT_KEY}.<br>
* Could be used with {@link RouteType#PRIMARY_SLOT_ID} or {@link RouteType#REPLICA_SLOT_ID} only.
*/
private final int slotId;

/**
* The request will be sent to nodes managing this key.<br>
* Could be used with {@link RouteType#PrimarySlotKey} or {@link RouteType#ReplicaSlotKey} only.
* Could be used with {@link RouteType#PRIMARY_SLOT_KEY} or {@link RouteType#REPLICA_SLOT_KEY}
* only.
*/
private final String slotKey;
}
28 changes: 14 additions & 14 deletions java/client/src/main/java/glide/managers/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ private RedisRequest.Builder prepareRedisRequest(
RedisRequest.Builder builder = prepareRedisRequest(command, args);

switch (route.getRouteType()) {
case Random:
case AllNodes:
case AllPrimaries:
case RANDOM:
case ALL_NODES:
case ALL_PRIMARIES:
builder.setRoute(
RedisRequestOuterClass.Routes.newBuilder()
.setSimpleRoutes(getSimpleRoutes(route.getRouteType()))
.build());
break;
case PrimarySlotKey:
case ReplicaSlotKey:
case PRIMARY_SLOT_KEY:
case REPLICA_SLOT_KEY:
builder.setRoute(
RedisRequestOuterClass.Routes.newBuilder()
.setSlotKeyRoute(
RedisRequestOuterClass.SlotKeyRoute.newBuilder()
.setSlotKey(route.getSlotKey())
.setSlotType(getSlotTypes(route.getRouteType()))));
break;
case PrimarySlotId:
case ReplicaSlotId:
case PRIMARY_SLOT_ID:
case REPLICA_SLOT_ID:
builder.setRoute(
RedisRequestOuterClass.Routes.newBuilder()
.setSlotIdRoute(
Expand All @@ -127,23 +127,23 @@ private RedisRequestOuterClass.RequestType mapRequestTypes(RequestType inType) {

private RedisRequestOuterClass.SimpleRoutes getSimpleRoutes(Route.RouteType routeType) {
switch (routeType) {
case Random:
case RANDOM:
return RedisRequestOuterClass.SimpleRoutes.Random;
case AllNodes:
case ALL_NODES:
return RedisRequestOuterClass.SimpleRoutes.AllNodes;
case AllPrimaries:
case ALL_PRIMARIES:
return RedisRequestOuterClass.SimpleRoutes.AllPrimaries;
}
throw new IllegalStateException("Unreachable code");
}

private RedisRequestOuterClass.SlotTypes getSlotTypes(Route.RouteType routeType) {
switch (routeType) {
case PrimarySlotId:
case PrimarySlotKey:
case PRIMARY_SLOT_ID:
case PRIMARY_SLOT_KEY:
return RedisRequestOuterClass.SlotTypes.Primary;
case ReplicaSlotId:
case ReplicaSlotKey:
case REPLICA_SLOT_ID:
case REPLICA_SLOT_KEY:
return RedisRequestOuterClass.SlotTypes.Replica;
}
throw new IllegalStateException("Unreachable code");
Expand Down

0 comments on commit 6cbc27f

Please sign in to comment.