Giter Site home page Giter Site logo

workshop-redis's Introduction

What is redis?

  • In-memory data structure store, used as a database, cache and message broker.
  • Key / value database.
  • Different levels of on-disk persistence.

alt text

Why redis?

  • Not just a cache.
  • Multiple datatypes.
  • Pub-sub model.
  • Cluster mode for high availability.
  • Perfectly works in cloud: AWS Elasticache, Azure Redis Cache and Memorystore (Google Cloud).

alt text

alt text

Data types

Remember you need in our local:

# redis
# redis-cli 
# npm / nodejs

# install dependencies
npm install

Overview

  • Redis instance has 16 databases, DONT NEED PREFIX IN KEYS
redis-cli -n {database_number}
  • Debugging from cli
redis-cli monitor
  • Main commands: KEYS / DEBUG / SCAN / TYPE / EXPIRATE

String

  • Basic data type
  • Main commands: set / get
node examples/datatypes/string.js

List

  • Arrays of strings
  • Main commands : lpush / lrange / lpop
node examples/datatypes/list.js

Set

  • Unique and unordered collection of strings
  • Main commands: sadd / smember / srem / sscan
node examples/datatypes/set.js

Hash

  • Maps between string fields and string values
  • Perfect data type to represent objects
  • Main commands: hset / hmset / hget / hgetall / hscan
node examples/datatypes/hash.js

Sorted Sets

  • Similarly to Redis Sets, non repeating collections of Strings.
  • Every member of a Sorted Set is associated with score
  • Main commands: zadd / zrangebyscore
node examples/datatypes/sorted-set.js

Streams

  • New data type from Redis 5
  • Goal handle large amount of data (example: chat history, logs, etc)
  • Main commands: xadd / xread
node examples/datatypes/stream.js

Transactions

COMMANDS MULTI, EXEC, DISCARD and WATCH

  • They allow the execution of a group of commands in a single step
  • All the commands in a transaction are serialized and executed sequentially.
  • Atomicity (either all occur or nothing occurs)
node examples/transactions/multi-exec.js

LUA SCRIPT

  • You can encapsulate some complex operations in a script and your data layer will perform the atomic
node examples/transactions/rewards.js
node examples/transactions/lua-script.js

Message Queues

  • PUBLISH / SUBSCRIBE

alt text

pros

  • Memory efficiency
  • Group messagingsS
  • Examples: notifications, chats, etc.

cons

  • High chance loss message
node pubsub.js
  • BRPOPLPUSH / RedisSMQ

alt text

  • Message only will be consumed by one consumer
  • Less memory efficiency
node examples/queues/create.js
node examples/queues/producer.js
node examples/queues/consumer.js

Everyone should read

https://redis.io/topics/introduction

https://dzone.com/articles/how-redis-is-used-in-practice

https://www.bogotobogo.com/DevOps/Redis/Redis_vs_Memcached.php

https://matt.sh/what-is-redis

https://matt.sh/introduction-to-redis-data-types

https://www.compose.com/articles/a-quick-guide-to-redis-lua-scripting/

https://medium.com/@anvannguyen/redis-message-queue-rpoplpush-vs-pub-sub-e8a19a3c071b

workshop-redis's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.