DynamoDB PHP getItem() - How to tell if item does not exist -


i writing "get or create" method attempts item, if doesn't exist, create fresh new version of it. obviously, want know item didn't exist when attempted it, never overwrites existing data.

am correct in assuming $result["item"] === null if , if item did not exist in database @ time of request? is, if item existed prior request, condition evaluate false, regardless of api errors, etc.? or there else should check instead?

    $result = $this->client->getitem(         array(             "tablename" => $tablename,             "key" => array(                 $keyname => array(type::string => $key),             )         )     );      if ( $result["item"] === null )     {         //item not exist; create , write dynamodb (code not shown)     }      return $result["item"]; 

i add 'consistentread' => true in order make sure read getting absolute, up-to-date data.

you still going have potential race condition here if multiple processes try item , see not there, try write item, 1 process won't have data clobbered. long there no chance write different data, doesn't matter.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -