title: Why is Postgres query faster than Redis query?
body: <p>I am learning about Redis, and how its blazing fast since its an in-memory database. In my Django application, I have a Postgres table with about 1500 rows in it. The model only has two fields 'name' and 'occurrence'. To test out how much faster it would be to query for objects out of memory, compared to from my local database, which I believe is stored on disc, I created two queries</p>
  
  <blockquote>
    <p>1) Simple order by query using Django objects manager</p>
    
    <p>2) ZRANGE command on Redis server, getting same items back from a
    Redis sorted set.</p>
  </blockquote>
  
  <p>After making both queries, I found that getting the same number of items from a Redis sorted set took 250 times longer than it took to make the Postgres Query. Why is this ?</p>
  
  <p>Script</p>
  
  <pre><code>import json
  import redis
  import datetime
  
  from django.http import HttpResponse
  from django.shortcuts import render
  
  from wikipedia.models import Word
  
  redis_server = redis.Redis("localhost")
  
  def get_word_results(request):
      now = datetime.datetime.now()
      words = Word.objects.all().order_by('-occurrence')
      after = datetime.datetime.now()
  
      diff = (after - now).total_seconds() * 1000
      print(diff)
  
      rnow = datetime.datetime.now()
      words_redis = redis_server.zrange(name='myzset', start=0, end=-1, withscores=True)
      rafter = datetime.datetime.now()
  
      diff2 = (rafter - rnow).total_seconds() * 1000
      print(diff2)
  </code></pre>
  
  <p>Results</p>
  
  <pre><code>0.199
  48.048
  </code></pre>