如何从Tarantool中的随机元组或数组中获取哈希值?

我有一个函数(random_typle),它的参数是一个随机元组,那么我如何从元组的所有字段中获取哈希值? 我可以使用类似tuple:bsize()的东西,还是应该遍历所有字段并计算哈希值?

点赞
用户11592715
用户11592715

Tarantool 内置了 digest 模块,其中包含了一系列哈希函数。下面是一个示例函数,用于计算元组的 crc32 哈希值。

local digest = require('digest')
local function calc_hash(tuple)
    local crc32 = digest.crc32.new()
    for _, v in ipairs(tuple) do
        crc32:update(tostring(v))
    end
    return crc32:result()
end
2020-11-22 09:10:31