title: How the duplication of data come in django and how can I avoid it?
body: <p>I am doing a project by django,just a person project.</p>
  <p>I try the project by django with celery,and add two task in celery.</p>
  <p>one task, is about a spider write by requests,get some proxy ip information and save to mysql by django orm ,which is update_or_create(defaults={'ip':'','port':''},**{'key':'value'}).I keep this task would always control data by one worker through redis lock.such as ,one work run the task,redis lock get and the other work try to get lock failed and would not contorl the data.</p>
  <p>the other task,is a spider,write by tornado,which is used to check the proxy ip data. Also, would run by one worker through redis lock. and the spider by tornado is a single thread ,too.</p>
  <p>the two task may run at the same time.</p>
  <h2>Here comes the problem!</h2>
  <p>when  I run the project a few time later,about several hours later. I found some data are the same in mysql. The ip,port and some others are the same.</p>
  <p>And when the code run to update_or_create() comes the error :</p>
  <h3><em>get() return 2.</em></h3>
  <p>How the data come? In my thought,although at most two thread would run together, but one is use updata_or_create,one is use .save() .The task use save() would not born duplication of data?and the update_or_create() would check the data by get(), it means coming None to say no data like this ip and port in database,but ,it has.</p>
  <p>Could anyone explain the reason to me ?</p>