Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 1.8.x

Key character set

2 replies [Last post]
  • Login or register to post comments
Tue, 03/19/2013 - 12:30
fischer70
Offline
Joined: 03/19/2013
Groups: None

We've bumped against the key size limit (250 "characters") and are compressing the keys as they go in to get them to fit. I seem to be able to pass in 250 length strings from the Java client (which from Java's point of view is 500 bytes, as they are 2-byte UTF characters). I'm guessing this get's transmuted to a 250 char string in the client side libraries somewhere? If so, what's the character set so I can ensure my ugly compressed strings are all represented?

Thanks!

Top
  • Login or register to post comments
Fri, 03/22/2013 - 04:52
daschl
Offline
Joined: 05/19/2012
Groups: None

Hi,

so normally, Couchbase can store anything that is UTF-8 encoded and is not longer than around 250 characters. Do you have problems with storing 250 utf-8 characters through the SDK?

Let me know and if you have some problems just post a concrete example and we'll walk it through from there.

Thanks!

Top
  • Login or register to post comments
Fri, 03/22/2013 - 05:09
fischer70
Offline
Joined: 03/19/2013
Groups: None

Hi,

Thanks for the reply. The 250 character limit does mess us up, but I believe I was able to track down the function that the Java client uses to validate the key so I can act accordingly. If I did find the correct block of code, then it's a byte count, which means you have to be careful with UTF-8, as many characters will need two bytes and key.length() doesn't necessarily tell you what you need. For posterity, I copied the function below in case anyone else wonders.

public  void validateKey(String key) throws Exception {
	byte[] keyBytes = key.getBytes("UTF-8");
	if (keyBytes.length > 250) {
		System.err.println(key + " is " + key.length() + " characters, but " + keyBytes.length+ " bytes.");
		throw new IllegalArgumentException("Key is too long (maxlen = " + 250 + ")");
	}
	if (keyBytes.length == 0) {
		throw new IllegalArgumentException("Key must contain at least one character.");
	}
	for (byte b : keyBytes) {
		if (b == ' ' || b == '\n' || b == '\r' || b == 0) {
			throw new IllegalArgumentException("Key contains invalid characters:  ``" + key + "''");
		}
	}
}

Best,
Nate

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