MemcachedClient.set() or add() aren't reliable?
Hi,
I'm trying to do simple set()/add() and get() and found that most of the objects I set() aren't there - I set() 10000 and when I get() only 985 are found.
Here is the code:
public static void testInsert(int count) throws Exception {
Device d = null;
long t0 = System.currentTimeMillis();
long t1 = System.currentTimeMillis();
for (int i=0; i
The set(String, int Object) function is an asynchronous call that returns a Future. This means that although you did a set and the function returned the value might not have actually been set in memcached. Then you do your gets and if one of the gets gets to memcached before the set does then memcached will say the item doesn't exist. If you change the line of code doing sets to client.set(key, new Device(i)).get() then this function will block until the set actually takes place and memcached responds to the client to tell it whether or not the set worked. Try this code below:
for (int i=0; i<10000; i++) {
String key = "device"+i;
if (!client.set(key, new Device(i)).get().booleanValue()) {
System.out.println("Set on key " + key + " failed");
}
Hmm...my full message is trimmed. Not sure how I can post this code. Basically:
for (int i=0; i<10000; i++) {
String key = "device"+i;
client.set(key, new Device(i));
}
For get:
for (int i=0; i<10000; i++) {
Object o = client.get("device"+i);
if (o != null) { found++; }
}