Skip to content

Instantly share code, notes, and snippets.

@Jd007
Created February 5, 2013 00:10
Show Gist options
  • Save Jd007/4710980 to your computer and use it in GitHub Desktop.
Save Jd007/4710980 to your computer and use it in GitHub Desktop.
def get_geo_hash_redis_result(coord_ui, precision, cache_key, redis_db):
UNSIGNED_BIGINT_MAX = 18446744073709551615
redis_pipe = redis_db.pipeline()
for hilo in geohash.expand_uint64(coord_ui, precision):
if hilo[0] and hilo[1]:
redis_pipe.zrangebyscore(cache_key, hilo[0], (hilo[1] - 1), start=None, num=None, withscores=True, score_cast_func=lambda score : long(float(score)))
elif hilo[0]:
redis_pipe.zrangebyscore(cache_key, hilo[0], UNSIGNED_BIGINT_MAX, start=None, num=None, withscores=True, score_cast_func=lambda score : long(float(score)))
elif hilo[1]:
redis_pipe.zrangebyscore(cache_key, 0, (hilo[1] - 1), start=None, num=None, withscores=True, score_cast_func=lambda score : long(float(score)))
results = redis_pipe.execute()
result_list = []
for result in results:
result_list += result
return list(set(result_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment