4

I want to store a key with special char (slash in my case) to Riak via REST.

HowTo http://wiki.basho.com/Riak-Search---Querying.html#Fields says:

If your field contains special characters, such as (‘+’,‘-’,‘/’,‘[’,‘]’,‘(’,‘)’,‘:’ or space), then either surround the phrase in single quotes, or escape each special character with a backslash.

But the fields are concerned, not the keys. I tried to backslash it, but it didn't work unfortunately.

I couldn't find any information regardind this issue. Does anybody know how to mask special chars in keys?

Example (not working):

PUT https://riak:8069/buckets/key/keys/11111\/2

where key is 11111/2

shipik
  • 45
  • 4

1 Answers1

6

This has nothing to do with Riak specifically but rather how you need to escape URLs so a server (including Riak) doesn't interpret the forward slash as a path separator:

PUT https://riak:8069/buckets/key/keys/11111%2F2

You can then retrieve it the same way:

GET https://riak:8069/riak/key/11111%2F2

%2F is the value for / when using URL Encoding - if your keys contain characters that are considered special characters in URLs, you need to do so with your keys.

You can verify this worked correctly in Riak by listing the keys in your key bucket (on a test server - don't do this on a production server as it is very expensive):

GET https://riak:8069/riak/key?keys=true

At the end of the JSON output you will find:

... "keys":[...,"11111/2",...]} 
Brian Roach
  • 76,169
  • 12
  • 136
  • 161
  • I've thought about URL Encoding, but I suppose in this case the key will be 11111%2F2, not 11111/2. Because it only changes the view, not the real value. Am I right? – shipik Mar 20 '12 at 17:02
  • No - that's why I added the part at the end about listing your keys to verify/prove that Riak is storing the actual `/` in the key, not `%2F`. Or am I misunderstanding what you're asking? – Brian Roach Mar 20 '12 at 17:04
  • Yes, you are right. It is stored as 11111/2, not encoded. Thanks! – shipik Mar 20 '12 at 17:21
  • No problem. If you ever have questions, feel free to ask us directly on the riak-users mailing list: http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com – Brian Roach Mar 20 '12 at 17:23