-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add smismember implementation and test * add georadius_ro test * rm geo return type alias * georadiusbymember and georadiusbymember_ro tests * add geosearch tests * add geosearchstore tests * add placeholder for acl functions * add script refactoring and tests * remove pubsub from commands * bump version * run black formatter
- Loading branch information
1 parent
ebd3ca4
commit a3aed79
Showing
136 changed files
with
2,199 additions
and
1,461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "upstash_redis" | ||
version = "0.13.3" | ||
version = "0.14.0" | ||
description = "Serverless Redis Sdk from Upstash" | ||
authors = ["Upstash <[email protected]>", "Zgîmbău Tudor <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from upstash_redis.asyncio import Redis | ||
redis = Redis.from_env(allow_telemetry=False) | ||
|
||
|
||
redis = Redis.from_env(allow_telemetry=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
from pytest import mark, raises | ||
from tests.async_client import redis | ||
|
||
|
||
@mark.asyncio | ||
async def test() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", longitude=15, latitude=37, radius=200, unit="KM" | ||
) == ["Palermo", "Catania"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_distance() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", | ||
longitude=15, | ||
latitude=37, | ||
radius=200, | ||
unit="KM", | ||
withdist=True, | ||
) == [ | ||
{"member": "Palermo", "distance": 190.4424}, | ||
{"member": "Catania", "distance": 56.4413}, | ||
] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_hash() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", | ||
longitude=15, | ||
latitude=37, | ||
radius=200, | ||
unit="KM", | ||
withhash=True, | ||
) == [ | ||
{"member": "Palermo", "hash": 3479099956230698}, | ||
{"member": "Catania", "hash": 3479447370796909}, | ||
] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_coordinates() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", | ||
longitude=15, | ||
latitude=37, | ||
radius=200, | ||
unit="KM", | ||
withcoord=True, | ||
) == [ | ||
{ | ||
"member": "Palermo", | ||
"longitude": 13.361389338970184, | ||
"latitude": 38.115556395496299, | ||
}, | ||
{ | ||
"member": "Catania", | ||
"longitude": 15.087267458438873, | ||
"latitude": 37.50266842333162, | ||
}, | ||
] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_count() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", longitude=15, latitude=37, radius=200, unit="KM", count=1 | ||
) == ["Catania"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_any() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", | ||
longitude=15, | ||
latitude=37, | ||
radius=200, | ||
unit="KM", | ||
count=1, | ||
count_any=True, | ||
) == ["Palermo"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_sort() -> None: | ||
async with redis: | ||
assert await redis.georadius_ro( | ||
"test_geo_index", | ||
longitude=15, | ||
latitude=37, | ||
radius=200, | ||
unit="KM", | ||
sort="ASC", | ||
) == ["Catania", "Palermo"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_invalid_parameters() -> None: | ||
async with redis: | ||
with raises(Exception) as exception: | ||
await redis.georadius_ro( | ||
"test_geo_index", | ||
longitude=15, | ||
latitude=37, | ||
radius=200, | ||
unit="KM", | ||
count=None, | ||
count_any=True, | ||
) | ||
|
||
assert ( | ||
str(exception.value) | ||
== '"count_any" can only be used together with "count".' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
from pytest import mark, raises | ||
from tests.async_client import redis | ||
|
||
|
||
@mark.asyncio | ||
async def test() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", "Catania", 200, "KM" | ||
) == ["Palermo", "Catania"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_distance() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
withdist=True, | ||
) == [ | ||
{"member": "Palermo", "distance": 166.2742}, | ||
{"member": "Catania", "distance": 0.0}, | ||
] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_hash() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
withhash=True, | ||
) == [ | ||
{"member": "Palermo", "hash": 3479099956230698}, | ||
{"member": "Catania", "hash": 3479447370796909}, | ||
] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_coordinates() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
withcoord=True, | ||
) == [ | ||
{ | ||
"member": "Palermo", | ||
"longitude": 13.3613893389701841, | ||
"latitude": 38.115556395496299, | ||
}, | ||
{ | ||
"member": "Catania", | ||
"longitude": 15.087267458438873, | ||
"latitude": 37.50266842333162, | ||
}, | ||
] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_count() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", "Catania", 200, unit="KM", count=1 | ||
) == ["Catania"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_any() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
count=1, | ||
count_any=True, | ||
) == ["Palermo"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_sort() -> None: | ||
async with redis: | ||
assert await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
sort="ASC", | ||
) == ["Catania", "Palermo"] | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_store() -> None: | ||
async with redis: | ||
assert ( | ||
await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
store="test_geo_store", | ||
) | ||
== 2 | ||
) | ||
assert await redis.zcard("test_geo_store") == 2 | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_store_dist() -> None: | ||
async with redis: | ||
assert ( | ||
await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
100, | ||
unit="KM", | ||
storedist="test_geo_store_dist", | ||
) | ||
== 1 | ||
) | ||
assert await redis.zcard("test_geo_store_dist") == 1 | ||
|
||
|
||
@mark.asyncio | ||
async def test_with_invalid_parameters() -> None: | ||
async with redis: | ||
with raises(Exception) as exception: | ||
await redis.georadiusbymember( | ||
"test_geo_index", | ||
"Catania", | ||
200, | ||
unit="KM", | ||
count=None, | ||
count_any=True, | ||
) | ||
|
||
assert ( | ||
str(exception.value) | ||
== '"count_any" can only be used together with "count".' | ||
) |
Oops, something went wrong.