setReadPreference() публичный Метод

public setReadPreference ( $readPreference, $tags = null )
 /**
  * Get mongo db stream collection
  *
  * @return \MongoCollection
  */
 private function getCollection()
 {
     if (null === $this->collection) {
         $this->collection = $this->mongoClient->selectCollection($this->dbName, $this->streamCollectionName);
         $this->collection->setReadPreference(\MongoClient::RP_PRIMARY);
     }
     return $this->collection;
 }
Пример #2
0
 /**
  * Set whether secondary read queries are allowed for this collection.
  *
  * This method wraps setSlaveOkay() for driver versions before 1.3.0. For
  * newer drivers, this method wraps setReadPreference() and specifies
  * SECONDARY_PREFERRED.
  *
  * @see http://php.net/manual/en/mongocollection.setreadpreference.php
  * @see http://php.net/manual/en/mongocollection.setslaveokay.php
  * @param boolean $ok
  * @return boolean Previous slaveOk value
  */
 public function setSlaveOkay($ok = true)
 {
     $prevSlaveOkay = $this->getSlaveOkay();
     if ($ok) {
         // Preserve existing tags for non-primary read preferences
         $readPref = $this->getReadPreference();
         $tags = !empty($readPref['tagsets']) ? $readPref['tagsets'] : [];
         $this->mongoCollection->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, $tags);
     } else {
         $this->mongoCollection->setReadPreference(\MongoClient::RP_PRIMARY);
     }
     return $prevSlaveOkay;
 }
Пример #3
0
 /**
  * Set whether secondary read queries are allowed for this collection.
  *
  * This method wraps setSlaveOkay() for driver versions before 1.3.0. For
  * newer drivers, this method wraps setReadPreference() and specifies
  * SECONDARY_PREFERRED.
  *
  * @see http://php.net/manual/en/mongocollection.setreadpreference.php
  * @see http://php.net/manual/en/mongocollection.setslaveokay.php
  * @param boolean $ok
  * @return boolean Previous slaveOk value
  */
 public function setSlaveOkay($ok = true)
 {
     if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
         return $this->mongoCollection->setSlaveOkay($ok);
     }
     $prevSlaveOkay = $this->getSlaveOkay();
     if ($ok) {
         // Preserve existing tags for non-primary read preferences
         $readPref = $this->getReadPreference();
         $tags = !empty($readPref['tagsets']) ? $readPref['tagsets'] : array();
         $this->mongoCollection->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, $tags);
     } else {
         $this->mongoCollection->setReadPreference(\MongoClient::RP_PRIMARY);
     }
     return $prevSlaveOkay;
 }
Пример #4
0
 public function readNearest(array $tags = null)
 {
     $this->_mongoCollection->setReadPreference(\MongoClient::RP_NEAREST, $tags);
     return $this;
 }