我正在尝试 Redis,但我不确定我的设置哪里出了问题
当r.lpush()
被调用时,我假设它会在我的列表中插入一个值并将列表加长,但是当llen()
被调用时,每次运行此脚本时长度都会随机增加
import redis
class RedisConnection:
def __init__(self):
config = {
'host': 'redis',
'port': 6379,
}
self.client = redis.Redis(**config)
def getClient(self):
return self.client
r = RedisConnection().getClient()
r.rpush("lst1", 6)
print r.llen("lst1")
每次我运行脚本时,列表的长度都会增加任意数量
编辑:所以在检查了之前的长度和之后的长度之后,它增加了一,但这是多次运行脚本后的输出
之前:1 之后:2
之前:5 之后:6
之前:16 之后:17
不确定是什么导致每次跑步后跳跃
编辑:redis MONITOR 命令的输出
这是上述脚本仅运行一次后的输出。该rpush("lst1", 6)
命令反复运行了很多次,我认为这与我的 Docker 配置有关
我的 Docker 配置是:
app:
restart: always
build: ./app/
expose:
- "8000"
links:
- redis:redis
volumes:
- ./app:/usr/src/app
env_file: .env
command: /usr/local/bin/gunicorn mytestapp.wsgi:application -w 2 -b :8000
redis:
restart: always
build: ./redis/
expose:
- "6379"
volumes:
- redisdata:/data
Redis Docker 文件:
FROM redis:latest
我试过有restart:always
和没有它的redis
Redis 监视器输出:
root@e2343dec33da: redis-cli -h redis MONITOR
OK
1467344153.562365 [0 172.17.0.16:35002] "RPUSH" "lst1" "6"
1467344153.563107 [0 172.17.0.16:35002] "LLEN" "lst1"
1467344154.281957 [0 172.17.0.16:35004] "RPUSH" "lst1" "6"
1467344154.282407 [0 172.17.0.16:35004] "LLEN" "lst1"
1467344155.072393 [0 172.17.0.16:35006] "RPUSH" "lst1" "6"
1467344155.073077 [0 172.17.0.16:35006] "LLEN" "lst1"
1467344156.081633 [0 172.17.0.16:35008] "RPUSH" "lst1" "6"
1467344156.082258 [0 172.17.0.16:35008] "LLEN" "lst1"
1467344156.329652 [0 172.17.0.15:43952] "RPUSH" "lst1" "6"
1467344156.330195 [0 172.17.0.15:43952] "LLEN" "lst1"
1467344157.494998 [0 172.17.0.16:35012] "RPUSH" "lst1" "6"
1467344157.495581 [0 172.17.0.16:35012] "LLEN" "lst1"
1467344159.675782 [0 172.17.0.16:35014] "RPUSH" "lst1" "6"
1467344159.677411 [0 172.17.0.16:35014] "LLEN" "lst1"
1467344163.432896 [0 172.17.0.16:35016] "RPUSH" "lst1" "6"
1467344163.433910 [0 172.17.0.16:35016] "LLEN" "lst1"
1467344169.653969 [0 172.17.0.15:43960] "RPUSH" "lst1" "6"
1467344169.654669 [0 172.17.0.15:43960] "LLEN" "lst1"
1467344170.446384 [0 172.17.0.16:35020] "RPUSH" "lst1" "6"
1467344170.447025 [0 172.17.0.16:35020] "LLEN" "lst1"
1467344172.540838 [0 172.17.0.14:44806] "RPUSH" "lst1" "6"
1467344172.541958 [0 172.17.0.14:44806] "LLEN" "lst1"
1467344183.797716 [0 172.17.0.16:35024] "RPUSH" "lst1" "6"
1467344183.798663 [0 172.17.0.16:35024] "LLEN" "lst1"
1467344195.843937 [0 172.17.0.15:43968] "RPUSH" "lst1" "6"
1467344195.844140 [0 172.17.0.15:43968] "LLEN" "lst1"
1467344209.951857 [0 172.17.0.16:35028] "RPUSH" "lst1" "6"
1467344209.952459 [0 172.17.0.16:35028] "LLEN" "lst1"
1467344224.430525 [0 172.17.0.14:44814] "RPUSH" "lst1" "6"
1467344224.430922 [0 172.17.0.14:44814] "LLEN" "lst1"
1467344247.764961 [0 172.17.0.15:43974] "RPUSH" "lst1" "6"
1467344247.766123 [0 172.17.0.15:43974] "LLEN" "lst1"
1467344261.729253 [0 172.17.0.16:35034] "RPUSH" "lst1" "6"
1467344261.729680 [0 172.17.0.16:35034] "LLEN" "lst1"
1467344284.244204 [0 172.17.0.13:49524] "RPUSH" "lst1" "6"
1467344284.245552 [0 172.17.0.13:49524] "LLEN" "lst1"
1467344327.393265 [0 172.17.0.14:44822] "RPUSH" "lst1" "6"
1467344327.394594 [0 172.17.0.14:44822] "LLEN" "lst1"
1467344350.752738 [0 172.17.0.15:43982] "RPUSH" "lst1" "6"
1467344350.753683 [0 172.17.0.15:43982] "LLEN" "lst1"
1467344365.029118 [0 172.17.0.16:35042] "RPUSH" "lst1" "6"
1467344365.029599 [0 172.17.0.16:35042] "LLEN" "lst1"