def keys(self, pattern='*'):
"""Emulate keys."""
import fnmatch
import re
# making sure the pattern is unicode/str.
try:
pattern = pattern.decode('utf-8')
# This throws an AttributeError in python 3, or an
# UnicodeEncodeError in python 2
except (AttributeError, UnicodeEncodeError):
pass
# Make regex out of glob styled pattern.
regex = fnmatch.translate(pattern)
regex = re.compile(regex)
# Find every key that matches the pattern
return [key for key in self.redis.keys() if regex.match(key.decode('utf-8'))]
评论列表
文章目录