Skip to content

Add support for custom Redis username #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions rma/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ def ptransform(nm):
return rt


def connect_to_redis(host, port, db=0, password=None, ssl=False):
def connect_to_redis(host, port, db=0, username=None, password=None, ssl=False):
"""

:param host:
:param port:
:param db:
:param username:
:param password:
:return RmaRedis:
"""
try:
redis = RmaRedis(host=host, port=port, db=db, password=password, ssl=ssl)
redis = RmaRedis(host=host, port=port, db=db, username=username, password=password, ssl=ssl)
if not check_redis_version(redis):
sys.stderr.write('This script only works with Redis Server version 2.6.x or higher\n')
sys.exit(-1)
Expand Down Expand Up @@ -79,13 +80,13 @@ class RmaApplication(object):
REDIS_TYPE_ID_ZSET: [],
}

def __init__(self, host="127.0.0.1", port=6367, password=None, db=0, ssl=False, match="*", limit=0, filters=None, logger=None, format="text", separator=":"):
def __init__(self, host="127.0.0.1", port=6367, username=None, password=None, db=0, ssl=False, match="*", limit=0, filters=None, logger=None, format="text", separator=":"):
self.logger = logger or logging.getLogger(__name__)

self.splitter = SimpleSplitter(separator)
self.isTextFormat = format == "text"
self.reporter = TextReporter() if self.isTextFormat else JsonReporter()
self.redis = connect_to_redis(host=host, port=port, db=db, password=password, ssl=ssl)
self.redis = connect_to_redis(host=host, port=port, db=db, username=username, password=password, ssl=ssl)

self.match = match
self.limit = limit if limit != 0 else sys.maxsize
Expand Down
5 changes: 4 additions & 1 deletion rma/cli/rma_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def main():
default=6379,
type=int,
help="Redis Server port. Defaults to 6379")
parser.add_argument("-u", "--username",
dest="username",
help="Username to use when connecting to the server")
parser.add_argument("-a", "--password",
dest="password",
help="Password to use when connecting to the server")
Expand Down Expand Up @@ -101,7 +104,7 @@ def main():
else:
filters['types'].append(x)

app = RmaApplication(host=options.host, port=options.port, db=options.db, password=options.password,
app = RmaApplication(host=options.host, port=options.port, db=options.db, username=options.username, password=options.password,
ssl=options.ssl, match=options.match, limit=options.limit, filters=filters, format=options.format,
separator=options.separator)

Expand Down