SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Redisfor Java Software Engineers
Copyrights © Moshe Kaplan
moshe.kaplan@brightaqua.com
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Redis
for Java Software Engineers
Moshe Kaplan
Scale Hacker
http://top-performance.blogspot.com
http://blogs.microsoft.co.il/vprnd
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
About Me: It’s all About
3
Scale
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
NOSQL MARKET
Introduction
4
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
When Should I Choose NoSQL?
• Eventually Consistent
• Document Store
• Key Value
5
http://guyharrison.squarespace.com/blog/tag/nosq
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Key Value Store
• insert
• get
• multiget
• remove
• truncate
6
<Key, Value>
http://wiki.apache.org/cassandra/API
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Redis
• Very simple protocol (SMTP like)
• Amazing Performance (60Kqps ops on 1 CPU machine)
• Persistency to disk
• Very little security
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
HELLO. MY NAME IS REDIS
Introduction
8
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
9
#10 Most Popular DB Engine
http://db-engines.com/en/ranking
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Who is Using Redis?
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Who is Behind Redis
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Installation: Give Yourself 5min
• sudo apt-get install -y build-essential tcl8.5
• wget http://download.redis.io/releases/redis-stable.tar.gz
• tar xzf redis-stable.tar.gz
• cd redis-stable
• make
• sudo make install
• cd utils
• sudo ./install_server.sh
• sudo service redis_6379 start
• redis-cli
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Redis and Data Models
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Redis Data Models
Data Types What?
Binary-safe strings Strings
Lists Strings List
Sets Unique unsorted strings
Sorted Sets Score field
Hashes O(1)
Bit Arrays/Bitmaps Bit operations on set
HyperLogLogs Estimate set cardinality
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Key Design
• Keep keys short
• But not too short (readable, existing overhead)
• Use Convention:
• comment:1234:reply.to
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Sets
simple storage
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Basic Sets
> SET counter 100
OK
> GET counter
(integer) 100
> inc counter
(integer) 101
> incby counter 50
(integer) 151
DECR DECRBY
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Multi Set
> MSET counter 100 cnt2 102 cnt3 103
OK
> MGET counter cnt2 cnt 3
(integer) 100
(integer) 102
(integer) 103
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Existence
> exists counter
(integer) 1
> type counter
integer
> del counter
(integer) 1
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
TTL Keys
> expire counter 5
(integer) 1
> set cnt2 ex 5
OK
> ttl cnt
5
> persist cnt2
OK
Will Expire in 5 secondsWill Expire in 5 seconds
Will Expire in 5 secondsWill Expire in 5 seconds
How much time was left?How much time was left?
Remove TTLRemove TTL
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Linked Lists
a basis for queues
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Existence
> Adding/Removing for end/start: O(1)
> Getting other items: O(N)
LPUSH/RPUSH => Add items (Head/Tail)
LPOP/RPOP => Take items (Head/Tail)
LRANGE/RRANGE => Get items (Head/Tail)
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Blocking Operations
Best for Producer/Consumer (Q)
If list is empty,calls are blocked
> BRPOP <LIST> <# of Seconds>
> BLPOP <LIST> <# of Seconds>
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Capped Lists
Define how many items we want to have
> LPUSH mylist <some element>
> LTRIM mylist 0 999
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Hashes
a column like data store
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Existence
> hmset user:1000 username antirez birthyear 1977
OK
> hget user:1000 username
"antirez"
> hget user:1000 birthyear
"1977"
> hgetall user:1000
1) "username"
2) "antirez"
3) "birthyear"
4) "1977"
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Sets
a basis for social and permissions
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Set Ops
> sismember myset 3
(integer) 1
> sadd news:1000:tags 1 2 5 77
(integer) 4
> sadd tag:1:news 1000
(integer) 1
> sinter news:1000:tags news:2000:tags
,,,,
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Ordered Sets (Z)
A leader board solution
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Set Ops
> zadd hackers 1940 "Alan Kay"
(integer) 1
> zadd hackers 1957 "Sophie Wilson"
(integer 1)
> zrange hackers 0 -1
> zremrangebyscore hackers 1940 1960
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
BitMaps
Efficient Configuration and
Permissions
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Set Ops
> setbit key 10 1
(integer) 1
> getbit key 10
(integer) 1
> bitcount key
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Advanced Operations
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Scan: You can iterate all keys!
Scan
SScan
HScan
ZScan
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Lua Scripting: You have script engine
> eval "return redis.call('set','foo','bar')" 0
OK
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Pub/Sub
Very nice tool, but not as good as Kafka and RabbitMQ
SUBSCRIBE first second
PUBLISH second Hello
UNSUBSCRIBE
PSUBSCRIBE news.*
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Sorting
SORT mylist
SORT mylist DESC
SORT mylist ALPHA
SORT mylist BY weight_*
SORT mylist BY nosort
SORT mylist BY weight_* GET object_*
SORT mylist BY weight_* GET object_* GET #
SORT mylist BY weight_* STORE resultkey
SORT mylist BY weight_*->fieldname GET object_*->fieldname
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Transactions
1. Atomic
2. Blocking all other operations
3. All or Nothing
MULTI: Start transaction
EXEC: Commit
DISCARD: “Roll back” (only before EXEC, nothing done)
WATCH: Don’t use in multi client (race conditions)
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Transaction by Example
> MULTI
OK
> INCR foo
QUEUED
> INCR bar
QUEUED
> EXEC
1) (integer) 1
2) (integer) 1
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Java Programming
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Many Options
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Securing Redis
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Authentication
• By default: None
• Enable: requirepass in the config file
• Authenticate: AUTH <PASSWORD>
• Simple, Clear text
• No measures to prevent brute force
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Communication Encryption
• SSL Communication encryption using stunnel/spiped
• Webdis web front layer
• Encrypt the data in the app level
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Persistency
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
The Good, bad and Evil
• RDB
• Point in time snapshots
• Backup before critical operation
• AOF
• On every write to log (or once a seocnd)
• Log rerun at startup
• None
• In memory only solution
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
CACHING
47
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Don’t Use Caching
48
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
If You Have To
49
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Invalidation Can Be Nightmare
50
http://luauf.com/2009/06/08/%C2%BFque-es-memcac
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Geo Load Balancing Can be Worse
51
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Finally, Recovery May Not Be Better
52
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
KISS
53
http://marriagelifeministries.org/?p=962
© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers
Thank You !
Moshe Kaplan
moshe.kaplan@brightaqua.com
054-2291978

Weitere ähnliche Inhalte

Was ist angesagt?

Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012
Julien Pivotto
 
Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013
Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013
Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013
Everett Toews
 

Was ist angesagt? (15)

Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012
 
wolfSSL Performance Improvements 2018
wolfSSL Performance Improvements 2018wolfSSL Performance Improvements 2018
wolfSSL Performance Improvements 2018
 
The Future of Adhearson
The Future of AdhearsonThe Future of Adhearson
The Future of Adhearson
 
Paris Container Day 2016 : Etcd - overview and future (CoreOS)
Paris Container Day 2016 : Etcd - overview and future (CoreOS)Paris Container Day 2016 : Etcd - overview and future (CoreOS)
Paris Container Day 2016 : Etcd - overview and future (CoreOS)
 
Introducing Project Longhorn - April 2016 Rancher Online Meetup
Introducing Project Longhorn - April 2016 Rancher Online MeetupIntroducing Project Longhorn - April 2016 Rancher Online Meetup
Introducing Project Longhorn - April 2016 Rancher Online Meetup
 
DSR Microservices (Day 1, Part 1)
DSR Microservices (Day 1, Part 1)DSR Microservices (Day 1, Part 1)
DSR Microservices (Day 1, Part 1)
 
Hadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoopHadoop Summit 2013 : Continuous Integration on top of hadoop
Hadoop Summit 2013 : Continuous Integration on top of hadoop
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Code Reviews vs. Pull Requests
Code Reviews vs. Pull RequestsCode Reviews vs. Pull Requests
Code Reviews vs. Pull Requests
 
Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013
Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013
Solve the Cross-Cloud Conundrum with jclouds at Gluecon 2013
 
[124] mit cheetah 로봇의 탄생
[124] mit cheetah 로봇의 탄생[124] mit cheetah 로봇의 탄생
[124] mit cheetah 로봇의 탄생
 
Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)
 
Blazing Fast Feedback Loops in the Java Universe
Blazing Fast Feedback Loops in the Java UniverseBlazing Fast Feedback Loops in the Java Universe
Blazing Fast Feedback Loops in the Java Universe
 
Immutable infrastructure:觀念與實作 (建議)
Immutable infrastructure:觀念與實作 (建議)Immutable infrastructure:觀念與實作 (建議)
Immutable infrastructure:觀念與實作 (建議)
 
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStackSaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
SaltConf14 - Oz Akan, Rackspace - Deploying OpenStack Marconi with SaltStack
 

Andere mochten auch

Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
Theo Jungeblut
 

Andere mochten auch (12)

Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...Clean Code - How to write comprehensible code regarding cognitive abilities o...
Clean Code - How to write comprehensible code regarding cognitive abilities o...
 
Empathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible codeEmpathic Programming - How to write comprehensible code
Empathic Programming - How to write comprehensible code
 
Writing beautiful code with Java 8
Writing beautiful code with Java 8Writing beautiful code with Java 8
Writing beautiful code with Java 8
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
 
Clean Code (Presentacion interna en Virtual Software)
Clean Code (Presentacion interna en Virtual Software)Clean Code (Presentacion interna en Virtual Software)
Clean Code (Presentacion interna en Virtual Software)
 
Clean Code
Clean CodeClean Code
Clean Code
 
OOP Basics
OOP BasicsOOP Basics
OOP Basics
 
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
Java data structures powered by Redis. Introduction to Redisson @ Redis Light...
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean code
Clean codeClean code
Clean code
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 

Ähnlich wie Redis training for java software engineers

6° Sessione Oracle - CRUI: Oracle Database Appliance: Il potere dell’ingegner...
6° Sessione Oracle - CRUI: Oracle Database Appliance:Il potere dell’ingegner...6° Sessione Oracle - CRUI: Oracle Database Appliance:Il potere dell’ingegner...
6° Sessione Oracle - CRUI: Oracle Database Appliance: Il potere dell’ingegner...
Jürgen Ambrosi
 

Ähnlich wie Redis training for java software engineers (20)

MongoDB training for java software engineers
MongoDB training for java software engineersMongoDB training for java software engineers
MongoDB training for java software engineers
 
MongoDB from Basics to Scale
MongoDB from Basics to ScaleMongoDB from Basics to Scale
MongoDB from Basics to Scale
 
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
Full Speed Ahead! (Ahead-of-Time Compilation for Java SE) [JavaOne 2017 CON3738]
 
20190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev220190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev2
 
Understanding the impact of Linux scheduler on your application
Understanding the impact of Linux scheduler on your applicationUnderstanding the impact of Linux scheduler on your application
Understanding the impact of Linux scheduler on your application
 
Streaming solutions for real time problems
Streaming solutions for real time problems Streaming solutions for real time problems
Streaming solutions for real time problems
 
MongoDB Best Practices for Developers
MongoDB Best Practices for DevelopersMongoDB Best Practices for Developers
MongoDB Best Practices for Developers
 
Cloud Native Java:GraalVM
Cloud Native Java:GraalVMCloud Native Java:GraalVM
Cloud Native Java:GraalVM
 
Cloud Native 자바 플랫폼: Graalvm Overview
Cloud Native 자바 플랫폼: Graalvm OverviewCloud Native 자바 플랫폼: Graalvm Overview
Cloud Native 자바 플랫폼: Graalvm Overview
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
Everything You Wanted to Know About JIT Compilation but Were Afraid to Ask [J...
 
IIMB presentation
IIMB presentationIIMB presentation
IIMB presentation
 
6 Tips to MySQL Performance Tuning
6 Tips to MySQL Performance Tuning6 Tips to MySQL Performance Tuning
6 Tips to MySQL Performance Tuning
 
Change Management for Oracle Database with SQLcl
Change Management for Oracle Database with SQLcl Change Management for Oracle Database with SQLcl
Change Management for Oracle Database with SQLcl
 
Getting Started with JDK Mission Control
Getting Started with JDK Mission ControlGetting Started with JDK Mission Control
Getting Started with JDK Mission Control
 
1 Million Writes per second on 60 nodes with Cassandra and EBS
1 Million Writes per second on 60 nodes with Cassandra and EBS1 Million Writes per second on 60 nodes with Cassandra and EBS
1 Million Writes per second on 60 nodes with Cassandra and EBS
 
Install Redis on Oracle Linux
Install Redis on Oracle LinuxInstall Redis on Oracle Linux
Install Redis on Oracle Linux
 
Ongoing management of your PHP 7 application
Ongoing management of your PHP 7 applicationOngoing management of your PHP 7 application
Ongoing management of your PHP 7 application
 
Is An Agile Standard Possible For Java?
Is An Agile Standard Possible For Java?Is An Agile Standard Possible For Java?
Is An Agile Standard Possible For Java?
 
6° Sessione Oracle - CRUI: Oracle Database Appliance: Il potere dell’ingegner...
6° Sessione Oracle - CRUI: Oracle Database Appliance:Il potere dell’ingegner...6° Sessione Oracle - CRUI: Oracle Database Appliance:Il potere dell’ingegner...
6° Sessione Oracle - CRUI: Oracle Database Appliance: Il potere dell’ingegner...
 

Mehr von Moshe Kaplan

Web systems architecture, Performance and More
Web systems architecture, Performance and MoreWeb systems architecture, Performance and More
Web systems architecture, Performance and More
Moshe Kaplan
 
mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
Moshe Kaplan
 

Mehr von Moshe Kaplan (20)

Spark and C Integration
Spark and C IntegrationSpark and C Integration
Spark and C Integration
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Introduciton to Python
Introduciton to PythonIntroduciton to Python
Introduciton to Python
 
Creating Big Data: Methodology
Creating Big Data: MethodologyCreating Big Data: Methodology
Creating Big Data: Methodology
 
The api economy
The api economyThe api economy
The api economy
 
Big Data Workshop
Big Data WorkshopBig Data Workshop
Big Data Workshop
 
Scale and Cloud Design Patterns
Scale and Cloud Design PatternsScale and Cloud Design Patterns
Scale and Cloud Design Patterns
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Web systems architecture, Performance and More
Web systems architecture, Performance and MoreWeb systems architecture, Performance and More
Web systems architecture, Performance and More
 
Do Big Data and NoSQL Fit Your Needs?
Do Big Data and NoSQL Fit Your Needs?Do Big Data and NoSQL Fit Your Needs?
Do Big Data and NoSQL Fit Your Needs?
 
The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...
The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...
The VP R&D Open Seminar on Project Management, SCRUM, Agile and Continuous De...
 
MySQL Multi Master Replication
MySQL Multi Master ReplicationMySQL Multi Master Replication
MySQL Multi Master Replication
 
mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
 
Web Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe KaplanWeb Systems Architecture by Moshe Kaplan
Web Systems Architecture by Moshe Kaplan
 
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuffBig Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
Big Data Seminar: Analytics, Hadoop, Map Reduce, Mongo and other great stuff
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplan
 
VP R&D Open Seminar: Caching
VP R&D Open Seminar: CachingVP R&D Open Seminar: Caching
VP R&D Open Seminar: Caching
 
Expert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project ManagementExpert Days: The VP R&D Open Seminar: Project Management
Expert Days: The VP R&D Open Seminar: Project Management
 
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
Expert Days 2011: The VP R&D Open Seminar: Systems Performance Seminar
 
Database2011 MySQL Sharding
Database2011 MySQL ShardingDatabase2011 MySQL Sharding
Database2011 MySQL Sharding
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Redis training for java software engineers

  • 1. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Redisfor Java Software Engineers Copyrights © Moshe Kaplan moshe.kaplan@brightaqua.com
  • 2. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Redis for Java Software Engineers Moshe Kaplan Scale Hacker http://top-performance.blogspot.com http://blogs.microsoft.co.il/vprnd
  • 3. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers About Me: It’s all About 3 Scale
  • 4. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers NOSQL MARKET Introduction 4
  • 5. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers When Should I Choose NoSQL? • Eventually Consistent • Document Store • Key Value 5 http://guyharrison.squarespace.com/blog/tag/nosq
  • 6. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Key Value Store • insert • get • multiget • remove • truncate 6 <Key, Value> http://wiki.apache.org/cassandra/API
  • 7. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Redis • Very simple protocol (SMTP like) • Amazing Performance (60Kqps ops on 1 CPU machine) • Persistency to disk • Very little security
  • 8. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers HELLO. MY NAME IS REDIS Introduction 8
  • 9. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers 9 #10 Most Popular DB Engine http://db-engines.com/en/ranking
  • 10. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Who is Using Redis?
  • 11. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Who is Behind Redis
  • 12. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Installation: Give Yourself 5min • sudo apt-get install -y build-essential tcl8.5 • wget http://download.redis.io/releases/redis-stable.tar.gz • tar xzf redis-stable.tar.gz • cd redis-stable • make • sudo make install • cd utils • sudo ./install_server.sh • sudo service redis_6379 start • redis-cli
  • 13. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Redis and Data Models
  • 14. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Redis Data Models Data Types What? Binary-safe strings Strings Lists Strings List Sets Unique unsorted strings Sorted Sets Score field Hashes O(1) Bit Arrays/Bitmaps Bit operations on set HyperLogLogs Estimate set cardinality
  • 15. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Key Design • Keep keys short • But not too short (readable, existing overhead) • Use Convention: • comment:1234:reply.to
  • 16. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Sets simple storage
  • 17. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Basic Sets > SET counter 100 OK > GET counter (integer) 100 > inc counter (integer) 101 > incby counter 50 (integer) 151 DECR DECRBY
  • 18. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Multi Set > MSET counter 100 cnt2 102 cnt3 103 OK > MGET counter cnt2 cnt 3 (integer) 100 (integer) 102 (integer) 103
  • 19. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Existence > exists counter (integer) 1 > type counter integer > del counter (integer) 1
  • 20. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers TTL Keys > expire counter 5 (integer) 1 > set cnt2 ex 5 OK > ttl cnt 5 > persist cnt2 OK Will Expire in 5 secondsWill Expire in 5 seconds Will Expire in 5 secondsWill Expire in 5 seconds How much time was left?How much time was left? Remove TTLRemove TTL
  • 21. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Linked Lists a basis for queues
  • 22. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Existence > Adding/Removing for end/start: O(1) > Getting other items: O(N) LPUSH/RPUSH => Add items (Head/Tail) LPOP/RPOP => Take items (Head/Tail) LRANGE/RRANGE => Get items (Head/Tail)
  • 23. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Blocking Operations Best for Producer/Consumer (Q) If list is empty,calls are blocked > BRPOP <LIST> <# of Seconds> > BLPOP <LIST> <# of Seconds>
  • 24. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Capped Lists Define how many items we want to have > LPUSH mylist <some element> > LTRIM mylist 0 999
  • 25. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Hashes a column like data store
  • 26. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Existence > hmset user:1000 username antirez birthyear 1977 OK > hget user:1000 username "antirez" > hget user:1000 birthyear "1977" > hgetall user:1000 1) "username" 2) "antirez" 3) "birthyear" 4) "1977"
  • 27. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Sets a basis for social and permissions
  • 28. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Set Ops > sismember myset 3 (integer) 1 > sadd news:1000:tags 1 2 5 77 (integer) 4 > sadd tag:1:news 1000 (integer) 1 > sinter news:1000:tags news:2000:tags ,,,,
  • 29. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Ordered Sets (Z) A leader board solution
  • 30. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Set Ops > zadd hackers 1940 "Alan Kay" (integer) 1 > zadd hackers 1957 "Sophie Wilson" (integer 1) > zrange hackers 0 -1 > zremrangebyscore hackers 1940 1960
  • 31. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers BitMaps Efficient Configuration and Permissions
  • 32. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Set Ops > setbit key 10 1 (integer) 1 > getbit key 10 (integer) 1 > bitcount key
  • 33. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Advanced Operations
  • 34. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Scan: You can iterate all keys! Scan SScan HScan ZScan
  • 35. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Lua Scripting: You have script engine > eval "return redis.call('set','foo','bar')" 0 OK
  • 36. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Pub/Sub Very nice tool, but not as good as Kafka and RabbitMQ SUBSCRIBE first second PUBLISH second Hello UNSUBSCRIBE PSUBSCRIBE news.*
  • 37. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Sorting SORT mylist SORT mylist DESC SORT mylist ALPHA SORT mylist BY weight_* SORT mylist BY nosort SORT mylist BY weight_* GET object_* SORT mylist BY weight_* GET object_* GET # SORT mylist BY weight_* STORE resultkey SORT mylist BY weight_*->fieldname GET object_*->fieldname
  • 38. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Transactions 1. Atomic 2. Blocking all other operations 3. All or Nothing MULTI: Start transaction EXEC: Commit DISCARD: “Roll back” (only before EXEC, nothing done) WATCH: Don’t use in multi client (race conditions)
  • 39. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Transaction by Example > MULTI OK > INCR foo QUEUED > INCR bar QUEUED > EXEC 1) (integer) 1 2) (integer) 1
  • 40. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Java Programming
  • 41. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Many Options
  • 42. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Securing Redis
  • 43. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Authentication • By default: None • Enable: requirepass in the config file • Authenticate: AUTH <PASSWORD> • Simple, Clear text • No measures to prevent brute force
  • 44. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Communication Encryption • SSL Communication encryption using stunnel/spiped • Webdis web front layer • Encrypt the data in the app level
  • 45. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Persistency
  • 46. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers The Good, bad and Evil • RDB • Point in time snapshots • Backup before critical operation • AOF • On every write to log (or once a seocnd) • Log rerun at startup • None • In memory only solution
  • 47. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers CACHING 47
  • 48. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Don’t Use Caching 48
  • 49. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers If You Have To 49
  • 50. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Invalidation Can Be Nightmare 50 http://luauf.com/2009/06/08/%C2%BFque-es-memcac
  • 51. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Geo Load Balancing Can be Worse 51
  • 52. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Finally, Recovery May Not Be Better 52
  • 53. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers KISS 53 http://marriagelifeministries.org/?p=962
  • 54. © All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers© All rights reserved: Moshe Kaplan© All rights reserved: Moshe Kaplan Redis for Java Software Engineers Thank You ! Moshe Kaplan moshe.kaplan@brightaqua.com 054-2291978