mirror of
https://github.com/fluencelabs/redis
synced 2025-06-13 01:01:22 +00:00
some change to redis-sha1.rb utility to make it more robust against non-meaningful changes in the dataset
This commit is contained in:
@ -16,17 +16,31 @@ def redisSha1(opts={})
|
||||
sha1=""
|
||||
r = Redis.new(opts)
|
||||
r.keys('*').sort.each{|k|
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+k)
|
||||
vtype = r.type?(k)
|
||||
if vtype == "string"
|
||||
len = 1
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+k)
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.get(k))
|
||||
elsif vtype == "list"
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.list_range(k,0,-1).join("\x01"))
|
||||
len = r.llen(k)
|
||||
if len != 0
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+k)
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.list_range(k,0,-1).join("\x01"))
|
||||
end
|
||||
elsif vtype == "set"
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.set_members(k).to_a.sort.join("\x02"))
|
||||
len = r.scard(k)
|
||||
if len != 0
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+k)
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.set_members(k).to_a.sort.join("\x02"))
|
||||
end
|
||||
elsif vtype == "zset"
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.zrange(k,0,-1).join("\x01"))
|
||||
len = r.zcard(k)
|
||||
if len != 0
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+k)
|
||||
sha1 = Digest::SHA1.hexdigest(sha1+r.zrange(k,0,-1).join("\x01"))
|
||||
end
|
||||
end
|
||||
# puts "#{k} => #{sha1}" if len != 0
|
||||
}
|
||||
sha1
|
||||
end
|
||||
|
Reference in New Issue
Block a user