Skip to content

Commit 70f3606

Browse files
justincastillaJustin Castilla
and
Justin Castilla
authored
Doc 2542 - Add code examples for the Geospatial tutorial (#2585)
* DOC-2542 Add code examples for the Geospatial tutorial * adds spaces after properties in objects --------- Co-authored-by: Justin Castilla <[email protected]>
1 parent 22f8b2f commit 70f3606

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

doctests/dt-geo.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// EXAMPLE: geo_tutorial
2+
// HIDE_START
3+
import assert from 'assert';
4+
import { createClient } from 'redis';
5+
6+
const client = createClient();
7+
await client.connect();
8+
// HIDE_END
9+
10+
// REMOVE_START
11+
await client.del('bikes:rentable')
12+
// REMOVE_END
13+
14+
// STEP_START geoAdd
15+
const res1 = await client.geoAdd('bikes:rentable', {
16+
longitude: -122.27652,
17+
latitude: 37.805186,
18+
member: 'station:1'
19+
});
20+
console.log(res1) // 1
21+
22+
const res2 = await client.geoAdd('bikes:rentable', {
23+
longitude: -122.2674626,
24+
latitude: 37.8062344,
25+
member: 'station:2'
26+
});
27+
console.log(res2) // 1
28+
29+
const res3 = await client.geoAdd('bikes:rentable', {
30+
longitude: -122.2469854,
31+
latitude: 37.8104049,
32+
member: 'station:3'
33+
})
34+
console.log(res3) // 1
35+
// STEP_END
36+
37+
// REMOVE_START
38+
assert.equal(res1, 1);
39+
assert.equal(res2, 1);
40+
assert.equal(res3, 1);
41+
// REMOVE_END
42+
43+
// STEP_START geoSearch
44+
const res4 = await client.geoSearch(
45+
'bikes:rentable', {
46+
longitude: -122.27652,
47+
latitude: 37.805186,
48+
},
49+
{ radius: 5,
50+
unit: 'km'
51+
}
52+
);
53+
console.log(res4) // ['station:1', 'station:2', 'station:3']
54+
// STEP_END
55+
56+
// REMOVE_START
57+
assert.deepEqual(res4, ['station:1', 'station:2', 'station:3']);
58+
// REMOVE_END
59+
await client.quit()

0 commit comments

Comments
 (0)