Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Georedis promised #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Other bonuses:
npm install --save georedis
```

Note: A promise-based wrapper is available via `npm install --save georedis-promised`. The API is identical, but promises are used instead of callbacks.

## Basic Usage
Usage of this module should be extremely simple. Just make sure that your Redis server is accessible to your Node environment. Because this module uses Redis as a store, almost all methods have integrated error handling for queries.

Expand Down
38 changes: 38 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { RedisClient } from 'redis'
export type Point = {
latitude: number
longitude: number
}

export type GeoCallback<TReply> = (err: Error, reply: TReply) => void

export type NearbyOptions = {
withCoordinates: boolean // Will provide coordinates with locations, default false
withHashes: boolean // Will provide a 52bit Geohash Integer, default false
withDistances: boolean // Will provide distance from query, default false
order: 'ASC' | 'DESC' // or 'DESC' or true (same as 'ASC'), default false
units: 'm' | 'km' | 'mi' | 'ft' // or 'km', 'mi', 'ft', default 'm'
count: number // Number of results to return, default undefined
accurate: boolean // Useful if in emulated mode and accuracy is important, default false
}

export type GeoRedis = {
delete(callback?: (err: Error) => void): void
removeLocations(
locationNames: string[],
callback?: GeoCallback<boolean>
): void
addLocation(
locationName: string,
position: Point,
callback?: GeoCallback<boolean>
): void
nearby(
locationName: string,
radius: number,
options?: NearbyOptions,
callback?: GeoCallback<string[]>
): void
}

export function initialize(client: RedisClient): GeoRedis
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"url": "https://github.com/arjunmehta/node-georedis"
},
"dependencies": {
"@types/redis": "^2.8.28",
"geolib": "2.0.24",
"ngeohash": "0.6.3"
},
Expand Down