From 4251f123fcb1f5e2a07b314d24472103ebd47ac2 Mon Sep 17 00:00:00 2001 From: Savannah Date: Fri, 21 Jul 2023 08:54:25 -0400 Subject: [PATCH] Create dt_geo.py (#2858) * Create dt_geo.py creating python code snippets for the geospatial data type page * Update dt_geo.py update for linter * Update dt_geo.py local lint of `black --line-length 80 dt_geo.py` passes * add remove keywords remove the cleanup code from ever being visible to the user * add newline for linter --- doctests/dt_geo.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 doctests/dt_geo.py 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