0

我试过了,ioredis但 HSCAN 只支持一个匹配模式。

从redis过滤多个模式的最佳方法是什么

var stream = redis.hscanStream('myhash', {
    match: `foo*`,
    count: 10
})

stream.on('data', function(resultKeys) {
    // add 
})

stream.on('end', function() {
    // end
})
4

1 回答 1

0

我最终为此使用了 Lua 脚本

仅使用 val ; 我不需要钥匙,因此if j % 2 == 0

local arr = {}
local len = redis.call('hlen', KEYS[1])
for i=1,#ARGV do
    local match = redis.call('hscan', KEYS[1], 0, 'match', ARGV[i], 'count', len)
    for j=1, #match[2] do
        if j % 2 == 0 then
            table.insert(arr, match[2][j])
        end
    end
end
return arr
于 2017-04-20T07:57:36.410 回答