Skip to content

[pull] main from redis:main #5

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

Open
wants to merge 7 commits into
base: main
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
4 changes: 4 additions & 0 deletions .github/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ validator
validators
virtualenv
http
AMR
EntraID
entraid
metamodel
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
pyver: [ "3.9", "3.10", "3.11", "3.12", "pypy-3.9", "pypy-3.10" ]
pyver: [ "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.9", "pypy-3.10" ]
redisstack: [ "latest" ]
fail-fast: false
services:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@ tests_sync/
# spelling cruft
*.dic

.idea
.idea

# version files
.tool-versions
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,36 @@ You can run these modules in your self-hosted Redis deployment, or you can use [

To learn more, read [our documentation](docs/redis_modules.md).

## Connecting to Azure Managed Redis with EntraID

Once you have EntraID setup for your Azure Managed Redis (AMR) deployment, you can use Redis OM Python with it by leveraging the [redis-py-entraid](https://github.com/redis/redis-py-entraid) library.
Simply install the library with:

```
pip install redis-entraid
```

Then you'll initialize your credentials provider, connect to redis, and pass the database object into your metamodel:

```python

from redis import Redis
from redis_entraid.cred_provider import create_from_default_azure_credential
from redis_om import HashModel, Field
credential_provider = create_from_default_azure_credential(
("https://redis.azure.com/.default",),
)

db = Redis(host="cluster-name.region.redis.azure.net", port=10000, ssl=True, ssl_cert_reqs=None, credential_provider=credential_provider)
db.flushdb()
class User(HashModel):
first_name: str
last_name: str = Field(index=True)

class Meta:
database = db
```

## ❤️ Contributing

We'd love your contributions!
Expand Down
99 changes: 0 additions & 99 deletions aredis_om/_compat.py

This file was deleted.

1 change: 0 additions & 1 deletion aredis_om/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import lru_cache
from typing import List

from aredis_om.connections import get_redis_connection

Expand Down
7 changes: 5 additions & 2 deletions aredis_om/model/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
from types import GeneratorType
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union

from .._compat import ENCODERS_BY_TYPE, BaseModel
from pydantic import BaseModel
from pydantic.deprecated.json import ENCODERS_BY_TYPE
from pydantic_core import PydanticUndefined


SetIntStr = Set[Union[int, str]]
Expand Down Expand Up @@ -72,7 +74,7 @@ def jsonable_encoder(
encoder = getattr(obj.__config__, "json_encoders", {})
if custom_encoder:
encoder.update(custom_encoder)
obj_dict = obj.dict(
obj_dict = obj.model_dump(
include=include, # type: ignore # in Pydantic
exclude=exclude, # type: ignore # in Pydantic
by_alias=by_alias,
Expand Down Expand Up @@ -106,6 +108,7 @@ def jsonable_encoder(
or (not isinstance(key, str))
or (not key.startswith("_sa"))
)
and value is not PydanticUndefined
and (value is not None or not exclude_none)
and ((include and key in include) or not exclude or key not in exclude)
):
Expand Down
3 changes: 3 additions & 0 deletions aredis_om/model/migrations/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ async def detect_migrations(self):
continue

stored_hash = await conn.get(hash_key)
if isinstance(stored_hash, bytes):
stored_hash = stored_hash.decode("utf-8")

schema_out_of_date = current_hash != stored_hash

if schema_out_of_date:
Expand Down
Loading