From 2fed732b1a3460249c7edb67db5ed596039c0b6e Mon Sep 17 00:00:00 2001 From: cheesecrust Date: Thu, 26 Dec 2024 16:59:47 +0900 Subject: [PATCH] INTERNAL: Integration get and mget api --- .../java/net/spy/memcached/MemcachedClient.java | 14 ++------------ .../spy/memcached/ops/BaseOperationFactory.java | 8 ++++---- .../protocol/ascii/AsciiOperationFactory.java | 2 ++ .../memcached/protocol/ascii/BaseGetOpImpl.java | 5 ++--- .../protocol/ascii/MGetOperationImpl.java | 5 +++-- .../protocol/ascii/MGetsOperationImpl.java | 5 +++-- .../protocol/binary/BinaryOperationFactory.java | 2 ++ 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/spy/memcached/MemcachedClient.java b/src/main/java/net/spy/memcached/MemcachedClient.java index e2c09c010..b84b8fedd 100644 --- a/src/main/java/net/spy/memcached/MemcachedClient.java +++ b/src/main/java/net/spy/memcached/MemcachedClient.java @@ -1102,12 +1102,7 @@ public void complete() { List 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); } @@ -1239,12 +1234,7 @@ public void complete() { List 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); } diff --git a/src/main/java/net/spy/memcached/ops/BaseOperationFactory.java b/src/main/java/net/spy/memcached/ops/BaseOperationFactory.java index d0a50640f..b228d1027 100644 --- a/src/main/java/net/spy/memcached/ops/BaseOperationFactory.java +++ b/src/main/java/net/spy/memcached/ops/BaseOperationFactory.java @@ -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); diff --git a/src/main/java/net/spy/memcached/protocol/ascii/AsciiOperationFactory.java b/src/main/java/net/spy/memcached/protocol/ascii/AsciiOperationFactory.java index f755a2fc9..833276758 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/AsciiOperationFactory.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/AsciiOperationFactory.java @@ -110,10 +110,12 @@ public GetsOperation gets(Collection keys, GetsOperation.Callback cb) { return new GetsOperationImpl(keys, cb); } + @Deprecated public GetOperation mget(Collection keys, GetOperation.Callback cb) { return new MGetOperationImpl(keys, cb); } + @Deprecated public GetsOperation mgets(Collection keys, GetsOperation.Callback cb) { return new MGetsOperationImpl(keys, cb); } diff --git a/src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java index 13e0fd0a8..9eced2660 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/BaseGetOpImpl.java @@ -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 \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 \r\n\r\n int lenKeys = keysString.getBytes().length; int numKeys = keys.size(); + commandBuilder.append("m"); commandBuilder.append(cmd); commandBuilder.append(' '); commandBuilder.append(lenKeys); diff --git a/src/main/java/net/spy/memcached/protocol/ascii/MGetOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/MGetOperationImpl.java index 41ff1f7af..328967866 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/MGetOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/MGetOperationImpl.java @@ -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 k, Callback c) { super(CMD, c, new HashSet<>(k)); - setAPIType(APIType.MGET); + setAPIType(APIType.GET); } } diff --git a/src/main/java/net/spy/memcached/protocol/ascii/MGetsOperationImpl.java b/src/main/java/net/spy/memcached/protocol/ascii/MGetsOperationImpl.java index c0a92b97b..8413b2fcb 100644 --- a/src/main/java/net/spy/memcached/protocol/ascii/MGetsOperationImpl.java +++ b/src/main/java/net/spy/memcached/protocol/ascii/MGetsOperationImpl.java @@ -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 k, Callback c) { super(CMD, c, new HashSet<>(k)); - setAPIType(APIType.MGETS); + setAPIType(APIType.GETS); } } diff --git a/src/main/java/net/spy/memcached/protocol/binary/BinaryOperationFactory.java b/src/main/java/net/spy/memcached/protocol/binary/BinaryOperationFactory.java index 6d261269e..a2ba1bcdf 100644 --- a/src/main/java/net/spy/memcached/protocol/binary/BinaryOperationFactory.java +++ b/src/main/java/net/spy/memcached/protocol/binary/BinaryOperationFactory.java @@ -113,11 +113,13 @@ public GetsOperation gets(Collection keys, GetsOperation.Callback callba "gets is not supported in binary protocol yet."); } + @Deprecated public GetOperation mget(Collection keys, GetOperation.Callback cb) { throw new RuntimeException( "mget is not supported in binary protocol yet."); } + @Deprecated public GetsOperation mgets(Collection keys, GetsOperation.Callback cb) { throw new RuntimeException( "mgets is not supported in binary protocol yet.");