Added documention for accessing low level client.

This commit is contained in:
Simon Prickett 2022-03-29 20:21:54 +01:00
parent 8a8c94fb5f
commit 1e8ba35f08
2 changed files with 65 additions and 0 deletions

View file

@ -35,6 +35,7 @@ span
- [🔎 Rich Queries and Embedded Models](#-rich-queries-and-embedded-models)
- [Querying](#querying)
- [Embedded Models](#embedded-models)
- [Calling Other Redis Commands](#-calling-other-redis-commands)
- [💻 Installation](#-installation)
- [📚 Documentation](#-documentation)
- [⛏️ Troubleshooting](#-troubleshooting)
@ -288,6 +289,38 @@ Customer.find(Customer.address.city == "San Antonio",
Customer.address.state == "TX")
```
## Calling Other Redis Commands
Sometimes you'll need to run a Redis command directly. Redis OM supports this through the `db` method on your model's class. This returns a connected Redis client instance which exposes a function named for each Redis command. For example, let's perform some basic set operations:
```python
from redis_om import HashModel
class Demo(HashModel):
some_field: str
redis_conn = Demo.db()
redis_conn.sadd("myset", "a", "b", "c", "d")
# Prints False
print(redis_conn.sismember("myset", "e"))
# Prints True
print(redis_conn.sismember("myset", "b"))
```
The parameters expected by each command function are those documented on the command's page on [redis.io](https://redis.io/commands/).
If you don't want to get a Redis connection from a model class, you can also use `get_redis_connection`:
```python
from redis_om import get_redis_connection
redis_conn = get_redis_conection()
redis_conn.set("hello", "world")
```
## 💻 Installation
Installation is simple with `pip`, Poetry, or Pipenv.

View file

@ -693,6 +693,38 @@ Customer.find((Customer.last_name == "Brookins") | (
) & (Customer.last_name == "Smith")).all()
```
## Calling Other Redis Commands
Sometimes you'll need to run a Redis command directly. Redis OM supports this through the `db` method on your model's class. This returns a connected Redis client instance which exposes a function named for each Redis command. For example, let's perform some basic set operations:
```python
from redis_om import HashModel
class Demo(HashModel):
some_field: str
redis_conn = Demo.db()
redis_conn.sadd("myset", "a", "b", "c", "d")
# Prints False
print(redis_conn.sismember("myset", "e"))
# Prints True
print(redis_conn.sismember("myset", "b"))
```
The parameters expected by each command function are those documented on the command's page on [redis.io](https://redis.io/commands/).
If you don't want to get a Redis connection from a model class, you can also use `get_redis_connection`:
```python
from redis_om import get_redis_connection
redis_conn = get_redis_conection()
redis_conn.set("hello", "world")
```
## Next Steps
Now that you know the basics of working with Redis OM, start playing around with it in your project!