Redis download installation configuration test + Django operation Redis

Redis download installation configuration test + Django operation Redis

Download Redis

Go to the Redis official website and download the msi file.

insert image description here

Redis installation

Install Redis all the way by default.

insert image description here

Redis configuration

Edit the Redis.windows-service.conf file in the Redis installation directory.

insert image description here
Find #requirepass foobared.
insert image description here
Add a line below, for example my password is wxm520.

insert image description here
View bind.

insert image description here

Redis test

After modifying the password and other configurations, restart the redis service.
[Control Panel] –> [Administrative Tools] –> [Services]

insert image description here
Open cmd, run as administrator, and type the following command.

insert image description here

Django actions

pip install django-redis

insert image description here
Configure the redis database in settings.py.

CACHES = {
    "default": { # 默认
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/0",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
    "session": { # session
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
}
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "session"

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_43779149/article/details/123396189