더가 내장되지-에 명령 그것을 위해 - 옵션은 두 목록을 끌어와 클라이언트에서 (차이에 대한) 비교를 수행하거나 EVAL
명령으로 실행되는 루아 스크립트를 작성할 수 있습니다 중 그것을 서버 측에서 수행하십시오.
--[[
LDIFF key [key ...]
Returns the elements in the first list key that are also present in all other
keys.
]]--
-- A utility function that converts an array to a table
local function a2t(a)
local t = {}
for i, v in ipairs(a) do
t[v] = true
end
return t
end
-- A utility function that converts a table to an array
local function t2a(t)
local a = {}
for k, _ in pairs(t) do
a[#a+1] = k
end
return a
end
-- main
local key = table.remove(KEYS,1)
local elems = a2t(redis.call('LRANGE', key, 0, -1))
-- iterate remaining keys
while #KEYS > 0 do
key = table.remove(KEYS,1)
local check = a2t(redis.call('LRANGE', key, 0, -1))
-- check each element in the current key for existence in the first key
for k, _ in pairs(elems) do
if check[k] then
elems[k] = nil
end
end
end
-- convert the table to an array and reply
return t2a(elems)
redis-cli
이것을 실행 다음과 같습니다 : 다음은 이러한 스크립트의 예입니다
$ redis-cli LPUSH key1 value1 value2 value3
(integer) 3
$ redis-cli LPUSH key2 value1 value3 value4
(integer) 3
$ redis-cli --eval ldiff.lua key1 key2
1) "value2"