Skip to content

Commit 421f281

Browse files
author
Boris
committed
修复阿里云redis集群调用Lua脚本报错的问题
1 parent b64a2c8 commit 421f281

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

feapder/core/scheduler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,18 @@ def check_task_status(self):
332332
else:
333333
# 判断时间间隔是否超过20分钟
334334
lua = """
335-
local key = KEYS[1]
335+
-- local key = KEYS[1]
336336
local field = ARGV[1]
337337
local current_timestamp = ARGV[2]
338338
339339
-- 取值
340-
local last_timestamp = redis.call('hget', key, field)
340+
local last_timestamp = redis.call('hget', KEYS[1], field)
341341
if last_timestamp and current_timestamp - last_timestamp >= 1200 then
342342
return current_timestamp - last_timestamp -- 返回任务停滞时间 秒
343343
end
344344
345345
if not last_timestamp then
346-
redis.call('hset', key, field, current_timestamp)
346+
redis.call('hset', KEYS[1], field, current_timestamp)
347347
end
348348
349349
return 0

feapder/db/redisdb.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def zrangebyscore(self, table, priority_min, priority_max, count=None, is_pop=Tr
325325

326326
# 使用lua脚本, 保证操作的原子性
327327
lua = """
328-
local key = KEYS[1]
328+
-- local key = KEYS[1]
329329
local min_score = ARGV[2]
330330
local max_score = ARGV[3]
331331
local is_pop = ARGV[4]
@@ -334,15 +334,15 @@ def zrangebyscore(self, table, priority_min, priority_max, count=None, is_pop=Tr
334334
-- 取值
335335
local datas = nil
336336
if count then
337-
datas = redis.call('zrangebyscore', key, min_score, max_score, 'limit', 0, count)
337+
datas = redis.call('zrangebyscore', KEYS[1], min_score, max_score, 'limit', 0, count)
338338
else
339-
datas = redis.call('zrangebyscore', key, min_score, max_score)
339+
datas = redis.call('zrangebyscore', KEYS[1], min_score, max_score)
340340
end
341341
342342
-- 删除redis中刚取到的值
343343
if (is_pop) then
344344
for i=1, #datas do
345-
redis.call('zrem', key, datas[i])
345+
redis.call('zrem', KEYS[1], datas[i])
346346
end
347347
end
348348
@@ -377,7 +377,7 @@ def zrangebyscore_increase_score(
377377

378378
# 使用lua脚本, 保证操作的原子性
379379
lua = """
380-
local key = KEYS[1]
380+
-- local key = KEYS[1]
381381
local min_score = ARGV[1]
382382
local max_score = ARGV[2]
383383
local increase_score = ARGV[3]
@@ -386,14 +386,14 @@ def zrangebyscore_increase_score(
386386
-- 取值
387387
local datas = nil
388388
if count then
389-
datas = redis.call('zrangebyscore', key, min_score, max_score, 'limit', 0, count)
389+
datas = redis.call('zrangebyscore', KEYS[1], min_score, max_score, 'limit', 0, count)
390390
else
391-
datas = redis.call('zrangebyscore', key, min_score, max_score)
391+
datas = redis.call('zrangebyscore', KEYS[1], min_score, max_score)
392392
end
393393
394394
--修改优先级
395395
for i=1, #datas do
396-
redis.call('zincrby', key, increase_score, datas[i])
396+
redis.call('zincrby', KEYS[1], increase_score, datas[i])
397397
end
398398
399399
return datas
@@ -426,7 +426,7 @@ def zrangebyscore_set_score(
426426

427427
# 使用lua脚本, 保证操作的原子性
428428
lua = """
429-
local key = KEYS[1]
429+
-- local key = KEYS[1]
430430
local min_score = ARGV[1]
431431
local max_score = ARGV[2]
432432
local set_score = ARGV[3]
@@ -435,9 +435,9 @@ def zrangebyscore_set_score(
435435
-- 取值
436436
local datas = nil
437437
if count then
438-
datas = redis.call('zrangebyscore', key, min_score, max_score, 'withscores','limit', 0, count)
438+
datas = redis.call('zrangebyscore', KEYS[1], min_score, max_score, 'withscores','limit', 0, count)
439439
else
440-
datas = redis.call('zrangebyscore', key, min_score, max_score, 'withscores')
440+
datas = redis.call('zrangebyscore', KEYS[1], min_score, max_score, 'withscores')
441441
end
442442
443443
local real_datas = {} -- 数据
@@ -448,7 +448,7 @@ def zrangebyscore_set_score(
448448
449449
table.insert(real_datas, data) -- 添加数据
450450
451-
redis.call('zincrby', key, set_score - score, datas[i])
451+
redis.call('zincrby', KEYS[1], set_score - score, datas[i])
452452
end
453453
454454
return real_datas
@@ -641,13 +641,13 @@ def hget(self, table, key, is_pop=False):
641641
return self._redis.hget(table, key)
642642
else:
643643
lua = """
644-
local key = KEYS[1]
644+
-- local key = KEYS[1]
645645
local field = ARGV[1]
646646
647647
-- 取值
648-
local datas = redis.call('hget', key, field)
648+
local datas = redis.call('hget', KEYS[1], field)
649649
-- 删除值
650-
redis.call('hdel', key, field)
650+
redis.call('hdel', KEYS[1], field)
651651
652652
return datas
653653

tests/spider/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ def debug_spider_test():
4646
function=debug_spider_test,
4747
)
4848

49-
parser.start()
49+
parser.start()

0 commit comments

Comments
 (0)