Simple App for Shorten your URL and using Redis as the main databases.
- Non Login - Home Page
- Login - Home Page
- URL List - By Users
- Edit URL
Here's a short video that explains the project and how it uses Redis:
The data is stored as JSON values and only has a single structure.
-
Each JSON values have properties:
- Id : Generated id, used for the key too.
- ShortenUrl: The shorten URL, will be used to find the original URL. (Indexed)
- OriginalUrl: The original URL, will be used to redirect the pages.
- CreatedBy: To know the creator, will allow editing for entries that are created by authenticated users. (Indexed)
- VisitedCounter: To know how many "clicks" or visited the shortened url.
The key is generated ShortenUrl.Models.Urls:{urlId}
.
Also generate index "FT.CREATE" "Urls" "ON" "Json" "PREFIX" "1" "ShortenUrl.Models.Urls:" "SCHEMA" "$.Id" "AS" "Id" "TAG" "SEPARATOR" "|" "$.ShortenUrl" "AS" "ShortenUrl" "TAG" "SEPARATOR" "|" "$.CreatedBy" "AS" "CreatedBy" "TAG" "SEPARATOR" "|" "$.VisitedCounter" "AS" "VisitedCounter" "NUMERIC" "SORTABLE"
Refer to this example for a more detailed example of what you need for this section.
-
MyURL list (search using index).
FT.SEARCH Urls (@CreatedBy:{username/email}) LIMIT 0 100
- Example:
"FT.SEARCH" "Urls" "(@CreatedBy:{bervianto\\.leo\\@gmail\\.com})" "LIMIT" "0" "100"
- Example:
-
Validate url uniques/find the shortened url.
FT.SEARCH Urls (@ShortenUrl:{shortened-url}) LIMIT 0 100
- Example:
"FT.SEARCH" "Urls" "(@ShortenUrl:{okeoke})" "LIMIT" "0" "1"
- Example:
-
Store the JSON value.
- Example:
"JSON.SET" "ShortenUrl.Models.Urls:01GBJAJ5CQMZRFC6D2MZQ3QBAD" "." "{"Id":"01GBJAJ5CQMZRFC6D2MZQ3QBAD","ShortenUrl":"okeoke","OriginalUrl":"https://google.com","CreatedBy":"bervianto.leo@gmail.com","VisitedCounter":0}"
- Example:
N/A
- Run using
dotnet run --project ShortenUrl
- Access the web using the link from the console output. As example, please see the picture below.
- .NET 6
- Docker (Optional)
- Clone the project
- Restore/Install Dependencies.
dotnet restore
. - Setup the environment example:
export RedisConnectionString=...
or update sectionRedisConnectionString
ofShortenUrl/appsettings.json
. - Now your project is ready!
To make deploys work, you need to create free account on Redis Cloud
Here some resources to help you quickly get started using Redis Stack. If you still have questions, feel free to ask them in the Redis Discord or on Twitter.
- Sign up for a free Redis Cloud account using this link and use the Redis Stack database in the cloud.
- Based on the language/framework you want to use, you will find the following client libraries:
- Redis OM .NET (C#)
- Watch this getting started video
- Follow this getting started guide
- Redis OM Node (JS)
- Watch this getting started video
- Follow this getting started guide
- Redis OM Python
- Watch this getting started video
- Follow this getting started guide
- Redis OM Spring (Java)
- Watch this getting started video
- Follow this getting started guide
- Redis OM .NET (C#)
The above videos and guides should be enough to get you started in your desired language/framework. From there you can expand and develop your app. Use the resources below to help guide you further:
- Developer Hub - The main developer page for Redis, where you can find information on building using Redis with sample projects, guides, and tutorials.
- Redis Stack getting started page - Lists all the Redis Stack features. From there you can find relevant docs and tutorials for all the capabilities of Redis Stack.
- Redis Rediscover - Provides use-cases for Redis as well as real-world examples and educational material
- RedisInsight - Desktop GUI tool - Use this to connect to Redis to visually see the data. It also has a CLI inside it that lets you send Redis CLI commands. It also has a profiler so you can see commands that are run on your Redis instance in real-time
- Youtube Videos
- Official Redis Youtube channel
- Redis Stack videos - Help you get started modeling data, using Redis OM, and exploring Redis Stack
- Redis Stack Real-Time Stock App from Ahmad Bazzi
- Build a Fullstack Next.js app with Fireship.io
- Microservices with Redis Course by Scalable Scripts on freeCodeCamp