[ci skip] Fix #3919, #4732
diff --git a/system/libraries/Session/drivers/Session_memcached_driver.php b/system/libraries/Session/drivers/Session_memcached_driver.php
index 88eb4b3..99b4d1b 100644
--- a/system/libraries/Session/drivers/Session_memcached_driver.php
+++ b/system/libraries/Session/drivers/Session_memcached_driver.php
@@ -209,10 +209,7 @@
 			$this->_memcached->replace($this->_lock_key, time(), 300);
 			if ($this->_fingerprint !== ($fingerprint = md5($session_data)))
 			{
-				if (
-					$this->_memcached->replace($key, $session_data, $this->_config['expiration'])
-					OR ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration']))
-				)
+				if ($this->_memcached->set($key, $session_data, $this->_config['expiration']))
 				{
 					$this->_fingerprint = $fingerprint;
 					return $this->_success;
@@ -220,8 +217,7 @@
 
 				return $this->_fail();
 			}
-
-			if (
+			elseif (
 				$this->_memcached->touch($key, $this->_config['expiration'])
 				OR ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration']))
 			)
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index c09c1b5..400b36e 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -12,7 +12,7 @@
 Bug fixes for 3.1.1
 -------------------
 
-
+-  Fixed a bug (#4732) - :doc:`Session Library <libraries/sessions>` triggered errors while writing data for a newly-created sessions with the 'memcached' driver.
 
 
 Version 3.1.0