20
20
TextField ,
21
21
VectorField ,
22
22
)
23
- from redis .commands .search .indexDefinition import IndexDefinition , IndexType
23
+ from redis .commands .search .index_definition import IndexDefinition , IndexType
24
24
from redis .commands .search .query import GeoFilter , NumericFilter , Query
25
25
from redis .commands .search .result import Result
26
26
from redis .commands .search .suggestion import Suggestion
30
30
is_resp2_connection ,
31
31
skip_if_redis_enterprise ,
32
32
skip_if_resp_version ,
33
+ skip_if_server_version_gte ,
33
34
skip_if_server_version_lt ,
34
35
skip_ifmodversion_lt ,
35
36
)
@@ -1007,6 +1008,7 @@ def test_get(client):
1007
1008
@pytest .mark .redismod
1008
1009
@pytest .mark .onlynoncluster
1009
1010
@skip_ifmodversion_lt ("2.2.0" , "search" )
1011
+ @skip_if_server_version_gte ("7.9.0" )
1010
1012
def test_config (client ):
1011
1013
assert client .ft ().config_set ("TIMEOUT" , "100" )
1012
1014
with pytest .raises (redis .ResponseError ):
@@ -1017,6 +1019,19 @@ def test_config(client):
1017
1019
assert "100" == res ["TIMEOUT" ]
1018
1020
1019
1021
1022
+ @pytest .mark .redismod
1023
+ @pytest .mark .onlynoncluster
1024
+ @skip_if_server_version_lt ("7.9.0" )
1025
+ def test_config_with_removed_ftconfig (client ):
1026
+ assert client .config_set ("timeout" , "100" )
1027
+ with pytest .raises (redis .ResponseError ):
1028
+ client .config_set ("timeout" , "null" )
1029
+ res = client .config_get ("*" )
1030
+ assert "100" == res ["timeout" ]
1031
+ res = client .config_get ("timeout" )
1032
+ assert "100" == res ["timeout" ]
1033
+
1034
+
1020
1035
@pytest .mark .redismod
1021
1036
@pytest .mark .onlynoncluster
1022
1037
def test_aggregations_groupby (client ):
@@ -1571,6 +1586,7 @@ def test_index_definition(client):
1571
1586
@pytest .mark .redismod
1572
1587
@pytest .mark .onlynoncluster
1573
1588
@skip_if_redis_enterprise ()
1589
+ @skip_if_server_version_gte ("7.9.0" )
1574
1590
def test_expire (client ):
1575
1591
client .ft ().create_index ((TextField ("txt" , sortable = True ),), temporary = 4 )
1576
1592
ttl = client .execute_command ("ft.debug" , "TTL" , "idx" )
@@ -2025,6 +2041,8 @@ def test_json_with_jsonpath(client):
2025
2041
@pytest .mark .redismod
2026
2042
@pytest .mark .onlynoncluster
2027
2043
@skip_if_redis_enterprise ()
2044
+ @skip_if_server_version_gte ("7.9.0" )
2045
+ @skip_if_server_version_lt ("6.3.0" )
2028
2046
def test_profile (client ):
2029
2047
client .ft ().create_index ((TextField ("t" ),))
2030
2048
client .ft ().client .hset ("1" , "t" , "hello" )
@@ -2034,10 +2052,9 @@ def test_profile(client):
2034
2052
q = Query ("hello|world" ).no_content ()
2035
2053
if is_resp2_connection (client ):
2036
2054
res , det = client .ft ().profile (q )
2037
- assert det ["Iterators profile" ]["Counter" ] == 2.0
2038
- assert len (det ["Iterators profile" ]["Child iterators" ]) == 2
2039
- assert det ["Iterators profile" ]["Type" ] == "UNION"
2040
- assert det ["Parsing time" ] < 0.5
2055
+ det = det .info
2056
+
2057
+ assert isinstance (det , list )
2041
2058
assert len (res .docs ) == 2 # check also the search result
2042
2059
2043
2060
# check using AggregateRequest
@@ -2047,15 +2064,14 @@ def test_profile(client):
2047
2064
.apply (prefix = "startswith(@t, 'hel')" )
2048
2065
)
2049
2066
res , det = client .ft ().profile (req )
2050
- assert det ["Iterators profile" ]["Counter" ] == 2
2051
- assert det ["Iterators profile" ]["Type" ] == "WILDCARD"
2052
- assert isinstance (det ["Parsing time" ], float )
2067
+ det = det .info
2068
+ assert isinstance (det , list )
2053
2069
assert len (res .rows ) == 2 # check also the search result
2054
2070
else :
2055
2071
res = client .ft ().profile (q )
2056
- assert res [ "profile" ][ "Iterators profile" ][ 0 ][ "Counter" ] == 2.0
2057
- assert res [ "profile" ][ "Iterators profile" ][ 0 ][ "Type" ] == "UNION"
2058
- assert res [ "profile" ][ "Parsing time" ] < 0.5
2072
+ res = res . info
2073
+
2074
+ assert isinstance ( res , dict )
2059
2075
assert len (res ["results" ]) == 2 # check also the search result
2060
2076
2061
2077
# check using AggregateRequest
@@ -2065,14 +2081,97 @@ def test_profile(client):
2065
2081
.apply (prefix = "startswith(@t, 'hel')" )
2066
2082
)
2067
2083
res = client .ft ().profile (req )
2068
- assert res [ "profile" ][ "Iterators profile" ][ 0 ][ "Counter" ] == 2
2069
- assert res [ "profile" ][ "Iterators profile" ][ 0 ][ "Type" ] == "WILDCARD"
2070
- assert isinstance (res [ "profile" ][ "Parsing time" ], float )
2084
+ res = res . info
2085
+
2086
+ assert isinstance (res , dict )
2071
2087
assert len (res ["results" ]) == 2 # check also the search result
2072
2088
2073
2089
2074
2090
@pytest .mark .redismod
2075
2091
@pytest .mark .onlynoncluster
2092
+ @skip_if_redis_enterprise ()
2093
+ @skip_if_server_version_lt ("7.9.0" )
2094
+ def test_profile_with_coordinator (client ):
2095
+ client .ft ().create_index ((TextField ("t" ),))
2096
+ client .ft ().client .hset ("1" , "t" , "hello" )
2097
+ client .ft ().client .hset ("2" , "t" , "world" )
2098
+
2099
+ # check using Query
2100
+ q = Query ("hello|world" ).no_content ()
2101
+ if is_resp2_connection (client ):
2102
+ res , det = client .ft ().profile (q )
2103
+ det = det .info
2104
+
2105
+ assert isinstance (det , list )
2106
+ assert len (res .docs ) == 2 # check also the search result
2107
+
2108
+ # check using AggregateRequest
2109
+ req = (
2110
+ aggregations .AggregateRequest ("*" )
2111
+ .load ("t" )
2112
+ .apply (prefix = "startswith(@t, 'hel')" )
2113
+ )
2114
+ res , det = client .ft ().profile (req )
2115
+ det = det .info
2116
+
2117
+ assert isinstance (det , list )
2118
+ assert det [0 ] == "Shards"
2119
+ assert det [2 ] == "Coordinator"
2120
+ assert len (res .rows ) == 2 # check also the search result
2121
+ else :
2122
+ res = client .ft ().profile (q )
2123
+ res = res .info
2124
+
2125
+ assert isinstance (res , dict )
2126
+ assert len (res ["Results" ]["results" ]) == 2 # check also the search result
2127
+
2128
+ # check using AggregateRequest
2129
+ req = (
2130
+ aggregations .AggregateRequest ("*" )
2131
+ .load ("t" )
2132
+ .apply (prefix = "startswith(@t, 'hel')" )
2133
+ )
2134
+ res = client .ft ().profile (req )
2135
+ res = res .info
2136
+
2137
+ assert isinstance (res , dict )
2138
+ assert len (res ["Results" ]["results" ]) == 2 # check also the search result
2139
+
2140
+
2141
+ @pytest .mark .redismod
2142
+ @pytest .mark .onlynoncluster
2143
+ @skip_if_redis_enterprise ()
2144
+ @skip_if_server_version_gte ("6.3.0" )
2145
+ def test_profile_with_no_warnings (client ):
2146
+ client .ft ().create_index ((TextField ("t" ),))
2147
+ client .ft ().client .hset ("1" , "t" , "hello" )
2148
+ client .ft ().client .hset ("2" , "t" , "world" )
2149
+
2150
+ # check using Query
2151
+ q = Query ("hello|world" ).no_content ()
2152
+ res , det = client .ft ().profile (q )
2153
+ det = det .info
2154
+
2155
+ assert isinstance (det , list )
2156
+ assert len (res .docs ) == 2 # check also the search result
2157
+
2158
+ # check using AggregateRequest
2159
+ req = (
2160
+ aggregations .AggregateRequest ("*" )
2161
+ .load ("t" )
2162
+ .apply (prefix = "startswith(@t, 'hel')" )
2163
+ )
2164
+ res , det = client .ft ().profile (req )
2165
+ det = det .info
2166
+
2167
+ assert isinstance (det , list )
2168
+ assert len (res .rows ) == 2 # check also the search result
2169
+
2170
+
2171
+ @pytest .mark .redismod
2172
+ @pytest .mark .onlynoncluster
2173
+ @skip_if_server_version_gte ("7.9.0" )
2174
+ @skip_if_server_version_lt ("6.3.0" )
2076
2175
def test_profile_limited (client ):
2077
2176
client .ft ().create_index ((TextField ("t" ),))
2078
2177
client .ft ().client .hset ("1" , "t" , "hello" )
@@ -2083,18 +2182,14 @@ def test_profile_limited(client):
2083
2182
q = Query ("%hell% hel*" )
2084
2183
if is_resp2_connection (client ):
2085
2184
res , det = client .ft ().profile (q , limited = True )
2086
- assert (
2087
- det ["Iterators profile" ]["Child iterators" ][0 ]["Child iterators" ]
2088
- == "The number of iterators in the union is 3"
2089
- )
2090
- assert (
2091
- det ["Iterators profile" ]["Child iterators" ][1 ]["Child iterators" ]
2092
- == "The number of iterators in the union is 4"
2093
- )
2094
- assert det ["Iterators profile" ]["Type" ] == "INTERSECT"
2185
+ det = det .info
2186
+ assert det [4 ][1 ][7 ][9 ] == "The number of iterators in the union is 3"
2187
+ assert det [4 ][1 ][8 ][9 ] == "The number of iterators in the union is 4"
2188
+ assert det [4 ][1 ][1 ] == "INTERSECT"
2095
2189
assert len (res .docs ) == 3 # check also the search result
2096
2190
else :
2097
2191
res = client .ft ().profile (q , limited = True )
2192
+ res = res .info
2098
2193
iterators_profile = res ["profile" ]["Iterators profile" ]
2099
2194
assert (
2100
2195
iterators_profile [0 ]["Child iterators" ][0 ]["Child iterators" ]
@@ -2110,6 +2205,8 @@ def test_profile_limited(client):
2110
2205
2111
2206
@pytest .mark .redismod
2112
2207
@skip_ifmodversion_lt ("2.4.3" , "search" )
2208
+ @skip_if_server_version_gte ("7.9.0" )
2209
+ @skip_if_server_version_lt ("6.3.0" )
2113
2210
def test_profile_query_params (client ):
2114
2211
client .ft ().create_index (
2115
2212
(
@@ -2125,13 +2222,15 @@ def test_profile_query_params(client):
2125
2222
q = Query (query ).return_field ("__v_score" ).sort_by ("__v_score" , True )
2126
2223
if is_resp2_connection (client ):
2127
2224
res , det = client .ft ().profile (q , query_params = {"vec" : "aaaaaaaa" })
2128
- assert det ["Iterators profile" ]["Counter" ] == 2.0
2129
- assert det ["Iterators profile" ]["Type" ] == "VECTOR"
2225
+ det = det .info
2226
+ assert det [4 ][1 ][5 ] == 2.0
2227
+ assert det [4 ][1 ][1 ] == "VECTOR"
2130
2228
assert res .total == 2
2131
2229
assert "a" == res .docs [0 ].id
2132
2230
assert "0" == res .docs [0 ].__getattribute__ ("__v_score" )
2133
2231
else :
2134
2232
res = client .ft ().profile (q , query_params = {"vec" : "aaaaaaaa" })
2233
+ res = res .info
2135
2234
assert res ["profile" ]["Iterators profile" ][0 ]["Counter" ] == 2
2136
2235
assert res ["profile" ]["Iterators profile" ][0 ]["Type" ] == "VECTOR"
2137
2236
assert res ["total_results" ] == 2
0 commit comments