为什么我的Redis Python会在调用一次命令时多次插入值?

时间:2016-06-30 23:07:55

标签: python docker redis docker-compose redis-py

我正在尝试Redis,我不确定我的设置在哪里出错

当调用r.lpush()时我假设它会在我的列表中插入一个值并将列表延长一个但是当调用llen()时,每次运行此脚本时,长度会增加一个随机数量< / p>

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,但这是多次运行脚本后的输出

在: 1 后: 2

在: 五 后: 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 Dockerfile:

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"

0 个答案:

没有答案