PHP API suggestion? Maybe?

Justin Matlock jmat@shutdown.net
Thu, 9 Oct 2003 11:43:33 -0400


This isn't necessarily a bug, but it's been annoying me..  Maybe it's not a
problem, and I'm just missing something obvious (wouldn't be surprising
these days)...

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.

Of course, this would suck if you were storing a single NULL... but I would
think 'false' would be stored more than NULL.

Yeah, a way around this would be to never store FALSE as a boolean, and use
=== to differentiate between FALSE and 0...  I just see a big potential for
bugs this way, since FALSE == 0 is true, but FALSE === 0 is untrue.  But, I
have to be able to tell the difference between "no records found" and "0"
and "false".

(I wrapped the memcached API with my own methods, just so I didn't have to
make mass changes if the API changes).. an example function:

if ($var = (mc_get("keyname") === NULL) {
    $R = db_quick("select value from table where foo='bar'");
    mc_put("keyname",$var);
}

As I'm writing this, I realize my db_wrapper could just return a NULL
instead of a false, and *I* could store the NULL in memcached to signify no
data.. duh... But it would still be nice if the memcached returned NULL if
no data found, just in case someone does store a boolean FALSE in there..

Thoughts?  Or am I just smoking crack?  I just like using NULL as it's
intended == "No Data", since False could be valid data.. :)

Justin

----- Original Message ----- 
From: "Ryan T. Dean" <rtdean-lists-memcache@cytherianage.net>
To: <memcached@lists.danga.com>
Sent: Thursday, October 09, 2003 10:57 AM
Subject: Re: [2nd try] PHP client question: why socket_create()?