|
35 | 35 | - [🔎 Rich Queries and Embedded Models](#-rich-queries-and-embedded-models)
|
36 | 36 | - [Querying](#querying)
|
37 | 37 | - [Embedded Models](#embedded-models)
|
| 38 | +- [Calling Other Redis Commands](#calling-other-redis-commands) |
38 | 39 | - [💻 Installation](#-installation)
|
39 | 40 | - [📚 Documentation](#-documentation)
|
40 | 41 | - [⛏️ Troubleshooting](#️-troubleshooting)
|
@@ -288,6 +289,38 @@ Customer.find(Customer.address.city == "San Antonio",
|
288 | 289 | Customer.address.state == "TX")
|
289 | 290 | ```
|
290 | 291 |
|
| 292 | +## Calling Other Redis Commands |
| 293 | + |
| 294 | +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: |
| 295 | + |
| 296 | +```python |
| 297 | +from redis_om import HashModel |
| 298 | + |
| 299 | +class Demo(HashModel): |
| 300 | + some_field: str |
| 301 | + |
| 302 | +redis_conn = Demo.db() |
| 303 | + |
| 304 | +redis_conn.sadd("myset", "a", "b", "c", "d") |
| 305 | + |
| 306 | +# Prints False |
| 307 | +print(redis_conn.sismember("myset", "e")) |
| 308 | + |
| 309 | +# Prints True |
| 310 | +print(redis_conn.sismember("myset", "b")) |
| 311 | +``` |
| 312 | + |
| 313 | +The parameters expected by each command function are those documented on the command's page on [redis.io](https://redis.io/commands/). |
| 314 | + |
| 315 | +If you don't want to get a Redis connection from a model class, you can also use `get_redis_connection`: |
| 316 | + |
| 317 | +```python |
| 318 | +from redis_om import get_redis_connection |
| 319 | + |
| 320 | +redis_conn = get_redis_conection() |
| 321 | +redis_conn.set("hello", "world") |
| 322 | +``` |
| 323 | + |
291 | 324 | ## 💻 Installation
|
292 | 325 |
|
293 | 326 | Installation is simple with `pip`, Poetry, or Pipenv.
|
|
0 commit comments