Skip to content

Commit

Permalink
INTERNAL: Integration get and mget api
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesecrust committed Dec 26, 2024
1 parent c9473d9 commit 2fed732
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1102,12 +1102,7 @@ public void complete() {
List<String> keyList = entry.getValue();

Operation op;
if (node == null) {
op = opFact.mget(keyList, cb);
} else {
op = node.enabledMGetOp() ? opFact.mget(keyList, cb)
: opFact.get(keyList, cb);
}
op = opFact.get(keyList, cb);
conn.addOperation(node, op);
ops.add(op);
}
Expand Down Expand Up @@ -1239,12 +1234,7 @@ public void complete() {
List<String> keyList = entry.getValue();

Operation op;
if (node == null) {
op = opFact.mgets(keyList, cb);
} else {
op = node.enabledMGetsOp() ? opFact.mgets(keyList, cb)
: opFact.gets(keyList, cb);
}
op = opFact.gets(keyList, cb);
conn.addOperation(node, op);
ops.add(op);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/spy/memcached/ops/BaseOperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ public Operation cloneMultiOperation(KeyedOperation op, MemcachedNode node,
assert !op.hasErrored() : "Attempted to clone an errored op";

if (op instanceof GetOperation) {
// If MemcachedNode supports this clone feature, it should support mget operation too.
return mget(redirectKeys, (GetOperation.Callback) mcb);
// If MemcachedNode supports this clone feature, it should support get keys operation too.
return get(redirectKeys, (GetOperation.Callback) mcb);
} else if (op instanceof GetsOperation) {
// If MemcachedNode supports this clone feature, it should support mgets operation too.
return mgets(redirectKeys, (GetsOperation.Callback) mcb);
// If MemcachedNode supports this clone feature, it should support gets keys operation too.
return gets(redirectKeys, (GetsOperation.Callback) mcb);
} else if (op instanceof CollectionBulkInsertOperation) {
final CollectionBulkInsert<?> insert = ((CollectionBulkInsertOperation) op).getInsert();
return collectionBulkInsert(insert.clone(node, redirectKeys), mcb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb) {
return new GetsOperationImpl(keys, cb);
}

@Deprecated
public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
return new MGetOperationImpl(keys, cb);
}

@Deprecated
public GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb) {
return new MGetsOperationImpl(keys, cb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,17 @@ public final void initialize() {

String keysString = generateKeysString();

if (cmd.equals("get") || cmd.equals("gets")) {
if (getHandlingNode() != null && !getHandlingNode().enabledMGetOp()) {
// syntax: get <keys...>\r\n
commandBuilder.append(cmd);
commandBuilder.append(' ');
commandBuilder.append(keysString);
commandBuilder.append(RN_STRING);
} else {
assert (cmd.equals("mget") || cmd.equals("mgets"))
: "Unknown Command " + cmd;
// syntax: mget <lenKeys> <numkeys>\r\n<keys>\r\n
int lenKeys = keysString.getBytes().length;
int numKeys = keys.size();
commandBuilder.append("m");
commandBuilder.append(cmd);
commandBuilder.append(' ');
commandBuilder.append(lenKeys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
/**
* Operation for retrieving data.
*/
@Deprecated
public final class MGetOperationImpl extends BaseGetOpImpl implements GetOperation {

private static final String CMD = "mget";
private static final String CMD = "get";

public MGetOperationImpl(Collection<String> k, Callback c) {
super(CMD, c, new HashSet<>(k));
setAPIType(APIType.MGET);
setAPIType(APIType.GET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
/**
* Operation for retrieving data.
*/
@Deprecated
public final class MGetsOperationImpl extends BaseGetOpImpl implements GetsOperation {

private static final String CMD = "mgets";
private static final String CMD = "gets";

public MGetsOperationImpl(Collection<String> k, Callback c) {
super(CMD, c, new HashSet<>(k));
setAPIType(APIType.MGETS);
setAPIType(APIType.GETS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ public GetsOperation gets(Collection<String> keys, GetsOperation.Callback callba
"gets is not supported in binary protocol yet.");
}

@Deprecated
public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
throw new RuntimeException(
"mget is not supported in binary protocol yet.");
}

@Deprecated
public GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb) {
throw new RuntimeException(
"mgets is not supported in binary protocol yet.");
Expand Down

0 comments on commit 2fed732

Please sign in to comment.