我有以下REDIS SET:
127.0.0.1:6379[2]> hgetall available
1) "00001"
2) "unassigned"
3) "00002"
4) "unassigned"
5) "00003"
6) "unassigned"
7) "00004"
8) "unassigned"
9) "00005"
10) "unassigned"
127.0.0.1:6379[2]>
我有以下python代码,该代码使用管道将帐户从可用列表“移动”到保留列表/集:
def reserve_mailboxes(lower, upper):
try:
assert(lower is not None)
assert(upper is not None)
if DEBUG == True: print("reserve_mailboxes invoked with lower limit: " + str(lower) + ", upper limit: " + str(upper))
for number in range(int(lower), int(upper) + 1):
number = '{0:05d}'.format(number) #zero pad
r = redis.Redis(connection_pool=POOL)
p = r.pipeline()
p.hmset('reserved', {number:'reserved'})
p.hdel('available', {number})
response = p.execute()
logging.info(response)
if not response[1] == True:
if DEBUG == True: logging.info(response)
return True
except Exception as e:
logging.error(e)
return False
如果您查看我在其中创建和执行管道的代码,则hdel命令实际上存在语法错误。确实应该是:
p.hdel('available', number)
但是,当我运行此代码时,它将继续并向“保留”列表中添加2个条目...但不会将它们从可用列表中删除。这是我现在的数据:
127.0.0.1:6379[2]> hgetall reserved
1) "00003"
2) "reserved"
3) "00004"
4) "reserved"
127.0.0.1:6379[2]> hgetall available
1) "00001"
2) "unassigned"
3) "00002"
4) "unassigned"
5) "00003"
6) "unassigned"
7) "00004"
8) "unassigned"
9) "00005"
10) "unassigned"
该日志显示两个命令的以下“响应” /结果:
root-INFO-[True,0]
如果hdel有效,则应返回1而不是0。
顺便说一句。当我删除错字时,代码会正确地从一个列表中删除,并添加到另一个列表中。
问题