Knowledge Bank
  • My GitBook
  • Miscellaneous
  • Project
    • Rider and Intellij
    • Code
    • Frontend
      • Condition
      • AddConditionModalDialog
    • Backend
    • e2e
      • fragments
  • JAVASCRIPT
    • Promise
    • Destructuring
    • Spread Syntax and Rest Parameters
    • Typescript
      • Examples of Types
      • React Typescript
    • This
    • Dot Notation vs Bracket Notation
    • Shallow vs Deep Clone
    • New ES Edition
  • C#
    • Project Note
    • Basic
    • Shortcut and Debugging
  • Programming Paradigms
    • SOLID Principles
    • Object Oriented Programming (OOP)
      • Evolution of OOP (Procedural to OOP)
      • Instantiation
      • 4 Pillars of OOP
      • Extra
    • Functional Programming (FP)
      • Idempotent
      • Imperative vs Declarative
      • Immutability
      • High Order Function and Closure
      • Currying
      • Partial Application
      • Memoization and Caching
      • Compose and Pipe
      • Extra
      • Example of FP
    • OOP vs FP
      • Composition vs Inheritance
  • DATA STRUCTURE
    • Big O
    • Data Structure
    • Array
    • Hash Table
    • Linked List
    • Queue and Stack
    • Tree
      • Binary Heap
      • Trie
    • Graph
      • Example of Graph
  • React-Redux
    • MobX
    • Best Practices
  • Algorithms
    • Recursion
      • Examples of Recursion
    • Sorting
    • Searching and Traversal
    • Dynamic Programming
  • REFACTORING
    • Clean Code
      • Formatting
      • Error Handling
      • Concurrency
      • Testing
      • SOLID Principles
      • Classes
      • Objects and Data Structures
      • Variables
      • Functions
    • Code Smells
      • Long Function
      • Duplicate Code
      • Loops
      • Double Negative
      • Christmas Tree Code
      • Complex Condition
      • Primitive Obsession
      • Speculative Generality
      • God Class
      • Long Parameter List
  • Junior to Senior
    • AWS
      • Lambda
    • Session + Authentication
    • Redis
    • Kubernetes
      • Networking
      • Services
      • Deployment
      • Replica Set
      • YAML
      • pod-definition.yml
      • Kubectl
      • Pods
      • Fundamentals
    • Docker
      • Operating System - Extra
      • Dockerfile - Docker Image
      • Docker Storage
      • Docker Network
      • Docker Registry
      • Docker Command
      • Docker Compose
      • Docker Compose - Postgres
    • Security
      • Logging
      • HTTPS, Cross-Site-Scripting (XSS) and Cross-Site-Request-Forgery (CSRF)
      • 3rd Party Library
      • Injection
      • Code Secret, Secure Header, Access Control, Data Management, Authentication
    • CI/CD
    • SPA vs Server-Side Rendering
    • Performance
      • Optimized Code
      • Critical Render Path
      • Backend Optimization
      • Minimized Files and Images
      • Minimized Delivery
  • SECURITY
    • Encryption
    • SSH
  • Command
  • Cheatsheet
    • NPM
    • GIT
  • Writing Template
    • Guide
    • API
    • ChangeLog
    • FAQ
  • Linux
Powered by GitBook
On this page

Was this helpful?

  1. Junior to Senior

Redis

Redis is Non-SQL database or sometimes we called in-memory database.

Non-SQL databases have different types: Key-Value (Redis), Document (MongoDB), Graph - (Neo4j).

Redis is what we call a key-value store (similar to how we handle JS Object)

Characteristics:

  • In-memory database which is very fast

  • Use for short lived data in our applications, like sessions or web page headcounts

  • Don't have large data sets like MongoDB. Only small data which allow us to keep it in machine memory and not on disk

  • Even though the data is stored in memory, it does take a snapshot occasionally to save the current data contents onto the disk which, is great to recover from, when there's unexpected shutdowns. Although we might lose the some/ latest information.

  • Handle 5 data types: string, hash, list, set and sorted set.

// Examples of simple redis command:

SET name "String"
GET name 
EXISTS name
DEL name
EXPIRE name ${num}
SET counter 1000
INCRBY counter 55 // 1055
DECR counter //1054
MSET a 2 b 5 //Multiple Set
MGET a b //Multiple Get

Hash:

// Similar to JS object

HMSET user id 45 name "John"
HGET user id
HGET user name
HGETALL user //id, 45, name, John

List:

  • Insertion is really really fast. Useful when you have long list and you need to add element quickly.

  • Take a bit of time when searching. Use sorted list which is better for searching.

// Similar to linked list

LPUSH mylist 10
RPUSH mylist hello
LPUSH mylist there
LRANGE mylist 0 2 // there, 10, hello
LPOP mylist // there

Set and Sorted Set:

Set is unordered collection of string and sorted set is ordered. In set, there is no duplicate value.

The difference between set and sorted set is in sorted set, for every member of a sorted set is associated with a score and this score allows it to be ordered from smallest to greatest.

SADD myset 1 2 3 4 5
SMEMBERS myset // 1 2 3 4 5
SADD myset 1 2 4 6 // 1 2 3 4 5 6
SISMEMBER myset 5 // 1 or yes


ZADD team 50 "Alice"
ZADD team 40 "Bob"
ZADD team 1 "Charlie"
ZRANGE team 0 2 // Charlie Bob Alice
ZRANK team "Bob" // 1
PreviousSession + AuthenticationNextKubernetes

Last updated 4 years ago

Was this helpful?