[PATCH] MemCached PHP client fix+feature

Shiar shiar at shiar.org
Mon Sep 27 04:58:37 PDT 2004


First off, thanks for memcached.  We're now using it for storing login
sessions on our site cu2.nl (200000 visitors a day), and it's doing a great
job.

I hope this is also the right list for sending patches for the PHP client by
Ryan Gilfether (1.0.10).  It contains two small things:

- Fixed get() so that arrayrefs are handled correctly.

- Added no_rehash option and set_norehash(), as found in the Perl API.

-- 
Shiar - http://www.shiar.org
> Prokrastadu longe, povus malaperi
-------------- next part --------------
--- MemCachedClient.inc.php.old	Thu Aug 14 21:08:21 2003
+++ MemCachedClient.inc.php	Mon Sep 27 11:22:04 2004
@@ -71,6 +71,11 @@
      */
     var $debug;
     /**
+     * set to disable finding alternative memcached servers
+     * @var bool
+     */
+    var $no_rehash;
+    /**
      * array of servers to attempt to use, "host:port" string format
      * @var array
      */
@@ -132,6 +137,7 @@
 		{
 			$this->set_servers($options["servers"]);
 			$this->debug = $options["debug"];
+			$this->no_rehash = $options["no_rehash"];
 			$this->compress = $options["compress"];
 			$this->cache_sock = array();
 		}
@@ -169,6 +175,20 @@
 
 
 	/**
+	 * if set, will disable finding a new memcached server when one goes down.
+	 * Your application may or may not need this, depending on your expirations
+	 * and key usage.
+	 *
+	 * @access public
+	 * @param bool $do_norehash
+	 */
+	function set_norehash($do_norehash)
+	{
+		$this->no_rehash = $do_norehash;
+	}
+
+
+	/**
 	 * remove all cached hosts that are no longer good
 	 *
 	 * @access public
@@ -392,7 +412,9 @@
 	 */
 	function get($key)
 	{
-		$val =& $this->get_multi($key);
+		$val =& $this->get_multi(array($key));
+
+		$key = is_array($key) ? $key[1] : $key;
 
 		if(!$val)
 		{
@@ -712,6 +734,9 @@
 			if(is_resource($sock))
 				return $sock;
 
+			if($this->no_rehash)
+				break;
+
 			$hv += $this->_hashfunc($tries.$real_key);
 			++$tries;
 		}


More information about the memcached mailing list