title: Distinction between str and unicode: why does Redis return binary data when passed unicode?
body: <p>After <a href="https://stackoverflow.com/questions/35618833/increased-understanding-of-unicode-in-python-2-7">two</a> <a href="https://stackoverflow.com/questions/35709765/encapsulating-unicode-from-redis">questions</a> regarding the distinction between the datatypes <code>str</code> and <code>unicode</code>, I'm still puzzled at the following.</p>
  
  <p>In Block 1 we see that the type of the city is <code>unicode</code>, as we're expecting.</p>
  
  <p>Yet in Block 2, after a round-trip through disk (redis), the type of the city is <code>str</code> (and the representation is different).</p>
  
  <p>The <a href="http://nedbatchelder.com/text/unipain.html" rel="noreferrer">dogma</a> of storing <code>utf-8</code> on disk, reading into <code>unicode</code>, and writing back in <code>utf-8</code> is failing somewhere.</p>
  
  <p>Why is the second instance of <code>type(city)</code> <code>str</code> rather than <code>unicode</code>?</p>
  
  <p>Just as importantly, does it matter? Do you care whether your variables are <code>unicode</code> or <code>str</code>, or are you oblivious to the difference just so long as the code "does the right thing"?</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  # Block 1
  city = u'Düsseldorf'
  print city, type(city), repr(city)
  # Düsseldorf &lt;type 'unicode'&gt; u'D\xfcsseldorf'
  
  # Block 2
  import redis
  r_server = redis.Redis('localhost')
  r_server.set('city', city)
  city = r_server.get('city')
  print city, type(city), repr(city)
  # Düsseldorf &lt;type 'str'&gt; 'D\xc3\xbcsseldorf'
  </code></pre>