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') ```