Skip to content

Commit 4251f12

Browse files
authored
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
1 parent 5d69ec7 commit 4251f12

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

doctests/dt_geo.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# EXAMPLE: geo_tutorial
2+
# HIDE_START
3+
import redis
4+
5+
r = redis.Redis(decode_responses=True)
6+
# HIDE_END
7+
# REMOVE_START
8+
r.delete("bikes:rentable")
9+
# REMOVE_END
10+
11+
# STEP_START geoadd
12+
res1 = r.geoadd("bikes:rentable", [-122.27652, 37.805186, "station:1"])
13+
print(res1) # >>> 1
14+
15+
res2 = r.geoadd("bikes:rentable", [-122.2674626, 37.8062344, "station:2"])
16+
print(res2) # >>> 1
17+
18+
res3 = r.geoadd("bikes:rentable", [-122.2469854, 37.8104049, "station:3"])
19+
print(res3) # >>> 1
20+
# STEP_END
21+
22+
# REMOVE_START
23+
assert res1 == 1
24+
assert res2 == 1
25+
assert res3 == 1
26+
# REMOVE_END
27+
28+
# STEP_START geosearch
29+
res4 = r.geosearch(
30+
"bikes:rentable",
31+
longitude=-122.27652,
32+
latitude=37.805186,
33+
radius=5,
34+
unit="km",
35+
)
36+
print(res4) # >>> ['station:1', 'station:2', 'station:3']
37+
# STEP_END
38+
39+
# REMOVE_START
40+
assert res4 == ["station:1", "station:2", "station:3"]
41+
# REMOVE_END

0 commit comments

Comments
 (0)