PHP API suggestion? Maybe?

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


--K1n7F7fSdjvFAEnM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 09, 2003 at 11:43:33AM -0400, Justin Matlock wrote:
> 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)...
>=20
> 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 boole=
an
> '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, whe=
n I
> do a get for this key, the API returns a boolean 'false' (since that's wh=
at
> 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 tho=
ugh
> it did, it was just value'd at false), and it makes another database call.
>=20
> Maybe the API should return NULL instead of FALSE if the data doesn't exi=
st;
> since NULL means 'no data'. ?  A configurable option, maybe, since this
> would mean major script changes for most people.
>=20
> Of course, this would suck if you were storing a single NULL... but I wou=
ld
> think 'false' would be stored more than NULL.
>=20
> Yeah, a way around this would be to never store FALSE as a boolean, and u=
se
> =3D=3D=3D to differentiate between FALSE and 0...  I just see a big poten=
tial for
> bugs this way, since FALSE =3D=3D 0 is true, but FALSE =3D=3D=3D 0 is unt=
rue.  But, I
> have to be able to tell the difference between "no records found" and "0"
> and "false".
>=20
> (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:
>=20
> if ($var =3D (mc_get("keyname") =3D=3D=3D NULL) {
>     $R =3D db_quick("select value from table where foo=3D'bar'");
>     mc_put("keyname",$var);
> }
>=20
> 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..
>=20
> Thoughts?  Or am I just smoking crack?  I just like using NULL as it's
> intended =3D=3D "No Data", since False could be valid data.. :)


Actually, in the coming version 0.2.0 I'll be tossing PEAR error objects=20
on error, instead of a null/false.  This will introduce a new method to=20
memcached-client: isError().  Error messages/codes will be available=20
from the error object using the normal PEAR api ($error>getCode() and=20
$error->getMessage()).

So yeah, a fix for this is coming.

		-Ryan T. Dean


--K1n7F7fSdjvFAEnM
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (FreeBSD)

iD8DBQE/hYYrW6VZzwycJGURArtYAJ0RuVk/jFevLHi6dFOUixhddw+QHQCeN5Yv
SNqwpo4gjlslf1XX3OtRD6A=
=TFb1
-----END PGP SIGNATURE-----

--K1n7F7fSdjvFAEnM--