cvs: phpdoc /en/reference/memcached/memcached cas.xml casbykey.xml

From: Date: Wed, 04 Feb 2009 21:52:39 +0000
Subject: cvs: phpdoc /en/reference/memcached/memcached cas.xml casbykey.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-3145@lists.php.net to get a copy of this message
andrei Wed Feb 4 21:52:39 2009 UTC Modified files: /phpdoc/en/reference/memcached/memcached cas.xml casbykey.xml Log: cas* methods docs

http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/memcached/memcached/cas.xml?r1=1.1&r2=1.2&diff_format=u Index: phpdoc/en/reference/memcached/memcached/cas.xml diff -u phpdoc/en/reference/memcached/memcached/cas.xml:1.1 phpdoc/en/reference/memcached/memcached/cas.xml:1.2 --- phpdoc/en/reference/memcached/memcached/cas.xml:1.1 Fri Jan 30 00:04:29 2009 +++ phpdoc/en/reference/memcached/memcached/cas.xml Wed Feb 4 21:52:39 2009 @@ -1,23 +1,30 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry xml:id="memcached.cas" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>Memcached::cas</refname> - <refpurpose>The cas purpose</refpurpose> + <refpurpose>Compare and swap an item</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> - <modifier>public</modifier> <type>void</type><methodname>Memcached::cas</methodname> - <methodparam><type>string</type><parameter>cas_token</parameter></methodparam> + <modifier>public</modifier> <type>bool</type><methodname>Memcached::cas</methodname> + <methodparam><type>double</type><parameter>cas_token</parameter></methodparam> <methodparam><type>string</type><parameter>key</parameter></methodparam> - <methodparam><type>string</type><parameter>value</parameter></methodparam> - <methodparam choice="opt"><type>string</type><parameter>expiration</parameter></methodparam> + <methodparam><type>mixed</type><parameter>value</parameter></methodparam> + <methodparam choice="opt"><type>int</type><parameter>expiration</parameter></methodparam> </methodsynopsis> <para> - The method description goes here. + <function>Memcached::cas</function> performs a "check and set" operation, + so that the item will be stored only if no other client has updated it + since it was last fetched by this client. The check is done via the + <parameter>cas_token</parameter> parameter which is a unique 64-bit + value assigned to the existing item by memcache. See the documentation for + <methodname>Memcached::get*</methodname> methods for how to obtain this + token. Note that the token is represented as a double due to the + limitations of PHP's integer space. </para> </refsect1> @@ -29,7 +36,7 @@ <term><parameter>cas_token</parameter></term> <listitem> <para> - Description... + Unique value associated with the existing item. Generated by memcache. </para> </listitem> </varlistentry> @@ -37,7 +44,7 @@ <term><parameter>key</parameter></term> <listitem> <para> - Description... + The key under which to store the value. </para> </listitem> </varlistentry> @@ -45,7 +52,7 @@ <term><parameter>value</parameter></term> <listitem> <para> - Description... + The value to store. </para> </listitem> </varlistentry> @@ -53,7 +60,8 @@ <term><parameter>expiration</parameter></term> <listitem> <para> - Description... + The expiration time, defaults to 0. See <link + linkend="memcached.expiration">Expiration Times</link> for more info. </para> </listitem> </varlistentry> @@ -64,7 +72,10 @@ <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> - Description... + &return.success; + The <methodname>Memcached::getResultCode</methodname> will return + <constant>Memcached::RES_DATA_EXISTS</constant> if the item you are trying + to store has been modified since you last fetched it. </para> </refsect1> @@ -76,16 +87,28 @@ <programlisting role="php"> <![CDATA[ <?php -/* ... */ +$m = new Memcached(); +$m->addServer('localhost', 11211); + +do { + /* fetch IP list and its token */ + $ips = $m->get('ip_block', null, $cas); + /* if list doesn't exist yet, create it and do + an atomic add which will fail if someone else already added it */ + if ($m->getResultCode() == Memcached::RES_NOTFOUND) { + $ips = array($_SERVER['REMOTE_ADDR']); + $m->add('ip_block', $ips); + /* otherwise, add IP to the list and store via compare-and-swap + with the token, which will fail if someone else updated the list */ + } else { + $ips[] = $_SERVER['REMOTE_ADDR']; + $m->cas($cas, 'ip_block', $ips); + } +} while ($m->getResultCode() != Memcached::RES_SUCCESS); + ?> ]]> </programlisting> - &example.outputs.similar; - <screen> -<![CDATA[ -... -]]> - </screen> </example> </para> </refsect1> @@ -94,7 +117,7 @@ &reftitle.seealso; <para> <simplelist> - <member><methodname>Classname::Method</methodname></member> + <member><methodname>Memcached::casByKey</methodname></member> </simplelist> </para> </refsect1> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/memcached/memcached/casbykey.xml?r1=1.1&r2=1.2&diff_format=u Index: phpdoc/en/reference/memcached/memcached/casbykey.xml diff -u phpdoc/en/reference/memcached/memcached/casbykey.xml:1.1 phpdoc/en/reference/memcached/memcached/casbykey.xml:1.2 --- phpdoc/en/reference/memcached/memcached/casbykey.xml:1.1 Fri Jan 30 00:04:29 2009 +++ phpdoc/en/reference/memcached/memcached/casbykey.xml Wed Feb 4 21:52:39 2009 @@ -1,24 +1,28 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry xml:id="memcached.casbykey" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> <refname>Memcached::casByKey</refname> - <refpurpose>The casByKey purpose</refpurpose> + <refpurpose>Compare and swap an item on a specific server</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <methodsynopsis> - <modifier>public</modifier> <type>void</type><methodname>Memcached::casByKey</methodname> - <methodparam><type>string</type><parameter>cas_token</parameter></methodparam> + <modifier>public</modifier> <type>bool</type><methodname>Memcached::casByKey</methodname> + <methodparam><type>double</type><parameter>cas_token</parameter></methodparam> <methodparam><type>string</type><parameter>server_key</parameter></methodparam> <methodparam><type>string</type><parameter>key</parameter></methodparam> - <methodparam><type>string</type><parameter>value</parameter></methodparam> - <methodparam choice="opt"><type>string</type><parameter>expiration</parameter></methodparam> + <methodparam><type>mixed</type><parameter>value</parameter></methodparam> + <methodparam choice="opt"><type>int</type><parameter>expiration</parameter></methodparam> </methodsynopsis> <para> - The method description goes here. + <function>Memcached::casByKey</function> is functionally equivalent to + <methodname>Memcached::cas</methodname>, except that the free-form + <parameter>server_key</parameter> can be used to map the + <parameter>key</parameter> to a specific server. This is useful if you need + to keep a bunch of related keys on a certain server. </para> </refsect1> @@ -30,7 +34,7 @@ <term><parameter>cas_token</parameter></term> <listitem> <para> - Description... + Unique value associated with the existing item. Generated by memcache. </para> </listitem> </varlistentry> @@ -38,7 +42,7 @@ <term><parameter>server_key</parameter></term> <listitem> <para> - Description... + The key identifying the server to store the value on. </para> </listitem> </varlistentry> @@ -46,7 +50,7 @@ <term><parameter>key</parameter></term> <listitem> <para> - Description... + The key under which to store the value. </para> </listitem> </varlistentry> @@ -54,7 +58,7 @@ <term><parameter>value</parameter></term> <listitem> <para> - Description... + The value to store. </para> </listitem> </varlistentry> @@ -62,7 +66,8 @@ <term><parameter>expiration</parameter></term> <listitem> <para> - Description... + The expiration time, defaults to 0. See <link + linkend="memcached.expiration">Expiration Times</link> for more info. </para> </listitem> </varlistentry> @@ -73,29 +78,10 @@ <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> - Description... - </para> - </refsect1> - - <refsect1 role="examples"> - &reftitle.examples; - <para> - <example> - <title><function>Memcached::casByKey</function> example</title> - <programlisting role="php"> -<![CDATA[ -<?php -/* ... */ -?> -]]> - </programlisting> - &example.outputs.similar; - <screen> -<![CDATA[ -... -]]> - </screen> - </example> + &return.success; + The <methodname>Memcached::getResultCode</methodname> will return + <constant>Memcached::RES_DATA_EXISTS</constant> if the item you are trying + to store has been modified since you last fetched it. </para> </refsect1> @@ -103,7 +89,7 @@ &reftitle.seealso; <para> <simplelist> - <member><methodname>Classname::Method</methodname></member> + <member><methodname>Memcached::cas</methodname></member> </simplelist> </para> </refsect1>
« previous php.doc.cvs (#3145) next »