Key character set
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!
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
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!