SlideShare a Scribd company logo
1 of 22
REmote DIctionary Server
Introduction
What is REDIS ?
Redis can persist data to the disk Redis is not only a key-value store
 Redis is a different evolution path in the key-value databases where values are
complex data types that are closely related to fundamental data structures and
are exposed to the programmer as such, without additional abstraction layers.
Official webpage: http://redis.io Source Code: https://github.com/antirez/redis Online Demo: http://try.redis.io
 Can be used as Database, a Caching layer or a Message broker.
 Redis is an advanced key-value store, where keys can contain data structures such
as strings, hashes, lists, sets, and sorted sets. Supporting a set of atomic
operations on these data types.
Redis is fast
What is not REDIS
 Redis is not a replacement for Relational Databases nor Document Stores.
 It might be used complementary to a SQL relational store, and/or NoSQL
document store.
 Even when Redis offers configurable mechanisms for persistency, increased
persistency will tend to increase latency and decrease throughput.
 Best used for rapidly changing data with a foreseeable database size (should fit
mostly in memory).
NoSQL comparisons:
http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
http://www.infoivy.com/2013/07/nosql-database-comparison-chart-only.html
Redis Use Cases
 Caching
 Counting things
 Blocking queues
 Pub/Sub (service bus)
 MVC Output Cache provider
 Backplane for SignalR
 ASP.NET Session State provider*
 Online user data (shopping cart, …)
* ASP.NET session state providers comparison: http://www.slideshare.net/devopsguys/best-performing-aspnet-session-state-providers
 … Any real-time, cross-platform, cross-application communication
When to consider Redis
 Speed is critical
 More than just key-value pairs
 Dataset can fit in memory
 Dataset is not critical
From: http://www.slideshare.net/autonomous/redis-overview-for-software-architecture-forum
Redis Architecture
 Written in ANSI C by Salvatore Sanfilippo (@antirez).
 Works in most POSIX systems like Linux, BSD and OS X.
 Linux is the recommended
 No official support for Windows, but Microsoft develops and maintains an open
source Win-64 port of Redis*
 Redis is a single-threaded server, not designed to benefit from multiple CPU cores.
Several Redis instances can be launched to scale out on several cores.
 All operations are atomic (no two commands can run at the same time).
 It executes most commands in O(1) complexity and with minimal lines of code.
*Redis on Windows: https://github.com/MSOpenTech/redis
Redis Architecture
*from https://matt.sh/redis-architecture-diagram
Redis data types
*Redis data types internals: https://cs.brown.edu/courses/cs227/archives/2011/slides/mar07-redis.pdf
Redis Data Type Contains Read/write ability
String
Binary-safe strings (up to 512 MB), Integers or
Floating point values, Bitmaps.
Operate on the whole string, parts, increment/decrement
the integers and floats, get/set bits by position.
Hash Unordered hash table of keys to string values
Add, fetch, or remove individual ítems by key, fetch the
whole hash.
List Doubly linked list of strings
Push or pop items from both ends, trim based on offsets,
read individual or multiple items, find or remove items by
value.
Set Unordered collection of unique strings
Add, fetch, or remove individual items, check
membership, intersect, union, difference, fetch random
items.
Sorted Set
Ordered mapping of string members to
floating-point scores, ordered by score
Add, fetch, or remove individual items, fetch items based
on score ranges or member value.
Geospatial
index
Sorted set implementation using geospatial
information as the score
Add, fetch or remove individual items, search by
coordinates and radius, calculate distance.
HyperLogLog
Probabilistic data structure to count unique
things using 12Kb of memory
Add individual or multiple items, get the cardinality.
Value1Key1
Value2Key2
Lon.:
-103.55328
Lat.:
20.63373
Value
10000110
...10
I m a string!
...0000110
ACBD
CBCA
C: 250A: 250D: 0.3B: 0.1
Redis data types - Examples
Redis in action
Redis-cli client
StackExchange.Redis C# client try.redis.io
Redis-server
Redis Commands - Basic
Get/Set strings SET [key value] / GET [key]
redis> SET foo “hello!“ O(1)
OK
redis> GET foo
“hello!“
Increment numbers INCRBY [key increment]
redis> SET bar 223 O(1)
OK
redis> INCRBY bar 1000
(integer) 1223
Get multiple keys at once MGET [key key …]
redis> MGET foo bar O(N) : N=# of keys.
1. “hello!"
2. "1223“
Set multiple keys at once MSET [key value key value …]
> MSET foo “hello!” bar 1223 O(N) : N=# of keys.
OK Set key expiration EXPIRE [key seconds]
O(1)
redis> EXPIRE foo 10
(integer) 1
Rename a key RENAME [key newkey]
redis> RENAME bar new_bar O(1)
OK
Update a value retrieving the old one GETSET [key value]
redis> GETSET foo “bye!” O(1)
“hello!"
redis> GET foo
“bye!"
Key removal DEL [key …]
O(1)
redis> DEL foo
(integer) 1
Test for existence EXISTS [key …]
O(1)
redis> EXISTS foo
(integer) 1
Get the length of a string STRLEN [key]
O(1)
redis> STRLEN foo
(integer) 6
Get the type of a key TYPE [key]
O(1)
redis> TYPE foo
string
Strings Keys
Get key time-to-live TTL [key]
O(1)
redis> TTL foo
(integer) 10
Redis Commands – Lists & Hashes
Push on either end RPUSH/LPUSH [key value]
redis> RPUSH jobs “foo” O(1)
(integer) 1
redis> LPUSH jobs “bar”
(integer) 1
Pop from either end RPOP/LPOP [key]
redis> RPOP jobs O(1)
“foo”
redis> LPOP jobs
“bar”
Blocking Pop BRPOP/BLPOP [key]
redis> BLPOP jobs O(1)
redis> BRPOP jobs
Get a range of elements LRANGE [key start stop]
redis> LRANGE jobs 0 -1 O(N)
1. “bar"
2. “foo“
Pop and Push to another list RPOPLPUSH [src dst]
O(1)
redis> RPOPLPUSH jobs proc
“foo”
Get an element by index LINDEX [key index]
redis> LINDEX jobs 1 O(N)
“foo”
Set a hashed value HSET [key field value]
O(1)
redis> HSET user:1 name John
(integer) 1
Set multiple fields HMSET [key field value …]
O(1)
redis> HMSET user:1 lastname Smith visits 1
OK
Get a hashed value HGET [key field]
O(1)
redis> HGET user:1 name
“John”
Get all the values in a hash HGETALL [key]
O(N) : N=size of hash.
redis> HGETALL user:1
1) "name"
2) "John"
3) "lastname"
4) "Smith"
5) "visits"
6) "1"
Increment a hashed value HINCRBY [key field incr]
O(1)
redis> HINCRBY user:1 visits 1
(integer) 2
Lists Hashes
Redis Commands – Sets & Sorted sets
Add member to a set SADD [key member ...]
redis> SADD admins “Peter” O(1)
(integer) 1
redis> SADD users “John” “Peter”
(integer) 2
Pop a random element SPOP [key]
O(1)
redis> SPOP users
“John”
Get all elements SMEMBERS [key]
redis> SMEMBERS users O(N) : N=size of set.
1) "Peter"
2) "John"
Intersect multiple sets SINTER [key key …]
redis> SINTER users admins O(N)
1. “Peter"
Union multiple sets SUNION [key key …]
redis> SUNION users admins O(N)
1) "Peter"
2) "John“
Diff. multiple sets DIFF [key key …]
O(N)
redis> SDIFF users admins
1) "John“
Add member to a sorted set ZADD [key score member]
redis> ZADD scores 100 “John” O(log(N))
(integer) 1
redis> ZADD scores 50 “Peter” 200 “Charles” 1000 “Mary”
(integer) 3
Get the rank of a member ZRANK [key member]
O(log(N))
redis> ZRANK scores “Mary”
(integer) 3
Get elements by score range ZRANGEBYSCORE [key min max]
O(log(N))
redis> ZRANGEBYSCORE scores 200 +inf WITHSCORES
1) “Charles“
2) 200
3) “Mary“
4) 1000
Increment score of member ZINCRBY [key incr member]
O(log(N))
redis> ZINCRBY scores 10 “Mary”
“1010”
Remove range by score ZREMRANGEBYSCORE [key min max]
O(log(N))
redis> ZREMRANGEBYSCORE scores 0 100
(integer) 2
Sets Sorted sets
Scaling Redis
 Persistence
Redis provides two mechanisms to deal with persistence: Redis database snapshots (RDB) and
append-only files (AOF).
Master
Slave
Slave
Master
Master
Master
Master
Master
Master
SlaveMaster
Redis
Disk
 Replication
A Redis instance known as the master, ensures that one or more instances kwown as the slaves,
become exact copies of the master. Clients can connect to the master or to the slaves. Slaves are
read only by default.
 Partitioning
Breaking up data and distributing it across different hosts in a cluster.
Can be implemented in different layers:
 Client: Partitioning on client-side code.
 Proxy: An extra layer that proxies all redis queries and performs partitioning
(i.e. Twemproxy).
 Query Router: instances will make sure to forward the query to the right node.
(i.e Redis Cluster).
 Failover
 Manual
 Automatic with Redis Sentinel (for master-slave topology)
 Automatic with Redis Cluster (for cluster topology)
Redis topologies
I. Standalone
II. Sentinel (automatic failover)
III. Twemproxy (distribute data)
IV. Cluster (automatic failover and distribute data)
Redis topologies I - Standalone
Master-slave
 The master data is optionally replicated to slaves.
 The slaves provides data redundancy, reads offloading and save-to-disk offloading.
 Clients can connect to the Master for read/write operations or to the Slaves for
read operations.
 Slaves can also replicate to its own slaves.
 There is no automatic failover.
Redis
Master
Redis
Slave
Redis
Slave
Master only Master-slave multi-level
Redis
Master
Redis
Slave
Redis
Slave
Redis
Slave
Redis
SlaveRedis
Master
Redis topologies II - Sentinel
Master-slave with Sentinel
 Redis Sentinel provides a reliable automatic failover in a master/slave topology,
automatically promoting a slave to master if the existing master fails.
 Sentinel does not distribute data across nodes.
Twemproxy (single)
 Twemproxy* works as a proxy between the clients and many Redis instances.
 Is able to automatically distribute data among different standalone Redis instances.
 Supports consistent hashing with different strategies and hashing functions.
 Multi-key commands and transactions are not supported.
Twemproxy (load balanced)
*Twemproxy is a project from Twitter and is not part of redis: https://github.com/twitter/twemproxy
Redis topologies III - Twemproxy
**Illustrations from Redis Essentials book by Maxwell Dayvson Da Silva and Hugo Lopes Tavares
Redis Cluster
 Redis Cluster distributes data across different Redis instances and perform automatic
failover if any problem happens to any master instance.
 All nodes are directly connected with a service channel.
 The keyspace is divided into hash slots. Different nodes will hold a subset of hash slots.
 Multi-key commands are only allowed for keys in the same hash slot.
Redis topologies IV - Cluster
Master A
Master B
Slave A1
Slave A2
Slave B1
Master C
Slave B1
Slots 0-6000
Slots 6001-12000
Slots 12001-16383
Servicechannel
Slave B12
Slave B11
Slave A22
Slave A21
Redis advantages
 Performance
 Availability
 Fault-Tolerance
 Scalability (adaptability)
 Portability
 Support for complex data types and structures
 Atomic operations and Transactions
 Pipelining (send multiple commands at once)
 LUA scripting support
 LRU eviction of keys
 Keys with limited time-to-live
 Simple to install, setup and manage
 Highly configurable
 Supported on many languages
 Straightforward and well documented API
 Open Source
 Available on Azure
NoSQL & SQL response performance comparison
(from https://redislabs.com/blog/the-proven-redis-performance)
Questions
 Redis Use Cases
 Redis Architecture
 Redis Data Types
 Redis Commands
 Redis Scalability
 Redis Topologies
Redis Official webpage: http://redis.io Online Demo: http://try.redis.io
Source Code: https://github.com/antirez/redis This PPT: http://bit.ly/1N87DJR
Redis/Memcached comparison: http://db-engines.com/en/system/Memcached%3BRiak%3BRedis

More Related Content

What's hot

An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAli MasudianPour
 
Caching solutions with Redis
Caching solutions   with RedisCaching solutions   with Redis
Caching solutions with RedisGeorge Platon
 
Redis persistence in practice
Redis persistence in practiceRedis persistence in practice
Redis persistence in practiceEugene Fidelin
 
Redis Overview
Redis OverviewRedis Overview
Redis OverviewHoang Long
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert HodgesA Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert HodgesAltinity Ltd
 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use CasesFabrizio Farinacci
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB plc
 
Redis cluster
Redis clusterRedis cluster
Redis clusteriammutex
 
Redis Reliability, Performance & Innovation
Redis Reliability, Performance & InnovationRedis Reliability, Performance & Innovation
Redis Reliability, Performance & InnovationRedis Labs
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLRené Cannaò
 
Your first ClickHouse data warehouse
Your first ClickHouse data warehouseYour first ClickHouse data warehouse
Your first ClickHouse data warehouseAltinity Ltd
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in PracticeNoah Davis
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBMydbops
 

What's hot (20)

Redis database
Redis databaseRedis database
Redis database
 
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis 101
Redis 101Redis 101
Redis 101
 
Caching solutions with Redis
Caching solutions   with RedisCaching solutions   with Redis
Caching solutions with Redis
 
Redis overview
Redis overviewRedis overview
Redis overview
 
Redis persistence in practice
Redis persistence in practiceRedis persistence in practice
Redis persistence in practice
 
Redis Overview
Redis OverviewRedis Overview
Redis Overview
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert HodgesA Fast Intro to Fast Query with ClickHouse, by Robert Hodges
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use Cases
 
Redis and it's data types
Redis and it's data typesRedis and it's data types
Redis and it's data types
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
 
Redis cluster
Redis clusterRedis cluster
Redis cluster
 
Redis Reliability, Performance & Innovation
Redis Reliability, Performance & InnovationRedis Reliability, Performance & Innovation
Redis Reliability, Performance & Innovation
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
ProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQLProxySQL - High Performance and HA Proxy for MySQL
ProxySQL - High Performance and HA Proxy for MySQL
 
Your first ClickHouse data warehouse
Your first ClickHouse data warehouseYour first ClickHouse data warehouse
Your first ClickHouse data warehouse
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
Parallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDBParallel Replication in MySQL and MariaDB
Parallel Replication in MySQL and MariaDB
 

Viewers also liked

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
REDIS caching explained
REDIS caching explained REDIS caching explained
REDIS caching explained Dan Rinzel
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeperSaurav Haloi
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & FeaturesDataStax Academy
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
 
Everything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askCarlos Abalde
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
Blackboard DevCon: Introducing IMS Learning Tools Interoperability
Blackboard DevCon: Introducing IMS Learning Tools InteroperabilityBlackboard DevCon: Introducing IMS Learning Tools Interoperability
Blackboard DevCon: Introducing IMS Learning Tools InteroperabilityCharles Severance
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2Dvir Volk
 
Code your Own: Authentication Provider for Blackboard Learn
Code your Own: Authentication Provider for Blackboard LearnCode your Own: Authentication Provider for Blackboard Learn
Code your Own: Authentication Provider for Blackboard LearnDan Rinzel
 
Redis replication dcshi
Redis replication dcshiRedis replication dcshi
Redis replication dcshidcshi
 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2Itamar Haber
 
Redis for search - Dvir Volk, Redis Labs
Redis for search - Dvir Volk, Redis LabsRedis for search - Dvir Volk, Redis Labs
Redis for search - Dvir Volk, Redis LabsRedis Labs
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating languagejgrahamc
 
Redis as a Main Database, Scaling and HA
Redis as a Main Database, Scaling and HARedis as a Main Database, Scaling and HA
Redis as a Main Database, Scaling and HADave Nielsen
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionDavid Pilato
 

Viewers also liked (20)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
REDIS caching explained
REDIS caching explained REDIS caching explained
REDIS caching explained
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
Everything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to askEverything you always wanted to know about Redis but were afraid to ask
Everything you always wanted to know about Redis but were afraid to ask
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Blackboard DevCon: Introducing IMS Learning Tools Interoperability
Blackboard DevCon: Introducing IMS Learning Tools InteroperabilityBlackboard DevCon: Introducing IMS Learning Tools Interoperability
Blackboard DevCon: Introducing IMS Learning Tools Interoperability
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Code your Own: Authentication Provider for Blackboard Learn
Code your Own: Authentication Provider for Blackboard LearnCode your Own: Authentication Provider for Blackboard Learn
Code your Own: Authentication Provider for Blackboard Learn
 
Redis replication dcshi
Redis replication dcshiRedis replication dcshi
Redis replication dcshi
 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2
 
Redis Labcamp
Redis LabcampRedis Labcamp
Redis Labcamp
 
Lightning Hedis
Lightning HedisLightning Hedis
Lightning Hedis
 
Redis for search - Dvir Volk, Redis Labs
Redis for search - Dvir Volk, Redis LabsRedis for search - Dvir Volk, Redis Labs
Redis for search - Dvir Volk, Redis Labs
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating language
 
Redis as a Main Database, Scaling and HA
Redis as a Main Database, Scaling and HARedis as a Main Database, Scaling and HA
Redis as a Main Database, Scaling and HA
 
InnoDB Locking Explained with Stick Figures
InnoDB Locking Explained with Stick FiguresInnoDB Locking Explained with Stick Figures
InnoDB Locking Explained with Stick Figures
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English version
 

Similar to Redis introduction

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisItamar Haber
 
quickguide-einnovator-9-redis
quickguide-einnovator-9-redisquickguide-einnovator-9-redis
quickguide-einnovator-9-redisjorgesimao71
 
Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Itamar Haber
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with ModulesItamar Haber
 
mar07-redis.pdf
mar07-redis.pdfmar07-redis.pdf
mar07-redis.pdfAnisSalhi3
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Itamar Haber
 
Fun with Ruby and Redis
Fun with Ruby and RedisFun with Ruby and Redis
Fun with Ruby and Redisjavier ramirez
 
Developing a Redis Module - Hackathon Kickoff
 Developing a Redis Module - Hackathon Kickoff Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon KickoffItamar Haber
 
NoSQL, SQL, NewSQL - methods of structuring data.
NoSQL, SQL, NewSQL - methods of structuring data.NoSQL, SQL, NewSQL - methods of structuring data.
NoSQL, SQL, NewSQL - methods of structuring data.Tony Rogerson
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014steffenbauer
 
Paris Redis Meetup Introduction
Paris Redis Meetup IntroductionParis Redis Meetup Introduction
Paris Redis Meetup IntroductionGregory Boissinot
 
REDIS intro and how to use redis
REDIS intro and how to use redisREDIS intro and how to use redis
REDIS intro and how to use redisKris Jeong
 
Redis Installation Configuration And Implementation
Redis Installation Configuration And ImplementationRedis Installation Configuration And Implementation
Redis Installation Configuration And ImplementationAbhijeet Shekhar
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfStephen Lorello
 
Redis学习笔记
Redis学习笔记Redis学习笔记
Redis学习笔记yongboy
 

Similar to Redis introduction (20)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
quickguide-einnovator-9-redis
quickguide-einnovator-9-redisquickguide-einnovator-9-redis
quickguide-einnovator-9-redis
 
Redis
RedisRedis
Redis
 
Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)
 
Redis basics
Redis basicsRedis basics
Redis basics
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with Modules
 
mar07-redis.pdf
mar07-redis.pdfmar07-redis.pdf
mar07-redis.pdf
 
Redis
RedisRedis
Redis
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)
 
Fun with Ruby and Redis
Fun with Ruby and RedisFun with Ruby and Redis
Fun with Ruby and Redis
 
Developing a Redis Module - Hackathon Kickoff
 Developing a Redis Module - Hackathon Kickoff Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon Kickoff
 
NoSQL, SQL, NewSQL - methods of structuring data.
NoSQL, SQL, NewSQL - methods of structuring data.NoSQL, SQL, NewSQL - methods of structuring data.
NoSQL, SQL, NewSQL - methods of structuring data.
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 
redis-demo.pptx
redis-demo.pptxredis-demo.pptx
redis-demo.pptx
 
Comredis
ComredisComredis
Comredis
 
Paris Redis Meetup Introduction
Paris Redis Meetup IntroductionParis Redis Meetup Introduction
Paris Redis Meetup Introduction
 
REDIS intro and how to use redis
REDIS intro and how to use redisREDIS intro and how to use redis
REDIS intro and how to use redis
 
Redis Installation Configuration And Implementation
Redis Installation Configuration And ImplementationRedis Installation Configuration And Implementation
Redis Installation Configuration And Implementation
 
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdfAn Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for .NET Developers.pdf
 
Redis学习笔记
Redis学习笔记Redis学习笔记
Redis学习笔记
 

Recently uploaded

VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 

Recently uploaded (20)

VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 

Redis introduction

  • 2.
  • 3. What is REDIS ? Redis can persist data to the disk Redis is not only a key-value store  Redis is a different evolution path in the key-value databases where values are complex data types that are closely related to fundamental data structures and are exposed to the programmer as such, without additional abstraction layers. Official webpage: http://redis.io Source Code: https://github.com/antirez/redis Online Demo: http://try.redis.io  Can be used as Database, a Caching layer or a Message broker.  Redis is an advanced key-value store, where keys can contain data structures such as strings, hashes, lists, sets, and sorted sets. Supporting a set of atomic operations on these data types. Redis is fast
  • 4. What is not REDIS  Redis is not a replacement for Relational Databases nor Document Stores.  It might be used complementary to a SQL relational store, and/or NoSQL document store.  Even when Redis offers configurable mechanisms for persistency, increased persistency will tend to increase latency and decrease throughput.  Best used for rapidly changing data with a foreseeable database size (should fit mostly in memory). NoSQL comparisons: http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis http://www.infoivy.com/2013/07/nosql-database-comparison-chart-only.html
  • 5. Redis Use Cases  Caching  Counting things  Blocking queues  Pub/Sub (service bus)  MVC Output Cache provider  Backplane for SignalR  ASP.NET Session State provider*  Online user data (shopping cart, …) * ASP.NET session state providers comparison: http://www.slideshare.net/devopsguys/best-performing-aspnet-session-state-providers  … Any real-time, cross-platform, cross-application communication
  • 6. When to consider Redis  Speed is critical  More than just key-value pairs  Dataset can fit in memory  Dataset is not critical From: http://www.slideshare.net/autonomous/redis-overview-for-software-architecture-forum
  • 7. Redis Architecture  Written in ANSI C by Salvatore Sanfilippo (@antirez).  Works in most POSIX systems like Linux, BSD and OS X.  Linux is the recommended  No official support for Windows, but Microsoft develops and maintains an open source Win-64 port of Redis*  Redis is a single-threaded server, not designed to benefit from multiple CPU cores. Several Redis instances can be launched to scale out on several cores.  All operations are atomic (no two commands can run at the same time).  It executes most commands in O(1) complexity and with minimal lines of code. *Redis on Windows: https://github.com/MSOpenTech/redis
  • 9. Redis data types *Redis data types internals: https://cs.brown.edu/courses/cs227/archives/2011/slides/mar07-redis.pdf Redis Data Type Contains Read/write ability String Binary-safe strings (up to 512 MB), Integers or Floating point values, Bitmaps. Operate on the whole string, parts, increment/decrement the integers and floats, get/set bits by position. Hash Unordered hash table of keys to string values Add, fetch, or remove individual ítems by key, fetch the whole hash. List Doubly linked list of strings Push or pop items from both ends, trim based on offsets, read individual or multiple items, find or remove items by value. Set Unordered collection of unique strings Add, fetch, or remove individual items, check membership, intersect, union, difference, fetch random items. Sorted Set Ordered mapping of string members to floating-point scores, ordered by score Add, fetch, or remove individual items, fetch items based on score ranges or member value. Geospatial index Sorted set implementation using geospatial information as the score Add, fetch or remove individual items, search by coordinates and radius, calculate distance. HyperLogLog Probabilistic data structure to count unique things using 12Kb of memory Add individual or multiple items, get the cardinality. Value1Key1 Value2Key2 Lon.: -103.55328 Lat.: 20.63373 Value 10000110 ...10 I m a string! ...0000110 ACBD CBCA C: 250A: 250D: 0.3B: 0.1
  • 10. Redis data types - Examples
  • 11. Redis in action Redis-cli client StackExchange.Redis C# client try.redis.io Redis-server
  • 12. Redis Commands - Basic Get/Set strings SET [key value] / GET [key] redis> SET foo “hello!“ O(1) OK redis> GET foo “hello!“ Increment numbers INCRBY [key increment] redis> SET bar 223 O(1) OK redis> INCRBY bar 1000 (integer) 1223 Get multiple keys at once MGET [key key …] redis> MGET foo bar O(N) : N=# of keys. 1. “hello!" 2. "1223“ Set multiple keys at once MSET [key value key value …] > MSET foo “hello!” bar 1223 O(N) : N=# of keys. OK Set key expiration EXPIRE [key seconds] O(1) redis> EXPIRE foo 10 (integer) 1 Rename a key RENAME [key newkey] redis> RENAME bar new_bar O(1) OK Update a value retrieving the old one GETSET [key value] redis> GETSET foo “bye!” O(1) “hello!" redis> GET foo “bye!" Key removal DEL [key …] O(1) redis> DEL foo (integer) 1 Test for existence EXISTS [key …] O(1) redis> EXISTS foo (integer) 1 Get the length of a string STRLEN [key] O(1) redis> STRLEN foo (integer) 6 Get the type of a key TYPE [key] O(1) redis> TYPE foo string Strings Keys Get key time-to-live TTL [key] O(1) redis> TTL foo (integer) 10
  • 13. Redis Commands – Lists & Hashes Push on either end RPUSH/LPUSH [key value] redis> RPUSH jobs “foo” O(1) (integer) 1 redis> LPUSH jobs “bar” (integer) 1 Pop from either end RPOP/LPOP [key] redis> RPOP jobs O(1) “foo” redis> LPOP jobs “bar” Blocking Pop BRPOP/BLPOP [key] redis> BLPOP jobs O(1) redis> BRPOP jobs Get a range of elements LRANGE [key start stop] redis> LRANGE jobs 0 -1 O(N) 1. “bar" 2. “foo“ Pop and Push to another list RPOPLPUSH [src dst] O(1) redis> RPOPLPUSH jobs proc “foo” Get an element by index LINDEX [key index] redis> LINDEX jobs 1 O(N) “foo” Set a hashed value HSET [key field value] O(1) redis> HSET user:1 name John (integer) 1 Set multiple fields HMSET [key field value …] O(1) redis> HMSET user:1 lastname Smith visits 1 OK Get a hashed value HGET [key field] O(1) redis> HGET user:1 name “John” Get all the values in a hash HGETALL [key] O(N) : N=size of hash. redis> HGETALL user:1 1) "name" 2) "John" 3) "lastname" 4) "Smith" 5) "visits" 6) "1" Increment a hashed value HINCRBY [key field incr] O(1) redis> HINCRBY user:1 visits 1 (integer) 2 Lists Hashes
  • 14. Redis Commands – Sets & Sorted sets Add member to a set SADD [key member ...] redis> SADD admins “Peter” O(1) (integer) 1 redis> SADD users “John” “Peter” (integer) 2 Pop a random element SPOP [key] O(1) redis> SPOP users “John” Get all elements SMEMBERS [key] redis> SMEMBERS users O(N) : N=size of set. 1) "Peter" 2) "John" Intersect multiple sets SINTER [key key …] redis> SINTER users admins O(N) 1. “Peter" Union multiple sets SUNION [key key …] redis> SUNION users admins O(N) 1) "Peter" 2) "John“ Diff. multiple sets DIFF [key key …] O(N) redis> SDIFF users admins 1) "John“ Add member to a sorted set ZADD [key score member] redis> ZADD scores 100 “John” O(log(N)) (integer) 1 redis> ZADD scores 50 “Peter” 200 “Charles” 1000 “Mary” (integer) 3 Get the rank of a member ZRANK [key member] O(log(N)) redis> ZRANK scores “Mary” (integer) 3 Get elements by score range ZRANGEBYSCORE [key min max] O(log(N)) redis> ZRANGEBYSCORE scores 200 +inf WITHSCORES 1) “Charles“ 2) 200 3) “Mary“ 4) 1000 Increment score of member ZINCRBY [key incr member] O(log(N)) redis> ZINCRBY scores 10 “Mary” “1010” Remove range by score ZREMRANGEBYSCORE [key min max] O(log(N)) redis> ZREMRANGEBYSCORE scores 0 100 (integer) 2 Sets Sorted sets
  • 15. Scaling Redis  Persistence Redis provides two mechanisms to deal with persistence: Redis database snapshots (RDB) and append-only files (AOF). Master Slave Slave Master Master Master Master Master Master SlaveMaster Redis Disk  Replication A Redis instance known as the master, ensures that one or more instances kwown as the slaves, become exact copies of the master. Clients can connect to the master or to the slaves. Slaves are read only by default.  Partitioning Breaking up data and distributing it across different hosts in a cluster. Can be implemented in different layers:  Client: Partitioning on client-side code.  Proxy: An extra layer that proxies all redis queries and performs partitioning (i.e. Twemproxy).  Query Router: instances will make sure to forward the query to the right node. (i.e Redis Cluster).  Failover  Manual  Automatic with Redis Sentinel (for master-slave topology)  Automatic with Redis Cluster (for cluster topology)
  • 16. Redis topologies I. Standalone II. Sentinel (automatic failover) III. Twemproxy (distribute data) IV. Cluster (automatic failover and distribute data)
  • 17. Redis topologies I - Standalone Master-slave  The master data is optionally replicated to slaves.  The slaves provides data redundancy, reads offloading and save-to-disk offloading.  Clients can connect to the Master for read/write operations or to the Slaves for read operations.  Slaves can also replicate to its own slaves.  There is no automatic failover. Redis Master Redis Slave Redis Slave Master only Master-slave multi-level Redis Master Redis Slave Redis Slave Redis Slave Redis SlaveRedis Master
  • 18. Redis topologies II - Sentinel Master-slave with Sentinel  Redis Sentinel provides a reliable automatic failover in a master/slave topology, automatically promoting a slave to master if the existing master fails.  Sentinel does not distribute data across nodes.
  • 19. Twemproxy (single)  Twemproxy* works as a proxy between the clients and many Redis instances.  Is able to automatically distribute data among different standalone Redis instances.  Supports consistent hashing with different strategies and hashing functions.  Multi-key commands and transactions are not supported. Twemproxy (load balanced) *Twemproxy is a project from Twitter and is not part of redis: https://github.com/twitter/twemproxy Redis topologies III - Twemproxy **Illustrations from Redis Essentials book by Maxwell Dayvson Da Silva and Hugo Lopes Tavares
  • 20. Redis Cluster  Redis Cluster distributes data across different Redis instances and perform automatic failover if any problem happens to any master instance.  All nodes are directly connected with a service channel.  The keyspace is divided into hash slots. Different nodes will hold a subset of hash slots.  Multi-key commands are only allowed for keys in the same hash slot. Redis topologies IV - Cluster Master A Master B Slave A1 Slave A2 Slave B1 Master C Slave B1 Slots 0-6000 Slots 6001-12000 Slots 12001-16383 Servicechannel Slave B12 Slave B11 Slave A22 Slave A21
  • 21. Redis advantages  Performance  Availability  Fault-Tolerance  Scalability (adaptability)  Portability  Support for complex data types and structures  Atomic operations and Transactions  Pipelining (send multiple commands at once)  LUA scripting support  LRU eviction of keys  Keys with limited time-to-live  Simple to install, setup and manage  Highly configurable  Supported on many languages  Straightforward and well documented API  Open Source  Available on Azure NoSQL & SQL response performance comparison (from https://redislabs.com/blog/the-proven-redis-performance)
  • 22. Questions  Redis Use Cases  Redis Architecture  Redis Data Types  Redis Commands  Redis Scalability  Redis Topologies Redis Official webpage: http://redis.io Online Demo: http://try.redis.io Source Code: https://github.com/antirez/redis This PPT: http://bit.ly/1N87DJR Redis/Memcached comparison: http://db-engines.com/en/system/Memcached%3BRiak%3BRedis

Editor's Notes

  1. NoSQL: NO RELATIONAL Relational: MySQL, MS-SQL, Oracle, PostgreSQL Analytical (OLAP): MS Analysis Services, Cubes Key-Value: Redis, Memcached Graph: ArangoDB, Neo4j, OrientDB Column-Oriented: MonetDB, HBase Document: MongoDB, CouchDB
  2. Most accepted meaning of NoSQL is Not Only SQL. Because Redis does so much, it's hard to precisely categorise it. It feels substantially different to the other NoSQL software. Performance is Redis's best feature. Mainly due to keeping the entire dataset in memory, and only periodically syncing to disk. Persistence to disk means you can use Redis as a real database instead of just a volatile cache. Redis is like Memcached, but with built-in persistence(snapshotting or journaling to disk), more datatypes, built-in pub/sub, transactions and Lua scripting.
  3. Redis is FAR faster than any RDBMS, but it also can't do as much. If you can map your RDBMS use case to Redis then it might be worth taking a look, but if you can't don't force it.
  4. Highly scalable data store shared by multiple processes, multiple applications, or multiple servers. You can communicate cross-platform, cross-server, or cross-application just as easily makes it a pretty great choice for many use cases. Its speed makes it great as a caching layer. Popular sites using Redis: Twitter, Instagram, Vine, Github, StackOverflow, Pinterest, VMWare, Snapchat, Digg and more…
  5. Redis is primarily an in-memory database. So there's no guarantee that data has actually been written to disk when a Redis command returns. So a server crash is very likely to lose some data (eventual consistency). There are a number of ways in which you can improve durability, generally by trading off performance. >>>>>>>> Download (https://github.com/MSOpenTech/redis/releases), Start Redis-Server, Start redis-cli, Show a couple of commands (SET, GET, EXPIRE, TTL)
  6. Binary-safe strings means that values are essentially byte strings, and can contain any byte (including the null byte). A hash allow compound objects to be stored in a single Redis value. A list works fine as a queue or as a stack, with blocking capabilities. Sorted sets works like a set but each member has an associated score. The set is kept ordered by that score, and range queries are extremely efficient, sorted in either direction. HyperLogLog HyperLogLog provides a good approximation of the cardinality of a set using a very small amount of memory. In Redis it only uses 12kbytes per key to count with a standard error of 0.81%, and there is virtually no limit to the number of items you can count.
  7. redis-cli is definitely the best way of experimenting with Redis. Run without arguments it connects to the local Redis server and provides an interactive prompt. >>>>>>>> Run redis-benchmark
  8. >>>>>>>> Show page http://redis.io/commands
  9. Lists Lists are doubly-linked lists. You can push and pop at both sides, extract range, resize, etc. Random access and ranges at O(N) Hashes Hash tables as values Think of an object store with atomic access to object members
  10. Sets Sets are sets of unique values w/push, pop, etc. Sets can be intersected/diffed/union'ed server side. Sorted sets Same as sets, but with score per element Ranked ranges, aggregation of scores on INTERSECT
  11. Persistence The RDB persistence performs point-in-time snapshots of your dataset at specified intervals. The AOF persistence logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset. It is possible to combine both AOF and RDB in the same instance. In this case, when Redis restarts, the AOF file will be used to reconstruct the original dataset. Replication Slave write mode can be enabled but will be ephemeral (until restart or resync). Slaves provides data redundancy, reads offloading and save-to-disk offloading.
  12. Redis Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention to certain kind of failures. Sentinel processes cooperates for Failure Detection (multiple Sentinels agree about the fact a given master is no longer available). Sentinel works even if not all the Sentinel processes are working, making the system robust against failures.
  13. >>>>>>>> Run the cluster
  14. High-Performance: designed for speed (in-memory, O(1) ops). High-Availability: Sentinel, Cluster, Replication, Partitioning. Fault-Tolerance: Failover mechanisms. (Manual or Automatic). Scalability: Scales down as well as up. It's equally useful for tiny projects as it is for huge services. Portability: Runs on multiple OS and multiple client languages.
  15. Scalability: Persistence, Replication, Partitioning, Clustering Topologies: Standalone, Sentinel, Twemproxy, Cluster