diff --git a/doctests/dt_geo.py b/doctests/dt_geo.py new file mode 100644 index 0000000000..d7de084158 --- /dev/null +++ b/doctests/dt_geo.py @@ -0,0 +1,41 @@ +# EXAMPLE: geo_tutorial +# HIDE_START +import redis + +r = redis.Redis(decode_responses=True) +# HIDE_END +# REMOVE_START +r.delete("bikes:rentable") +# REMOVE_END + +# STEP_START geoadd +res1 = r.geoadd("bikes:rentable", [-122.27652, 37.805186, "station:1"]) +print(res1) # >>> 1 + +res2 = r.geoadd("bikes:rentable", [-122.2674626, 37.8062344, "station:2"]) +print(res2) # >>> 1 + +res3 = r.geoadd("bikes:rentable", [-122.2469854, 37.8104049, "station:3"]) +print(res3) # >>> 1 +# STEP_END + +# REMOVE_START +assert res1 == 1 +assert res2 == 1 +assert res3 == 1 +# REMOVE_END + +# STEP_START geosearch +res4 = r.geosearch( + "bikes:rentable", + longitude=-122.27652, + latitude=37.805186, + radius=5, + unit="km", +) +print(res4) # >>> ['station:1', 'station:2', 'station:3'] +# STEP_END + +# REMOVE_START +assert res4 == ["station:1", "station:2", "station:3"] +# REMOVE_END