PHP API suggestion? Maybe?

Ryan T. Dean rtdean-lists-memcache@cytherianage.net
Thu, 9 Oct 2003 12:09:11 -0400


On Thu, Oct 09, 2003 at 12:00:43PM -0400, Ryan T. Dean wrote:
> On Thu, Oct 09, 2003 at 11:43:33AM -0400, Justin Matlock wrote:
> > Let's say you actually need to store a boolean "false" value in memcached.
> > For example, if I run a query, and it returns no records, I store a boolean
> > 'false', since that would be different than if I just pulled an int 0 from
> > the DB (it means I could find a record, but the result was 0).  Well, when I
> > do a get for this key, the API returns a boolean 'false' (since that's what
> > was stored in memcached).  This, of course, usually means the key wasn't
> > found in a memcached, so my software think the key didn't exist (even though
> > it did, it was just value'd at false), and it makes another database call.
> > 
> > Maybe the API should return NULL instead of FALSE if the data doesn't exist;
> > since NULL means 'no data'. ?  A configurable option, maybe, since this
> > would mean major script changes for most people.
> 
> Actually, in the coming version 0.2.0 I'll be tossing PEAR error objects 
> on error, instead of a null/false.  This will introduce a new method to 
> memcached-client: isError().  Error messages/codes will be available 
> from the error object using the normal PEAR api ($error>getCode() and 
> $error->getMessage()).

Alternatively, you could use get_multi instead of get, and see if the 
key exists using isset($result['key']), and if it exists, check its 
value.  Both false and null should be supported there.

		-Ryan T. Dean