Skip to content

Commit

Permalink
Merge pull request #57 from RedisInsight/main
Browse files Browse the repository at this point in the history
Releasing latest changes
  • Loading branch information
ViktarStarastsenka authored May 30, 2024
2 parents 12c17f8 + 3ea3450 commit ae98015
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 23 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ redis:[pipeline=8;mode=raw;results=single;]
```
### Links configuration

#### Reference other tutorials
You can reference other tutorial pages.
To do this, use the markdown syntax described below and specify the ID of the tutorial you want to link to:
```
[{text}](redisinsight:_?tutorialId={tutorialId})
```

For example:
```
[Create JSON Documents](redisinsight:_?tutorialId=ds-json-create)
```


#### Internal links
You can insert links that lead to a specific page inside Redis Insight. The syntax for these links is following:
```
Expand Down Expand Up @@ -242,7 +255,6 @@ The full list of pages:
| Functions | triggered-functions/functions |
| Settings | settings |


#### Create a free Cloud database link

Also, there is a possibility to insert link which opens Create Free Database dialog inside Redis Insight
Expand Down
27 changes: 27 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"initialIsOpen": true
},
"children": [
{
"type": "internal-link",
"id": "redis_use_cases",
"label": "Redis Use Cases",
"summary": "A collection of several common use cases for Redis.",
"args": {
"initialIsOpen": true,
"path": "/uc/intro.md"
}
},
{
"type": "group",
"id": "ds",
Expand Down Expand Up @@ -405,6 +415,15 @@
"initialIsOpen": false
},
"children": [
{
"type": "internal-link",
"id": "vss-intro",
"label": "Introduction",
"summary": "Understand how to use Redis as a vector database.",
"args": {
"path": "/vss/intro.md"
}
},
{
"type": "internal-link",
"id": "vss-vectors-basic",
Expand All @@ -420,6 +439,14 @@
"args": {
"path": "/vss/vectors-adv-hash.md"
}
},
{
"type": "internal-link",
"id": "vss-learn-more",
"label": "Learn more",
"args": {
"path": "/vss/learn-more.md"
}
}
]
}
Expand Down
139 changes: 139 additions & 0 deletions src/uc/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
**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.

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.

```redis-upload:[/uc/sample_data.txt] Upload Sample Data
```

### Matchmaking

Redis serves as a powerful document store that is well-suited for matchmaking use cases. For instance, consider a bike shop where you need to pair shoppers with bikes based on their preferences and budget.

You can store your bike inventory using the JSON data structure, where bikes have attributes such as type (e.g., mountain, road, electric), condition (new or used), price, etc.

```redis:[run_confirmation=true] Add a bike as JSON
// Add a bike as JSON
JSON.SET sample_bicycle:2048 $ '{
"model": "Ranger",
"brand": "TrailBlazer",
"price": 450,
"type": "Mountain",
"specs": {
"material": "carbon",
"weight": 12
},
"description": "The Ranger is designed for rugged trails and adventurous rides!",
"addons": [
"water bottle holder",
"rear rack"
],
"helmet_included": false
}'
```

In Redis, you can easily index these attributes and perform complex queries efficiently.

```redis:[run_confirmation=true] Create a bike index
// Create a secondary index of your bike data
FT.CREATE idx:smpl_bicycle
ON JSON
PREFIX 1 sample_bicycle:
SCHEMA
$.brand AS brand TEXT
$.model AS model TEXT
$.description AS description TEXT
$.price AS price NUMERIC
$.condition AS condition TAG SEPARATOR ,
$.type AS type TAG
$.helmet_included AS helmet_included TAG
$.specs.material AS material TAG
$.specs.weight AS weight NUMERIC
```

You can then easily match a user to their preferred type of bike within a requested price bracket.

```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
```

### Session store

Redis shines as a session store, offering speed and scalability for web applications. Using commands like HSET to store session data as hashes and HGET to retrieve it, Redis ensures rapid access to user sessions.

```redis:[run_confirmation=true] Create a session hash with expiration
// Store new session
HSET sample_session:074529275 user_id 7254 username gabe_jones email [email protected] last_activity "2024-06-01 10:24:00"
// Set an expiration time for the new session entry
EXPIRE sample_session:074529275 7344000
```

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

### Job queue

In many applications, tasks need to be processed asynchronously, such as maintaining a waiting list for a helpdesk where incoming support tickets are queued for processing. A job queue helps manage these tasks efficiently. In Redis, a [job queue](https://redis.io/glossary/redis-queue/) can be implemented using the List data structure. When a new task needs to be queued, it is added to the left end of the list (using the LPUSH command). When a worker is ready to process a task, it dequeues it from the right end of the list (using the RPOP command).


```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"
```
```redis:[run_confirmation=true] Enqueue job
// Enqueue the new job to the waiting list
LPUSH sample_jobQueue:waitingList sample_jobQueue:ticket:199
```
```redis:[run_confirmation=true] Show all jobs
// Show the full list of jobs
LRANGE sample_jobQueue:waitingList 0 -1
```
```redis:[run_confirmation=true] Dequeue a job
// Dequeue a job from the list
RPOP sample_jobQueue:waitingList
```

### Leaderboard

[Leaderboards](https://redis.io/solutions/leaderboards/) are crucial for gaming applications to display rankings based on scores. Sorted Sets in Redis are perfect for this purpose due to their ability to store elements with associated scores, which can be easily queried and sorted.

```redis:[run_confirmation=true] Create a leaderboard score
// Add a new score to leaderboard
ZADD sample_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
```
Loading

0 comments on commit ae98015

Please sign in to comment.