我在StackExchange.Redis中遇到了Lua脚本的问题(请在下面找到)。 我已经解剖了代码,并且除了最后一个循环之外,它已经完成了所有工作。 我得到以下错误 - 错误协议错误:预期' $',得到' ' 错误消息本质上是非常通用的,因为它为不同类型的错误提供了相同的错误消息。 有人可以帮我解决问题吗?
var doesExist = (bool)db.ScriptEvaluate(@"
local function isDateInRange(DateStart, DateEnd, GivenDate)
if (GivenDate > DateStart and GivenDate < DateEnd)
then
return(true)
else
return(false)
end
end
--Fetch User's Category's StartDate and EndDate
local function IsCategoryDateValid()
local givenDate, DateStart, DateEnd
GivenDate = '2017-01-09'
StartDate = '2015-01-01'
EndDate = '2018-01-01'
local isDateValid
isDateValid = isDateInRange(StartDate, EndDate, GivenDate)
return(isDateValid)
end
-- Pass User, UserCategory and UserCategoryItem as parameters
local userNameKey = 'UserDetails:Invincible'
local userCategoryKey = 'UserCategories:Book'
local userCategoryItemKey = 'UserCategoryItems:Harry-Potter'
local userNameKeySplit = {}
local a = 1
for i in string.gmatch(userNameKey, '([^'..':'..']+)') do
userNameKeySplit[a] = i
a = a + 1
end
local userName = userNameKeySplit[2]
local userCategoryKeySplit = {}
local b = 1
for j in string.gmatch(userCategoryKey, '([^'..':'..']+)') do
userCategoryKeySplit[b] = j
b = b + 1
end
local userCategory = userCategoryKeySplit[2]
local userCategoryItemKeySplit = {}
local c = 1
for k in string.gmatch(userCategoryItemKey, '([^'..':'..']+)') do
userCategoryItemKeySplit[c] = k
c = c + 1
end
local userCategoryItem = userCategoryItemKeySplit[2]
-- Fetch Users, UserCategories and UserCategoryItems from the Redis DB
local userData = {'Invincible', 'User1', 'User2', 'User3'}
local userCategoryData = {'Book', 'Movie', 'Journals'}
local userCategoryItemData = {'Hardy-Boys', 'Harry-Potter', 'Shawshank-Redemption', 'The-Terminal'}
local msg
for i=1,#userData,1
do
if(userData[i] == userName)
then
for j=1,#userCategoryData,1
do
if(userCategoryData[j] == userCategory)
then
msg = true
break
else
msg = false
end
end
break
else
msg = false
break
end
end
return msg
",
new RedisKey[] { "UserDetails:" + "Invincible", "UserCategories:" + "Book", "UserCategoryItems:" + "Harry-Potter" });