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')
    ```
  • 相关阅读:
    Binary Tree Maximum Path Sum
    ZigZag Conversion
    Longest Common Prefix
    Reverse Linked List II
    Populating Next Right Pointers in Each Node
    Populating Next Right Pointers in Each Node II
    Rotate List
    Path Sum II
    [Leetcode]-- Gray Code
    Subsets II
  • 原文地址:https://www.cnblogs.com/mldsh/p/13624883.html
Copyright © 2011-2022 走看看