Best practices for automatically removing spaces from keys...

Josh Berkus josh at agliodbs.com
Thu Nov 18 13:41:30 PST 2004


Sean,

> I'm curious what people think the best practices are regarding spaces
> in keys.  In libmemcache(3), I pass spaces right through to the wire
> and am not too terribly happy about that.  What is the best
> alternative?  I'm thinking that replacing it with '_' would be more
> appropriate, or even (char)254 since that should fail isspace(3) and
> would be reasonably unique enough to allow (char)254 to be mapped back
> to a space (yeah, I know non-ascii keys will break, but...).  Thoughts?

My general approach is not to let users generate keys.  If your code generates 
the keys, then you don't need to worry about spaces.

However, I've had this same problem on ltree (postgresql tool) and there I 
used _.   I find that regular users aren't going to use _ much, if at all, 
and converting them back to spaces is no problem.

Of course, I've yet to stash the filesystem in memcached, which would raise 
exactly this issue.   In that case, I'd probably use some utterly improbable 
string .... like _*_ rather than risk breaking some client with chr(254).

-- 
--Josh

Josh Berkus
Aglio Database Solutions
San Francisco


More information about the memcached mailing list