fix(tests): check for RediSearch module availability in Redis tests (#6687)
This commit is contained in:
@@ -249,9 +249,23 @@ REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
|
|||||||
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
|
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
|
||||||
|
|
||||||
|
|
||||||
|
def _redis_search_available(host, port, timeout=2):
|
||||||
|
"""RediSearch (the FT.* command family) is an optional module, not part of vanilla Redis."""
|
||||||
|
if not _tcp_reachable(host, port, timeout=timeout):
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
import redis
|
||||||
|
|
||||||
|
client = redis.Redis(host=host, port=port, socket_connect_timeout=timeout, socket_timeout=timeout)
|
||||||
|
modules = {m["name"].lower() for m in client.module_list()}
|
||||||
|
return "search" in modules
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
not _tcp_reachable(REDIS_HOST, REDIS_PORT),
|
not _redis_search_available(REDIS_HOST, REDIS_PORT),
|
||||||
reason=f"Redis not reachable at {REDIS_HOST}:{REDIS_PORT}",
|
reason=f"RediSearch module not available at {REDIS_HOST}:{REDIS_PORT} (requires Redis Stack, not vanilla Redis)",
|
||||||
)
|
)
|
||||||
class TestRedisThreshold:
|
class TestRedisThreshold:
|
||||||
def test_threshold_filtering(self):
|
def test_threshold_filtering(self):
|
||||||
|
|||||||
@@ -239,9 +239,23 @@ REDIS_HOST = os.environ.get("REDIS_HOST", "localhost")
|
|||||||
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
|
REDIS_PORT = int(os.environ.get("REDIS_PORT", "6379"))
|
||||||
|
|
||||||
|
|
||||||
|
def _redis_search_available(host, port, timeout=2):
|
||||||
|
"""RediSearch (the FT.* command family) is an optional module, not part of vanilla Redis."""
|
||||||
|
if not _tcp_reachable(host, port, timeout=timeout):
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
import redis
|
||||||
|
|
||||||
|
client = redis.Redis(host=host, port=port, socket_connect_timeout=timeout, socket_timeout=timeout)
|
||||||
|
modules = {m["name"].lower() for m in client.module_list()}
|
||||||
|
return "search" in modules
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
not _tcp_reachable(REDIS_HOST, REDIS_PORT),
|
not _redis_search_available(REDIS_HOST, REDIS_PORT),
|
||||||
reason=f"Redis not reachable at {REDIS_HOST}:{REDIS_PORT}",
|
reason=f"RediSearch module not available at {REDIS_HOST}:{REDIS_PORT} (requires Redis Stack, not vanilla Redis)",
|
||||||
)
|
)
|
||||||
class TestRedis:
|
class TestRedis:
|
||||||
"""Redis returns cosine distance [0,2]. Conversion: score = max(0, 1 - dist)."""
|
"""Redis returns cosine distance [0,2]. Conversion: score = max(0, 1 - dist)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user