From: antirez Date: Sat, 28 Mar 2009 10:50:27 +0000 (+0100) Subject: redis-sha1 utility added X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/8de4907a86e25ac8a50be57f5c2a80f872017e77 redis-sha1 utility added --- diff --git a/utils/redis-sha1.rb b/utils/redis-sha1.rb new file mode 100644 index 00000000..54d34dea --- /dev/null +++ b/utils/redis-sha1.rb @@ -0,0 +1,32 @@ +# redis-sha1.rb - Copyright (C) 2009 Salvatore Sanfilippo +# BSD license, See the COPYING file for more information. +# +# Performs the SHA1 sum of the whole datset. +# This is useful to spot bugs in persistence related code and to make sure +# Slaves and Masters are in SYNC. +# +# If you hack this code make sure to sort keys and set elements as this are +# unsorted elements. Otherwise the sum may differ with equal dataset. + +require 'rubygems' +require 'redis' +require 'digest/sha1' + +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" + sha1 = Digest::SHA1.hexdigest(sha1+r.get(k)) + elsif vtype == "list" + sha1 = Digest::SHA1.hexdigest(sha1+r.list_range(k,0,-1).join("\x01")) + elsif vtype == "set" + sha1 = Digest::SHA1.hexdigest(sha1+r.set_members(k).to_a.sort.join("\x02")) + end + } + sha1 +end + +p "Dataset SHA1: #{redisSha1()}"