Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_server_verison_after_client():
from iredis.config import config
Client("127.0.0.1", "6379", None)
assert config.version.startswith("5.")
config.version = "Unknown"
Client("127.0.0.1", "6379", None, get_info=False)
assert config.version == "Unknown"
def test_get_server_verison_after_client():
from iredis.config import config
Client("127.0.0.1", "6379", None)
assert config.version.startswith("5.")
config.version = "Unknown"
Client("127.0.0.1", "6379", None, get_info=False)
assert config.version == "Unknown"
def test_do_help():
from iredis.config import config
client = Client("127.0.0.1", "6379", None)
config.version = "5.0.0"
resp = client.do_help("SET")
assert resp[10] == ("", "1.0.0 (Avaiable on your redis-server: 5.0.0)")
config.version = "2.0.0"
resp = client.do_help("cluster", "addslots")
assert resp[10] == ("", "3.0.0 (Not avaiable on your redis-server: 2.0.0)")
def test_do_help():
from iredis.config import config
client = Client("127.0.0.1", "6379", None)
config.version = "5.0.0"
resp = client.do_help("SET")
assert resp[10] == ("", "1.0.0 (Avaiable on your redis-server: 5.0.0)")
config.version = "2.0.0"
resp = client.do_help("cluster", "addslots")
assert resp[10] == ("", "3.0.0 (Not avaiable on your redis-server: 2.0.0)")
def test_get_server_verison_after_client():
from iredis.config import config
Client("127.0.0.1", "6379", None)
assert config.version.startswith("5.")
config.version = "Unknown"
Client("127.0.0.1", "6379", None, get_info=False)
assert config.version == "Unknown"
try:
doc_file = open(
project_path / "redis-doc" / "commands" / f"{command_docs_name}.md"
)
except FileNotFoundError:
raise NotRedisCommand(
f"{command_summary_name} is not a valide Redis command."
)
with doc_file as doc_file:
doc = doc_file.read()
rendered_detail = markdown.render(doc)
summary_dict = commands_summary[command_summary_name]
avaiable_version = summary_dict.get("since", "?")
server_version = config.version
# FIXME anything strange with single quotes?
logger.debug(f"[--version--] '{server_version}'")
try:
is_avaiable = StrictVersion(server_version) > StrictVersion(
avaiable_version
)
except Exception as e:
logger.exception(e)
is_avaiable = None
if is_avaiable:
avaiable_text = f"(Avaiable on your redis-server: {server_version})"
elif is_avaiable is False:
avaiable_text = f"(Not avaiable on your redis-server: {server_version})"
else:
avaiable_text = ""
def greetings():
iredis_version = f"iredis {__version__}"
if config.no_version_reason:
reason = f"({config.no_version_reason})"
else:
reason = ""
server_version = f"redis-server {config.version} {reason}"
home_page = "Home: https://iredis.io"
issues = "Issues: https://iredis.io/issues"
display = "\n".join([iredis_version, server_version, home_page, issues])
write_result(display)
def get_server_info(self):
self.connection.send_command("INFO")
# safe to decode Redis's INFO response
info_resp = utils.ensure_str(self.connection.read_response())
version = re.findall(r"^redis_version:([\d\.]+)\r\n", info_resp, re.MULTILINE)[
0
]
logger.debug(f"[Redis Version] {version}")
config.version = version
def render_slowlog(raw, completers=None):
if config.raw:
return _render_raw_list(raw)
fields = ["Slow log id", "Start at", "Running time(ms)", "Command"]
if StrictVersion(config.version) > StrictVersion("4.0"):
fields.extend(["Client IP and port", "Client name"])
rendered = []
text = _ensure_str(raw)
index_width = len(str(len(text)))
for index, slowlog in enumerate(text):
index_str = f"{index+1:{index_width}}) "
rendered.append(("", index_str))
for field, value in zip(fields, slowlog):
if field == "Command":
value = " ".join(value)
if field != "Slow log id":
display_field = " " * len(index_str) + field
else:
display_field = field
logger.debug(f"field: {field}, value: {value}")