I don't think you should implement a peek command in memcached's server. If you need a convenience function, add one in your application that does the add routine, and call it yourself.
On Wed, 21 Mar 2012, TragicWarrior wrote: > Thanks for the reply. So is it not worth implementing a wrapper > function that responds to a PEEK command at all or would you suggest > adding it as a convenience func using the means you described? > > On Wednesday, March 21, 2012 9:34:44 PM UTC-5, Dormando wrote: > > I'm thinking about implementing a PEEK command. It turns out that on > > large payloads ( >= 1MB) it would be advantageous to know if the data > > already exists before doing all the work to create the data. I would > > like to solicited some feedback before I dive into it. > > > > - Is there already a way to check for the existence of a key before > > fetching the data? If so, then I would like to know how to do so and > > not waste my time. > > > > - I was thinking this would be more-or-less a clone of item_get() as > > item_peek() except it returns 1 or 0 to the user instead of the > > payload. > > > > Thoughts? > > Just do a 0 byte add with an expiration time in the past. If the add > succeeds, the item wasn't already there. > > For bonus points, you could add with a 5 second timeout, then use set to > overwrite your key. So two processes would serialize on the add call. > > touch could probably be used as well. > > > On Wednesday, March 21, 2012 9:34:44 PM UTC-5, Dormando wrote: > > I'm thinking about implementing a PEEK command. It turns out that on > > large payloads ( >= 1MB) it would be advantageous to know if the data > > already exists before doing all the work to create the data. I would > > like to solicited some feedback before I dive into it. > > > > - Is there already a way to check for the existence of a key before > > fetching the data? If so, then I would like to know how to do so and > > not waste my time. > > > > - I was thinking this would be more-or-less a clone of item_get() as > > item_peek() except it returns 1 or 0 to the user instead of the > > payload. > > > > Thoughts? > > Just do a 0 byte add with an expiration time in the past. If the add > succeeds, the item wasn't already there. > > For bonus points, you could add with a 5 second timeout, then use set to > overwrite your key. So two processes would serialize on the add call. > > touch could probably be used as well. > > >
