码迷,mamicode.com
首页 > 其他好文 > 详细

路飞-Redis

时间:2019-11-12 20:34:27      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:tcl   def   集合   字符   header   数据   python   core   tor   

redis数据库

# 1.安装redis与可视化操作工具

# 2.在服务中管理redis服务器的开启关闭

# 3.命令行简单使用redis:
    -- redis-cli  # 启动客户端
    -- set key value  # 设置值
    -- get key  # 取出值
    
# 4.redis支持:字符串、字典、列表、集合、有序集合
# https://www.runoob.com/redis/redis-tutorial.html

# 5.特点:可持久化、单线程单进程并发

python使用redis

依赖
>: pip3 install redis
直接使用
import redis
r = redis.Redis(host='127.0.0.1', port=6379)
连接池使用
import redis
pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
r = redis.Redis(connection_pool=pool)
缓存使用:要额外安装 django-redis
# 1.将缓存存储位置配置到redis中:settings.py
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "CONNECTION_POOL_KWARGS": {"max_connections": 100}
        }
    }
}

# 2.操作cache模块直接操作缓存:views.py
from django.core.cache import cache  # 结合配置文件实现插拔式
# 存放token,可以直接设置过期时间
cache.set('token', 'header.payload.signature', 10)
# 取出token
token = cache.get('token')

路飞-Redis

标签:tcl   def   集合   字符   header   数据   python   core   tor   

原文地址:https://www.cnblogs.com/DcentMan/p/11844608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!