Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

MemcachedClient.set() or add() aren't reliable?

2 replies [Last post]
  • Login or register to post comments
Wed, 08/03/2011 - 09:40
edy_at_ssn
Offline
Joined: 08/01/2011
Groups: None

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

Top
  • Login or register to post comments
Wed, 08/03/2011 - 09:50
edy_at_ssn
Offline
Joined: 08/01/2011
Groups: None

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++; }
}

Top
  • Login or register to post comments
Wed, 08/03/2011 - 11:01
mikew
Offline
Joined: 03/14/2011
Groups:

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");
}

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker