]> git.saurik.com Git - redis.git/blobdiff - utils/redis-sha1.rb
"SORT by nosort" (skip sorting) respect sorted set ordering.
[redis.git] / utils / redis-sha1.rb
index 6f9e045b4630e64f82d7a5ec8355aedb9b9400a0..24498e25a545ac6784191a8baf68f0ec4e012915 100644 (file)
@@ -16,20 +16,37 @@ def redisSha1(opts={})
     sha1=""
     r = Redis.new(opts)
     r.keys('*').sort.each{|k|
     sha1=""
     r = Redis.new(opts)
     r.keys('*').sort.each{|k|
-        sha1 = Digest::SHA1.hexdigest(sha1+k)
         vtype = r.type?(k)
         if vtype == "string"
         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.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"
         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"
+            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
         end
+        # puts "#{k} => #{sha1}" if len != 0
     }
     sha1
 end
 
 host = ARGV[0] || "127.0.0.1"
 port = ARGV[1] || "6379"
     }
     sha1
 end
 
 host = ARGV[0] || "127.0.0.1"
 port = ARGV[1] || "6379"
-puts "Performing SHA1 of Redis server #{host} #{port}"
-p "Dataset SHA1: #{redisSha1(:host => host, :port => port.to_i)}"
+db = ARGV[2] || "0"
+puts "Performing SHA1 of Redis server #{host} #{port} DB: #{db}"
+p "Dataset SHA1: #{redisSha1(:host => host, :port => port.to_i, :db => db)}"