Skip to content

TomDoesTech/learn-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learn Just Enough Redis to be Productive

Useful links

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

What is Redis?

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