コード例 #1
0
 public function store($id, $data)
 {
     $ids = Util::validateIds($this->shardSequences(), array($id));
     if (!in_array($id, $ids)) {
         throw new Exception('invalid id', $id);
     }
     $this->store->set($id, $data);
     return TRUE;
 }
コード例 #2
0
 /**
  * update an existing entry based on id. It does an insert or update just in case the record is missing in the db.
  */
 public function store($id, $data)
 {
     $ids = Util::validateIds($this->shardSequences(), array($id));
     if (!in_array($id, $ids)) {
         throw new Exception('invalid id', $id);
     }
     list($shard, $sequence) = Util::parseId($id);
     $table = $this->table($shard);
     $db = $this->db($table);
     if (DB\Transaction::inProgress()) {
         DB\Transaction::add($db);
     }
     $sql = "INSERT INTO {$table} (thread, sequence, data) VALUES (%i, %i, %s) ON DUPLICATE KEY UPDATE `data` = VALUES(`data`)";
     $db->execute($sql, $this->thread, $sequence, $this->serialize($data));
     return TRUE;
 }
コード例 #3
0
 /**
  * update an existing entry based on id. It does an insert or update just in case the record is missing in the db.
  */
 public function store($id, $data)
 {
     $ids = Util::validateIds($this->shardSequences(), array($id));
     if (!in_array($id, $ids)) {
         throw new Exception('invalid id', $id);
     }
     list($shard, $sequence) = Util::parseId($id);
     $table = $this->table($shard);
     $db = $this->db($table);
     if (DB\Transaction::inProgress()) {
         DB\Transaction::add($db);
     }
     $sql = "INSERT OR IGNORE INTO {$table} (thread, sequence, data) VALUES (%i, %i, %s)";
     $data = $this->serialize($data);
     $rs = $db->execute($sql, $this->thread, $sequence, $data);
     if (!$rs->affected()) {
         $sql = "UPDATE {$table} SET `data` = %s WHERE `thread` = %i AND `sequence` = %i";
         $db->execute($sql, $data, $this->thread, $sequence);
     }
     return TRUE;
 }