Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
8de4907a
Commit
8de4907a
authored
Mar 28, 2009
by
antirez
Browse files
redis-sha1 utility added
parent
e3566d4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/redis-sha1.rb
0 → 100644
View file @
8de4907a
# 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
()
}
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment