Skip to content

update uc #59

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

Merged
merged 2 commits into from
May 31, 2024
Merged
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
56 changes: 14 additions & 42 deletions src/uc/intro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Redis** is a powerful in-memory data structure store that can be used for various use cases due to its speed, simplicity, and versatility. In this tutorial, we'll explore several common use cases: matchmaking, location-based search, job queue, leaderboard, and session store.
**Redis** is a powerful in-memory data structure store that can be used for various use cases due to its speed, simplicity, and versatility. In this tutorial, we'll explore several common use cases: matchmaking, job queue, leaderboard, and session store.

If you haven't done so already, you can upload the sample data related to this tutorial by clicking the button below. You will also need support for [JSON](https://redis.io/docs/latest/develop/data-types/json/) and [Search & query](https://redis.io/docs/latest/develop/interact/search-and-query/) in your database to take advantage of this tutorial fully.

Expand All @@ -13,7 +13,7 @@ You can store your bike inventory using the JSON data structure, where bikes hav

```redis:[run_confirmation=true] Add a bike as JSON
// Add a bike as JSON
JSON.SET sample_bicycle:2048 $ '{
JSON.SET bicycle:2048 $ '{
"model": "Ranger",
"brand": "TrailBlazer",
"price": 450,
Expand All @@ -35,9 +35,9 @@ In Redis, you can easily index these attributes and perform complex queries effi

```redis:[run_confirmation=true] Create a bike index
// Create a secondary index of your bike data
FT.CREATE idx:smpl_bicycle
FT.CREATE idx:bicycle
ON JSON
PREFIX 1 sample_bicycle:
PREFIX 1 bicycle:
SCHEMA
$.brand AS brand TEXT
$.model AS model TEXT
Expand All @@ -54,35 +54,7 @@ You can then easily match a user to their preferred type of bike within a reques

```redis:[run_confirmation=true] Search for a match
// Match leisure bikes within a price of 200 and 300
FT.SEARCH idx:smpl_bicycle "@type:{mountain} @price:[400 450]" RETURN 4 brand model type price
```

### Location-based search

Location-based search involves finding and retrieving data that is relevant to a specific geographic location. Redis can be used to power location-based search applications by storing and indexing geospatial data, such as latitude and longitude coordinates, and providing fast and efficient search capabilities

```redis:[run_confirmation=true] Add a restaurant
// Add a restaurant as JSON
JSON.SET sample_restaurant:341 $ '{
"name": "Zen Galushca",
"cuisine": "Japanese",
"location": "-98.1221,30.8232"
}'
```
```redis:[run_confirmation=true] Create a restaurant index
//Create an index of your restaurant data
FT.CREATE "idx:smpl_restaurant"
ON JSON
PREFIX 1 "sample_restaurant:"
SCHEMA
"$.cuisine" AS "cuisine" TAG
"$.name" AS "restaurant_name" TEXT
"$.location" AS "location" GEO
```

```redis:[run_confirmation=true] Search for a restaurant
// Find a Japanese restaurant within a 50 mile radius
FT.SEARCH idx:smpl_restaurant "@cuisine:{japanese} @location:[-98.1179,30.671 50 mi]" RETURN 2 restaurant_name location
FT.SEARCH idx:bicycle "@type:{mountain} @price:[400 450]" RETURN 4 brand model type price
```

### Session store
Expand All @@ -91,15 +63,15 @@ Redis shines as a session store, offering speed and scalability for web applicat

```redis:[run_confirmation=true] Create a session hash with expiration
// Store new session
HSET sample_session:074529275 user_id 7254 username gabe_jones email gabe@example.com last_activity "2024-06-01 10:24:00"
HSET session:074529275 user_id 7254 username gabe_jones email gabe@example.com last_activity "2024-06-01 10:24:00"

// Set an expiration time for the new session entry
EXPIRE sample_session:074529275 7344000
EXPIRE session:074529275 7344000
```

```redis:[run_confirmation=true] Retrieve a session
// Retrieve an existing session
HGETALL sample_session:074529275
HGETALL session:074529275
```

### Job queue
Expand All @@ -109,19 +81,19 @@ In many applications, tasks need to be processed asynchronously, such as maintai

```redis:[run_confirmation=true] Create a job ticket
// Create a new job as a Hash
HSET sample_jobQueue:ticket:199 id 199 user_id 723 description "Unable to access console" priority "High" created_at "2024-04-20T12:00:00Z"
HSET jobQueue:ticket:199 id 199 user_id 723 description "Unable to access console" priority "High" created_at "2024-04-20T12:00:00Z"
```
```redis:[run_confirmation=true] Enqueue job
// Enqueue the new job to the waiting list
LPUSH sample_jobQueue:waitingList sample_jobQueue:ticket:199
LPUSH jobQueue:waitingList jobQueue:ticket:199
```
```redis:[run_confirmation=true] Show all jobs
// Show the full list of jobs
LRANGE sample_jobQueue:waitingList 0 -1
LRANGE jobQueue:waitingList 0 -1
```
```redis:[run_confirmation=true] Dequeue a job
// Dequeue a job from the list
RPOP sample_jobQueue:waitingList
RPOP jobQueue:waitingList
```

### Leaderboard
Expand All @@ -130,10 +102,10 @@ RPOP sample_jobQueue:waitingList

```redis:[run_confirmation=true] Create a leaderboard score
// Add a new score to leaderboard
ZADD sample_leaderboard:tetris 670000 "user100"
ZADD leaderboard:tetris 670000 "user100"
```

```redis:[run_confirmation=true] Get users with scores
// Get the top 5 users on the leaderboard, with scores
ZRANGE sample_leaderboard:tetris 0 4 REV WITHSCORES
ZRANGE leaderboard:tetris 0 4 REV WITHSCORES
```
Loading