Skip to content

Commit

Permalink
(fix) invalidateNamespace not work when sanitizeKeys is true, issue #85
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 committed Jul 8, 2018
1 parent 1f48c70 commit 5b7611b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/main/java/net/rubyeye/xmemcached/XMemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.code.yanf4j.config.Configuration;
import com.google.code.yanf4j.core.Session;
import com.google.code.yanf4j.core.SocketOption;
import com.google.code.yanf4j.util.SystemUtils;
import net.rubyeye.xmemcached.auth.AuthInfo;
import net.rubyeye.xmemcached.buffer.BufferAllocator;
import net.rubyeye.xmemcached.buffer.SimpleBufferAllocator;
Expand Down Expand Up @@ -62,12 +68,6 @@
import net.rubyeye.xmemcached.utils.ByteUtils;
import net.rubyeye.xmemcached.utils.InetSocketAddressWrapper;
import net.rubyeye.xmemcached.utils.Protocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.code.yanf4j.config.Configuration;
import com.google.code.yanf4j.core.Session;
import com.google.code.yanf4j.core.SocketOption;
import com.google.code.yanf4j.util.SystemUtils;

/**
* Memcached Client for connecting to memcached server and do operations.
Expand Down Expand Up @@ -2505,8 +2505,8 @@ private String preProcessKey(String key) throws MemcachedException, InterruptedE

public void invalidateNamespace(String ns, long opTimeout)
throws MemcachedException, InterruptedException, TimeoutException {
String key = this.getNSKey(ns);
this.incr(key, 1, System.currentTimeMillis(), opTimeout);
String key = this.keyProvider.process(this.getNSKey(ns));
this.sendIncrOrDecrCommand(key, 1, System.nanoTime(), CommandType.INCR, false, opTimeout, 0);
}

public void invalidateNamespace(String ns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.google.code.yanf4j.buffer.IoBuffer;
import com.google.code.yanf4j.util.ResourcesUtils;
import junit.framework.Assert;
import junit.framework.TestCase;
import net.rubyeye.xmemcached.CASOperation;
import net.rubyeye.xmemcached.Counter;
import net.rubyeye.xmemcached.GetsResponse;
import net.rubyeye.xmemcached.KeyIterator;
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.MemcachedClientCallable;
Expand Down Expand Up @@ -49,8 +49,6 @@
import net.rubyeye.xmemcached.utils.AddrUtil;
import net.rubyeye.xmemcached.utils.ByteUtils;
import net.rubyeye.xmemcached.utils.Protocol;
import com.google.code.yanf4j.buffer.IoBuffer;
import com.google.code.yanf4j.util.ResourcesUtils;

public abstract class XMemcachedClientIT extends TestCase {
protected MemcachedClient memcachedClient;
Expand Down Expand Up @@ -1223,6 +1221,26 @@ public Void call(MemcachedClient client)

}

public void testNameSpaceWithSantiKeys() throws Exception {
this.memcachedClient.setSanitizeKeys(true);
this.memcachedClient.withNamespace("hello", new MemcachedClientCallable<Void>() {
public Void call(MemcachedClient client)
throws MemcachedException, InterruptedException, TimeoutException {
client.set("a", 0, 1);
assertEquals(1, client.get("a"));
return null;
}
});
this.memcachedClient.invalidateNamespace("hello");
this.memcachedClient.withNamespace("hello", new MemcachedClientCallable<Void>() {
public Void call(MemcachedClient client)
throws MemcachedException, InterruptedException, TimeoutException {
assertNull(client.get("a"));
return null;
}
});
}

public void testNamespaceWithGetMulti() throws Exception {
String ns = "user";
this.memcachedClient.withNamespace(ns, new MemcachedClientCallable<Void>() {
Expand Down

0 comments on commit 5b7611b

Please sign in to comment.