Django How can I use redis in Windows10?
<p>I am developing small system with Django framework and Windows 10. I am going to use Redis for caching on memory. Well, I found that Redis doesn't support Windows OS officially but MsOpenTech provides a package for Windows 64 bit. I installed it with chocolatey package manager. <a href="https://chocolatey.org/packages/redis-64" rel="nofollow">https://chocolatey.org/packages/redis-64</a></p>

<p>Then I installed django-redis package by pip install in cmd. Well, It automatically installed redis module at the same time. I thought it would be fine to delete redis module because I already installed redis 3.0.503 64 bit(for Win). But it occured error "no mudule named 'redis'". I checked django-redis directory "django_redis-4.5.0-py3.4.egg-info". There was one line 'redis>=2.10.0' in 'requries.text' file. so I assumed django-redis is set to need redis 2.10.0 as default.</p>

<p>well, then I just installed redis by pip install redis in cmd. After setting in Django, I saved some key value data as test on redis. (by using cache_page decorator)</p>

<pre><code>CACHES = {
    "default" : {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTION": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        },
        "KEY_PREFIX": "Test"
    }
}
</code></pre>

<p>I connected to redis.</p>

<pre><code>redis-cli -n 1
</code></pre>

<p>I checked keys</p>

<pre><code>127.0.0.1:6379[1]&gt; keys *
</code></pre>

<p>result was like this. empty</p>

<pre><code>(empty list or set)
</code></pre>

<p>then I put test data on redis by cache_page decorator to check it. I got this result.</p>

<pre><code>1) "Test:1:views.decorators.cache.cache_page..GET.1be77f2243e36ea7e7fa68d85c1c277e.d41d8cd98f00b204e9800998ecf8427e.en-us.Korea_Standard_Time"
2) "Test:1:views.decorators.cache.cache_header..1be77f2243e36ea7e7fa68d85c1c277e.en-us.Korea_Standard_Time"
</code></pre>

<p>I checked it with get command.it is supposed to show rendered HTML string. </p>

<pre><code>get "Test:1:views.decorators.cache.cache_page..GET.1be77f2243e36ea7e7fa68d85c1c277e.d41d8cd98f00b204e9800998ecf8427e.en-us.Korea_Standard_Time"
</code></pre>

<p>The result like below seems alright.</p>

<pre><code>"\x80\x04\x95\xe8\a\x00\x00\x00\x00\x00\x00\x8c\x14django.http.response\x94\x8c\x0cHttpResponse\x94\x93\x94)}\x94\x92\x94}\x94(\x8c\x06closed\x94\x89\x8c\b_charset\x94N\x8c\x0e_handler_class\x94N\x8c\b_headers\x94}\x94(\x8c\x0ccontent-type\x94\x8c\x0cContent-Type\x94\x8c\x18text/html; charset=utf-8\x94\x86\x94\x8c\aexpires\x94\x8c\aExpires\x94\x8c\x1dMon, 10 Oct 2016 09:32:19 GMT\x94\x86\x94\x8c\rcache-control\x94\x8c\rCache-Control\x94\x8c\nmax-age=60\x94\x86\x94\x8c\rlast-modified\x94\x8c\rLast-Modified\x94\x8c\x1dMon, 10 Oct 2016 09:31:19 GMT\x94\x86\x94u\x8c\x0e_reason_phrase\x94N\x8c\acookies\x94\x8c\x0chttp.cookies\x94\x8c\x0cSimpleCookie\x94\x93\x94)}\x94\x92\x94\x8c\x11_closable_objects\x94]\x94\x8c\n_container\x94]\x94B/\x06\x00\x00&lt;!DOCTYPE html&gt;\n&lt;html lang=\"ko\"&gt;\n\n&lt;head&gt;\n&lt;title&gt;Menu front page&lt;/title&gt;\n&lt;/head&gt;\n\n&lt;body&gt;\n&lt;div id=\"context_processor_test\"&gt;\n\t&lt;ul&gt;\n\t\t&lt;li&gt;[&amp;lt;Menu: root&amp;gt;, &amp;lt;Menu: \xed\x98\x84\xed\x99\xa9\xeb\xb6\x84\xec\x84\x9d&amp;gt;, &amp;lt;Menu: \xec\x9e\xac\xea\xb3\xa0\xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xed\x98\x84\xec\x9e\xac \xec\x9e\xac\xea\xb3\xa0&amp;gt;, &amp;lt;Menu: \xea\xb8\xb0\xea\xb0\x84\xec\x9e\xac\xea\xb3\xa0 \xec\xa1\xb0\xed\x9a\x8c&amp;gt;, &amp;lt;Menu: \xec\x9e\xac\xea\xb3\xa0\xea\xb8\xb0\xea\xb4\x80 \xec\xa1\xb0\xed\x9a\x8c&amp;gt;, &amp;lt;Menu: \xec\x9e\xac\xea\xb3\xa0 \xed\x9a\x8c\xec\xa0\x84\xec\x9c\xa8 \xec\xa1\xb0\xed\x9a\x8c&amp;gt;, &amp;lt;Menu: \xeb\xa7\xa4\xec\x9e\x85\xeb\xa7\xa4\xec\xb6\x9c \xeb\xb6\x84\xec\x84\x9d&amp;gt;, &amp;lt;Menu: \xea\xb8\xb0\xea\xb0\x84\xeb\xb3\x84 \xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xec\x83\x81\xed\x92\x88\xeb\xb3\x84 \xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xea\xb1\xb0\xeb\x9e\x98\xed\x98\x95\xed\x83\x9c\xeb\xb3\x84 \xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xec\x82\xac\xec\x97\x85\xeb\xb6\x80\xeb\xb3\x84 \xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xea\xb1\xb0\xeb\x9e\x98\xec\xb2\x98\xeb\xb3\x84 \xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xec\x9e\x91\xec\x97\x85\xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xec\x9e\x91\xec\x97\x85\xec\x9a\x94\xec\xb2\xad \xed\x98\x84\xed\x99\xa9&amp;gt;, &amp;lt;Menu: \xea\xb2\x80\xec\x88\x98\xec\x9a\x94\xec\xb2\xad&amp;gt;, &amp;lt;Menu: \xec\x83\x81\xed\x92\x88\xed\x99\x94 \xec\x9a\x94\xec\xb2\xad&amp;gt;, &amp;lt;Menu: \xec\xa0\x9c\xed\x92\x88\xed\x99\x94 \xec\x9a\x94\xec\xb2\xad&amp;gt;, &amp;lt;Menu: \xec\x97\xbd\xec\x97\x89\xea\xb4\x80\xeb\xa6\xac&amp;gt;, &amp;lt;Menu: \xeb\x82\xb4\xeb\xb6\x80\xec\xb2\x98\xeb\xa6\xac&amp;gt;, &amp;lt;Menu: \xed\x8c\x90\xeb\xa7\xa4\xea\xb4\x80\xeb\xa6\xac&amp;gt;, &amp;lt;Menu: \xea\xb5\xac\xeb\xa7\xa4\xea\xb4\x80\xeb\xa6\xac&amp;gt;, &amp;lt;Menu: \xed\x99\x98\xea\xb2\xbd\xec\x84\xa4\xec\xa0\x95&amp;gt;]&lt;/li&gt;\n\t&lt;/ul&gt;\n&lt;/div&gt;\n\n&lt;div id=\"context_processor_test2\"&gt;\n\t&lt;ul&gt;\n\t\t&lt;li&gt;&amp;lt;QuerySet [&amp;lt;UserInfo: dkjfadl&amp;gt;, &amp;lt;UserInfo: fidlajf&amp;gt;, &amp;lt;UserInfo: fjialejgljadf&amp;gt;, &amp;lt;UserInfo: dfialghelfdja&amp;gt;, &amp;lt;UserInfo: dkajlf&amp;gt;, &amp;lt;UserInfo: testgroup&amp;gt;, &amp;lt;UserInfo: dfjlda&amp;gt;, &amp;lt;UserInfo: fjdalfiagda&amp;gt;, &amp;lt;UserInfo: remann&amp;gt;, &amp;lt;UserInfo: aldfjdalfj&amp;gt;, &amp;lt;UserInfo: dlkajflad&amp;gt;, &amp;lt;UserInfo: dkajfldafj&amp;gt;, &amp;lt;UserInfo: djafldijfl&amp;gt;, &amp;lt;UserInfo: testgroup&amp;gt;, &amp;lt;UserInfo: &amp;lt;bound method Group.__str__ of &amp;lt;Group: remann&amp;gt;&amp;gt;&amp;gt;, &amp;lt;UserInfo: remann&amp;gt;, &amp;lt;UserInfo: testgroup&amp;gt;, &amp;lt;UserInfo: testgroup&amp;gt;]&amp;gt;&lt;/li&gt;\n\t&lt;/ul&gt;\n&lt;/div&gt;\n&lt;!--\n&lt;div id=\"top_menu\"&gt;\n\t\n&lt;/div&gt;\n--&gt;\n\n\n\n\n&lt;/body&gt;\n&lt;/html&gt;\n\n\x94aub."
</code></pre>

<p>Because my templete code is like below.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="ko"&gt;

&lt;head&gt;
&lt;title&gt;{% block title %}Menu front page{% endblock %}&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="context_processor_test"&gt;
    &lt;ul&gt;
        &lt;li&gt;{{ menu_list }}&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;

&lt;div id="context_processor_test2"&gt;
    &lt;ul&gt;
        &lt;li&gt;{{ user_info_list }}&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;
&lt;!--
&lt;div id="top_menu"&gt;
    {% for top_menu in root.get_children %}
    &lt;ul style="display:inline-block;"&gt;
        &lt;li&gt;&lt;a href="{{top_menu.menu_alias}}"&gt; {{ top_menu.menu_name }} &lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
    {% endfor %}
&lt;/div&gt;
--&gt;
{% block content %}{% endblock %}

{% block footer %}{% endblock %}

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>My question are</p>

<p>1) Is it okay to use redis on Windows with this setting? I wonder if it works properly.</p>

<p>2) I wonder why it named like "Test:1:views.decorators.cache.cache_page..GET.1be77f2243e36ea7e7fa68d85c1c277e.d41d8cd98f00b204e9800998ecf8427e.en-us.Korea_Standard_Time" instead of just "Test:1:views.decorators.cache.cache_page"</p>

<p>well, my question could be not well explained or out of point.
Just let me know if you need to know more in detail or properly.</p>

<p>I hope there are some people have similar issues with Windows OS to deal with Redis and Django!</p>

<p>Thank you for reading!</p>

<p>You uninstalled the Python <code>redis</code> package thinking it was the Redis server but it's just a Python package with code to <em>access</em> Redis. You need to reinstall it. But you seem to have that part fixed.</p>

<p>As for using Redis with Django on Windows 10 the way you installed it, I would say it depends on what you want to do. If you just want to play around with it to learn, you should be fine. On the other hand, if you want to do some more serious development, I would install Redis another way. Here are a few possibilities I can think of:</p>

<ul>
<li>Installing Linux in a virtual machine with VirtualBox, VMWare or something like that, and install Redis in there;</li>
<li>Windows 10 now has the possibility of running Ubuntu Linux in it, so perhaps installing Redis there is the easiest option;</li>
<li>Use a Docker container to run Redis (use Docker for Windows: <a href="https://docs.docker.com/engine/getstarted/" rel="nofollow">https://docs.docker.com/engine/getstarted/</a> then you can get the Redis image from here: <a href="https://hub.docker.com/_/redis/" rel="nofollow">https://hub.docker.com/_/redis/</a>)</li>
</ul>

<p>Finally, regarding why the cache entries have those names, the default key Django cache creates for cache entries is defined <a href="https://github.com/django/django/blob/master/django/core/cache/backends/base.py#L27" rel="nofollow">here (django/core/cache/backends/base.py:27)</a>:</p>

<pre class="lang-python prettyprint-override"><code>def default_key_func(key, key_prefix, version):
    """
    Default function to generate keys.

    Constructs the key used by all other methods. By default it prepends
    the `key_prefix'. KEY_FUNCTION can be used to specify an alternate
    function with custom key making behavior.
    """
    return '%s:%s:%s' % (key_prefix, version, key)
</code></pre>

<p>In your case the key is <code>Test:1:views.decorators.cache.cache_page..GET.1be77f2243e36ea7e7fa68d85c1c277e.d41d8cd98f00b204e9800998ecf8427e.en-us.Korea_Standard_Time</code>, so that gives us the following breakdown:</p>

<pre><code>key_prefix = Test
version = 1
key = views.decorators.cache.cache_page..GET.1be77f2243e36ea7e7fa68d85c1c277e.d41d8cd98f00b204e9800998ecf8427e.en-us.Korea_Standard_Time
</code></pre>

<p>If you have a look in <a href="https://github.com/django/django/blob/master/django/views/decorators/cache.py#L10" rel="nofollow"><code>django/views/decorators/cache.py:10</code></a> you can see how the key part is composed. Specifically, this:</p>

<blockquote>
  <p>The cache is keyed by the URL and some data from the headers.</p>
</blockquote>

<p>The extra stuff you see there beyond what you were expecting is the headers data from the request.</p>

python django redis windows-10