Skip to content

Commit 8a5db64

Browse files
author
Andrew Brookins
committed
WIP on getting started guide
1 parent 807a29b commit 8a5db64

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

docs/getting_started.md

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Windows users can also use Docker. See the next section on running Redis with Do
3737

3838
### Running Redis With Docker
3939

40-
Instead of installing Redis manually or with a package manager, you can run Redis with Docker. The official Redis Docker image is hosted on [Docker Hub](https://hub.docker.com/_/redis).
40+
Instead of installing Redis manually or with a package manager, you can run Redis with Docker. The official Redis Docker image is hosted on [Docker Hub](https://hub.docker.com/_/redis).
4141

4242
**TIP:** If you plan on using Docker, we recommend the [redismod](https://hub.docker.com/r/redislabs/redismod) image because it includes the RediSearch and RedisJSON modules.
4343

@@ -51,10 +51,9 @@ The easiest way to run these Redis modules during local development is to use th
5151

5252
You can quickly start Redis with the redismod Docker image by running the following command:
5353

54-
docker run -d -p 6379:6379 redislabs/redismod
55-
54+
docker run -d -p 6379:6379 redislabs/redismod
5655
**TIP:** The `-d` option runs Redis in the background.
57-
56+
5857
For other installation methods, follow the "Quick Start" guides on both modules' home pages for alternative installation methods.
5958

6059
## Start Redis
@@ -67,41 +66,38 @@ The command you use to start Redis will depend on how you installed it.
6766

6867
If you installed Redis using `apt`, start it with the `systemctl` command:
6968

70-
sudo systemctl restart redis.service
71-
69+
sudo systemctl restart redis.service
7270
Otherwise, you can start the server manually:
7371

74-
redis-server start
72+
redis-server start
7573

7674
### macOS with Homebrew
77-
78-
brew services start redis
79-
75+
76+
brew services start redis
77+
8078
### Docker
8179

8280
The command to start Redis with Docker depends on the image you've chosen to use.
8381

8482
#### Docker with the redismod image (recommended)
8583

86-
docker run -d -p 6379:6379 redislabs/redismod
84+
docker run -d -p 6379:6379 redislabs/redismod
8785

8886
### Docker iwth the redis image
8987

90-
docker run -d -p 6379:6379 redis
88+
docker run -d -p 6379:6379 redis
9189

9290
## Installing Redis OM
9391

9492
You can install Redis OM with `pip` by running the following command:
9593

96-
pip install redis-om
97-
94+
pip install redis-om
9895
Or, if you're using Poetry, you can install Redis OM with the following command:
9996

100-
poetry install redis-om
101-
97+
poetry install redis-om
10298
With Pipenv, the command is:
10399

104-
pipenv install redis-om
100+
pipenv install redis-om
105101

106102
## Setting the Redis URL Environment Variable
107103

@@ -113,19 +109,16 @@ However, if you configured Redis to run on a different port, or if you're using
113109

114110
The `REDIS_URL` environment variable follows the redis-py URL format:
115111

116-
redis://[[username]:[password]]@localhost:6379/[database number]
117-
112+
redis://[[username]:[password]]@localhost:6379/[database number]
118113
The default connection is eqivalent to the following `REDIS_URL` environment variable:
119114

120-
redis://@localhost:6379
121-
115+
redis://@localhost:6379
122116
**TIP:** Redis databases are numbered, and the default is 0. You can leave off the database number to use the default database.
123-
117+
124118
Other supported prefixes include "rediss" for SSL connections and "unix" for Unix domain sockets:
125119

126-
rediss://[[username]:[password]]@localhost:6379/0
127-
unix://[[username]:[password]]@/path/to/socket.sock?db=0
128-
120+
rediss://[[username]:[password]]@localhost:6379/0
121+
unix://[[username]:[password]]@/path/to/socket.sock?db=0
129122
For more details about how to connect to Redis with Redis OM, see the [connections documentation](connections.md).
130123

131124
### Redis Cluster Support
@@ -134,7 +127,7 @@ Redis OM supports connecting to Redis Cluster, but this preview release does not
134127

135128
See the [connections documentation](connections.md) for examples of connecting to Redis Cluster.
136129

137-
Support for connecting to Redis Cluster via `REDIS_URL` will be added in a future release.
130+
Support for connecting to Redis Cluster via `REDIS_URL` will be added in a future release.
138131

139132
## Defining a Model
140133

@@ -167,7 +160,7 @@ Let's dig into these two details a bit more.
167160

168161
### The HashModel Class
169162

170-
When you subclass `HashModel`, your subclass is both a Redis OM model, with methods for saving data to Redis, *and* a Pydantic model.
163+
When you subclass `HashModel`, your subclass is both a Redis OM model, with methods for saving data to Redis, *and* a Pydantic model.
171164

172165
This means that you can use Pydantic field validations with your Redis OM models, which we'll cover later, when we talk about validation. But this also means you can use Redis OM models anywhere you would use a Pydantic model, like in your FastAPI applications. 🤯
173166

@@ -231,7 +224,7 @@ class Customer(HashModel):
231224
join_date: datetime.date
232225
age: int
233226
bio: Optional[str]
234-
```
227+
```
235228

236229
Now we can create `Customer` objects with or without the `bio` field.
237230

@@ -247,7 +240,7 @@ class Customer(HashModel):
247240
join_date: datetime.date
248241
age: int
249242
bio: Optional[str] = "Super dope"
250-
```
243+
```
251244

252245
Now, if we create a `Customer` object without a `bio` field, it will use the default value.
253246

@@ -258,13 +251,34 @@ andrew = Customer(
258251
259252
join_date=datetime.date.today(),
260253
age=38)
261-
254+
262255
print(andrew.bio)
263256
'Super Dope'
264257
```
265258

259+
The model will then save this default value to Redis the next time you call `save()`.
260+
261+
### Automatic Primary Keys
262+
263+
Models generate a globally unique primary key automatically without needing to talk to Redis.
264+
265+
```python
266+
print(andrew.pk)
267+
'01FJM6PH661HCNNRC884H6K30C'
268+
```
269+
270+
The ID is available *before* you save the model.
271+
272+
The default ID generation function creates [ULIDs](https://github.com/ulid/spec), though you can change the function that generates the primary key for models if you'd like to use a different kind of primary key.
273+
266274
## Saving Models
267275

276+
We can save the model to Redis by calling `save()`:
277+
278+
```python
279+
andrew.save()
280+
```
281+
268282
## Examining Your Data In Redis
269283

270284
## Validating Data
@@ -274,5 +288,6 @@ print(andrew.bio)
274288
Now that you know the basics of working with Redis OM, continue on for all the nitty-gritty details about [models and fields](validation.md).
275289

276290
<!-- Links -->
291+
277292
[redisearch-url]: https://oss.redis.com/redisearch/
278293
[redis-json-url]: https://oss.redis.com/redisjson/

0 commit comments

Comments
 (0)