https://github.com/tomdoestech/learn-redis
https://github.com/tomdoestech/learn-redis
nodejs redis
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tomdoestech/learn-redis
- Owner: TomDoesTech
- Created: 2024-03-09T10:40:07.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-09T10:43:56.000Z (about 2 years ago)
- Last Synced: 2024-04-17T06:07:24.099Z (about 2 years ago)
- Topics: nodejs, redis
- Language: TypeScript
- Homepage: https://youtu.be/mofZIitXMvU
- Size: 13.7 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Learn Just Enough Redis to be Productive

## Useful links
- [Build & Deploy a Realtime App that Scales with Upstash Redis, Next.js & Fastify](https://youtu.be/cfEqS1A5diM)
- [Upstash Redis](https://upstash.com/?utm_source=tom1)
## What you will learn
- What Redis is
- Why Redis is so popular
- How to use Redis
- How to use Redis to solve some common problems in Node.js
**What you will need**
- Node.js
- Upstash Redis account (free) https://upstash.com/
**What is Redis?**
- Key value store
- Can handle lots of different data structures: https://redis.io/docs/data-types/
- Has lots of features that you’d expect from a database:
- Pub/Sub https://redis.io/docs/interact/pubsub/
- Transactions https://redis.io/docs/interact/transactions/
- Persistence https://redis.io/docs/management/persistence/
- Programmability with Lua https://redis.io/docs/interact/programmability/
## Video sturcture
1. Getting started with Upstash Redis
2. Basic commands & data structures
3. Problems Redis can solve
- Caching
- Rate limiting
- Pub/Sub
- Indexes
- Transactions
## Basic commands
https://redis.io/commands/
- Set `set mykey tom`
- Get `get mykey`
- Del `DEL mykey`
- Set with TTL `SETEX key seconds value`
- Check if key exists `EXISTS mykey`
- List keys `KEYS *`
### Data structures
**JSON**
```
SET user:100 '{"name": "John", "age": 30, "email": "john@example.com"}'
GET user:100
```
**Hash**
Hashes are used to store objects, represented by fields and values.
```
HSET user:101 name "Alice"
HSET user:101 age 24
HSET user:101 email "alice@example.com"
HGET user:101 name
```
**Sets**
Sets are collections of unique elements
```
SADD myset 1 2 3
SMEMBERS myset
```
```
SADD users tom
SADD users alice
SADD users tom
SMEMBERS users
```
**Sorted Sets**
Sorted sets are similar to sets, but every member of a sorted set is associated with a score, that is used in order to take the sorted set ordered, from the smallest to the greatest score.
```
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZRANGE myzset 0 -1
```
**Counters**
```
INCR counter
INCRBY counter 10
DECR counter
DECRBY counter 5
GET counter
```