import
sys
import
redis
import
exceptions
import
traceback
_hashtables
=
[]
_continue
=
True
_alllist
=
[]
class
RedisException(Exception):
def
__init__(
self
, errorlog):
self
.errorlog
=
errorlog
def
__str__(
self
):
return
"error log is %s"
%
(
self
.errorlog)
def
scan_one(cursor,conn):
try
:
cursor_v
=
conn.scan(cursor)
cursor_next
=
cursor_v[
0
]
cursor_value
=
cursor_v[
1
]
for
line
in
cursor_value:
if
(line.startswith(
"com-vip-storm"
)
or
line.startswith(
"stormdelay_"
)):
_hashtables.append(line)
else
:
pass
return
cursor_next
except
Exception,e:
raise
RedisException(
str
(e))
def
scan_all(conn):
try
:
cursor1
=
scan_one(
'0'
,conn)
global
_continue
while
_continue:
cursor2
=
scan_one(cursor1,conn)
if
int
(cursor2)
=
=
0
:
_continue
=
False
else
:
cursor1
=
cursor2
_continue
=
True
except
Exception,e:
raise
RedisException(
str
(e))
def
hget_fields(conn,hashname):
fields
=
conn.hkeys(hashname)
re
=
"["
for
field
in
fields:
aline
=
""
aline
+
=
%
(hashname,field)
_alllist.append(aline)
if
__name__
=
=
'__main__'
:
re
=
""
try
:
r
=
redis.StrictRedis(host
=
'xxx'
, port
=
xxx, db
=
0
)
scan_all(r)
for
hashtable
in
_hashtables:
hget_fields(r,hashtable)
re
+
=
re
+
=
str
(_alllist).replace(
,'"')
except
Exception,e:
print
-
1