zoukankan      html  css  js  c++  java
  • redis 主从

    redis主从:
    
    ```python
    # 进入桌面conf目录 创建两个配置文件, 内容如下:
    
    # redis.conf
    daemonize yes
    pidfile ./redis-server.pid
    port 6377
    bind 10.211.55.15
    
    
    # slave.conf
    daemonize yes
    pidfile ./redis-server-slave.pid
    port 6378
    bind 10.211.55.15
    slaveof 10.211.55.15 6377
    ```
    
    ```python
    # 启动 主/从 redis服务
    redis-server redis.conf
    redis-server slave.conf
    
    # 测试主从读写
    redis-cli -h 10.211.55.15 -p 6377
    set/get
    
    redis-cli -h 10.211.55.15 -p 6378
    get        # 无法set
    
    # django中使用:
    # 配置
    CACHES = {
        "write": {  # 主服务
            "BACKEND": "django_redis.cache.RedisCache",
            "LOCATION": "redis://10.211.55.15:6377/10",
            "OPTIONS": {
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
            }
        },
        "read": {  # 从服务
            "BACKEND": "django_redis.cache.RedisCache",
            "LOCATION": "redis://10.211.55.15:6378/10",
            "OPTIONS": {
                "CLIENT_CLASS": "django_redis.client.DefaultClient",
            }
        },
    }
    
    # 测试
    from django_redis import get_redis_connection
    w_client = get_redis_connection('write')
    r_client = get_redis_connection('read')
    ```
  • 相关阅读:
    day7 反射
    day7 面向对象进阶
    day7 面向对象class()学习
    day6 subprocess模块、logging模块
    day6 hashlib模块
    day6 ConfigParser模块 yaml模块
    day6 xml文件格式的处理
    day6 shelve模块
    day6 SYS模块
    Servlet的学习之Response响应对象(1)
  • 原文地址:https://www.cnblogs.com/mldsh/p/13624883.html
Copyright © 2011-2022 走看看