SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
... perhaps the fastest NoSQL database in the world
What is Redis? 
Remote Dictionary Server 
●Often described as Key / Value NoSQL database 
●Better description: Data structures server 
●"Swiss Army Knife", collection of small useful data structures
Redis most important feature: High performance 
●In-memory database 
●Small codebase (20000 lines), native C 
●Connection via TCP or UNIX socket (no REST interface) 
●Limited choice of key mappings (5 types, 2 special types) 
●No nested data structures
More Redis features: 
●Persistence via Snapshotting and/or Journalling 
●Master/Slave chain database replication 
●Sentinel server monitoring 
●For real clustering -> redis-cluster project (beta, not production-ready yet) 
●Keys can have expiry time 
●Publish / Subscribe system
Sounds cool, but what are the Use Cases? 
●memcached++ 
●Statistics collection (downloads, hits, dwell times ...) 
●Log buffers 
●Task queues 
●Share state between processes (common 'blackboard') 
●Inter-process communication (channels)
Starting up Redis (on Debian) ... 
●Start the server:$> /etc/init.d/redis-server start 
●Configuration in: /etc/redis/redis.conf 
●Log files in:/var/log/redis/redis-server.log 
●Database dumps:/var/lib/redis/dump.rdb 
●Journal:/var/lib/redis/appendonly.aof
Accessing Redis ... 
●Command line tool:$> redis-cli 
●Socket access:$> telnet <redishost> 6379 
●Libraries: 
●redis-py (Python) 
●redis-rb (Ruby) 
●hiredis (C) 
●Jedis(Java) 
●... and many more (http://redis.io/clients)
More Redis tools ... 
●Benchmarking tool: $> redis-benchmark 
●Database consistency check: $> redis-check-dump <database dump> 
●Journal consistency check: $> redis-check-aof <aof file>
General commands: 
redis> PING# Check server connection 
PONG 
redis> INFO# Get server information 
# Server 
redis_version:2.8.13 
[...] 
redis> HELP # Command help 
[...] 
redis> SELECT 0# Select database #no 
OK 
redis> FLUSHDB# Clear current database 
OK 
redis> SHUTDOWN# Shutdown the server 
redis> QUIT# Quit the session
Redis stores data in key / value pairs, <value> one of: 
●String 
●Hash 
●List 
●Set 
●Sorted Set 
and two special structures (derivative of String): 
●Bitmaps 
●HyperLogLogs
Basic key / value pairs ('Strings') : 
redis> SET currentuser Max 
OK 
redis> GET currentuser 
"Max" 
redis> SET count 1 
OK 
redis> INCR count 
(integer) 2 
redis> GET count 
"2"
Hashes: 
redis> HSET users:123 name Max 
(integer) 1 
redis> HSET users:123 password Super_secret 
(integer) 1 
redis> HGET users:123 name 
"Max" 
redis> HGET users:123 password 
"Super_secret" 
redis> HKEYS users:123 
1) "name" 
2) "password"
Lists: 
redis> RPUSH users Max John Peter 
(integer) 3 
redis> LLEN users 
(integer) 3 
redis> LRANGE users 0 -1 
1) "Max" 
2) "John" 
3) "Peter" 
redis> LPOP users 
"Max" 
redis> LINDEX users 1 
"Peter"
Sets: 
redis> SADD favorites:news BBC NYT Wired 
(integer) 3 
redis> SADD favorites:tech Wired Heise 
(integer) 2 
redis> SINTER favorites:tech favorites:news 
1) "Wired" 
redis> SUNION favorites:tech favorites:news 
1) "Heise" 
2) "Wired" 
3) "NYT" 
4) "BBC"
Sorted Sets: (Entries sorted by Score) 
redis> ZADD favorites 15 BBC 10 NYT 80 Heise 50 Wired 
(integer) 4 
redis> ZSCORE favorites NYT 
"10" 
redis> ZRANGEBYSCORE favorites 40 inf 
1) "Wired" 
2) "Heise"
Key expiry: 
redis> SET icecream "Like ice in the sunshine" 
OK 
redis> EXPIRE icecream 20 
(integer) 1 
[... after 6 seconds ...] 
redis> TTL icecream 
(integer) 14 
redis> GET icecream 
"Like ice in the sunshine" 
[... after half a minute ...] 
redis> TTL icecream 
(integer) -1 
redis> GET icecream 
(nil)
Publish / Subscribe: 
redis> SUBSCRIBE channel 
Reading messages... (press Ctrl-C to quit) 
1) "subscribe" 
2) "channel" 
3) (integer) 1 
[...] 
1) "message" 
2) "channel" 
3) "Hi there!" 
redis> PUBSUB CHANNELS 
1) "channel" 
[...] 
redis> PUBLISH channel "Hi there!" 
(integer) 1 
Subscriber 
Publisher 
1 
2 
3 
4
Bitmaps: 
redis> SET bitkey "xff" 
OK 
redis> SETBIT bitkey 4 0 
(integer) 1 
redis> GET bitkey 
"xf7" 
redis> BITCOUNT bitkey 
(integer) 7
Lua scripting: 
-- usernames.lua 
-- Get field "name" from all users 
local users = redis.call('KEYS', 'users:*') 
local names = {} 
for num,key in ipairs(users) do 
names[num] = redis.call('HGET', key, 'name') 
end 
return names 
$> redis-cli EVAL "$(cat usernames.lua)" 0
Hyperloglogs: 
(approximate cardinality of huge sets with small memory demand) 
redis> PFADD hll a b c d a a 
(integer) 1 
redis> PFCOUNT hll 
(integer) 4 
redid> PFADD hll a a a a a 
(integer) 0 
redis> PFCOUNT hll 
(integer) 4
Master / Slave DB replication: 
$> redis-server --port 6380 --slaveof localhost 6379 --dbfilename dumpslave.rdb 
Master@localhost:6379 
Slave@localhost:6380 
dump.rdb 
dumpslave.rdb
Redis homepage: 
●www.redis.io 
Books: 
●The little Book of Redis (free) 
●Redis in Action (Manning) 
●Redis Cookbook (O'Reilly)
Questions from the SoCraTes 2014 session: (and my attempts at an answer, please feel free to correct) 
●Is it possible to access sets via wildcards? -> Doesn't seem so. Looks like only the KEYS command accepts wildcards. 
●Is there a performance penalty when accessing different database numbers? -> Didn't find anything, but there shouldn't be any significant penalty.
Questions from the SoCraTes 2014 session (cont.): (and my attempts at an answer, please feel free to correct) 
●Is there a mechanism to notify a client when a key is changed? -> Yes, 2.8 introduced Keyspace Notifications, see: http://redis.io/topics/notifications

Contenu connexe

Tendances

Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2Dvir Volk
 
Redis And python at pycon_2011
Redis And python at pycon_2011Redis And python at pycon_2011
Redis And python at pycon_2011sunilar0ra
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with ModulesItamar Haber
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisKnoldus Inc.
 
Caching solutions with Redis
Caching solutions   with RedisCaching solutions   with Redis
Caching solutions with RedisGeorge Platon
 
Riak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup GroupRiak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup Groupsiculars
 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101Dvir Volk
 
glance replicator
glance replicatorglance replicator
glance replicatoririx_jp
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)Felix Geisendörfer
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
Cassandra summit 2013 - DataStax Java Driver Unleashed!
Cassandra summit 2013 - DataStax Java Driver Unleashed!Cassandra summit 2013 - DataStax Java Driver Unleashed!
Cassandra summit 2013 - DataStax Java Driver Unleashed!Michaël Figuière
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examplesTerry Cho
 

Tendances (20)

Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Redis And python at pycon_2011
Redis And python at pycon_2011Redis And python at pycon_2011
Redis And python at pycon_2011
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with Modules
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Caching solutions with Redis
Caching solutions   with RedisCaching solutions   with Redis
Caching solutions with Redis
 
Hanganalyze presentation
Hanganalyze presentationHanganalyze presentation
Hanganalyze presentation
 
Riak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup GroupRiak at The NYC Cloud Computing Meetup Group
Riak at The NYC Cloud Computing Meetup Group
 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101
 
glance replicator
glance replicatorglance replicator
glance replicator
 
Django cryptography
Django cryptographyDjango cryptography
Django cryptography
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
Node.js in production
Node.js in productionNode.js in production
Node.js in production
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Cassandra summit 2013 - DataStax Java Driver Unleashed!
Cassandra summit 2013 - DataStax Java Driver Unleashed!Cassandra summit 2013 - DataStax Java Driver Unleashed!
Cassandra summit 2013 - DataStax Java Driver Unleashed!
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examples
 
Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3Nodejs - A-quick-tour-v3
Nodejs - A-quick-tour-v3
 
Node.js - A Quick Tour II
Node.js - A Quick Tour IINode.js - A Quick Tour II
Node.js - A Quick Tour II
 

Similaire à Redis SoCraTes 2014

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
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuRedis Labs
 
Session Control @ nolinux day
Session Control  @ nolinux daySession Control  @ nolinux day
Session Control @ nolinux dayWalter Traspadini
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redisTanu Siwag
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisRizky Abdilah
 
mar07-redis.pdf
mar07-redis.pdfmar07-redis.pdf
mar07-redis.pdfAnisSalhi3
 
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
 
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...Insight Technology, Inc.
 
quickguide-einnovator-10-redis-admin
quickguide-einnovator-10-redis-adminquickguide-einnovator-10-redis-admin
quickguide-einnovator-10-redis-adminjorgesimao71
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced ReplicationMongoDB
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamCodemotion
 
Redis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRedis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRoberto Franchini
 
Redhat 6 & 7
Redhat 6 & 7Redhat 6 & 7
Redhat 6 & 7r9social
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisItamar Haber
 
Introducing redis
Introducing redisIntroducing redis
Introducing redisNuno Caneco
 

Similaire à Redis SoCraTes 2014 (20)

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
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
Redis introduction
Redis introductionRedis introduction
Redis introduction
 
Session Control @ nolinux day
Session Control  @ nolinux daySession Control  @ nolinux day
Session Control @ nolinux day
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redis
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis acc
Redis accRedis acc
Redis acc
 
mar07-redis.pdf
mar07-redis.pdfmar07-redis.pdf
mar07-redis.pdf
 
Developing a Redis Module - Hackathon Kickoff
 Developing a Redis Module - Hackathon Kickoff Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon Kickoff
 
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
[db tech showcase Tokyo 2017] C23: Lessons from SQLite4 by SQLite.org - Richa...
 
Mini-Training: Redis
Mini-Training: RedisMini-Training: Redis
Mini-Training: Redis
 
Redis by-hari
Redis by-hariRedis by-hari
Redis by-hari
 
quickguide-einnovator-10-redis-admin
quickguide-einnovator-10-redis-adminquickguide-einnovator-10-redis-admin
quickguide-einnovator-10-redis-admin
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Redis begins
Redis beginsRedis begins
Redis begins
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time stream
 
Redis for duplicate detection on real time stream
Redis for duplicate detection on real time streamRedis for duplicate detection on real time stream
Redis for duplicate detection on real time stream
 
Redhat 6 & 7
Redhat 6 & 7Redhat 6 & 7
Redhat 6 & 7
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Introducing redis
Introducing redisIntroducing redis
Introducing redis
 

Dernier

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Redis SoCraTes 2014

  • 1. ... perhaps the fastest NoSQL database in the world
  • 2. What is Redis? Remote Dictionary Server ●Often described as Key / Value NoSQL database ●Better description: Data structures server ●"Swiss Army Knife", collection of small useful data structures
  • 3. Redis most important feature: High performance ●In-memory database ●Small codebase (20000 lines), native C ●Connection via TCP or UNIX socket (no REST interface) ●Limited choice of key mappings (5 types, 2 special types) ●No nested data structures
  • 4. More Redis features: ●Persistence via Snapshotting and/or Journalling ●Master/Slave chain database replication ●Sentinel server monitoring ●For real clustering -> redis-cluster project (beta, not production-ready yet) ●Keys can have expiry time ●Publish / Subscribe system
  • 5. Sounds cool, but what are the Use Cases? ●memcached++ ●Statistics collection (downloads, hits, dwell times ...) ●Log buffers ●Task queues ●Share state between processes (common 'blackboard') ●Inter-process communication (channels)
  • 6. Starting up Redis (on Debian) ... ●Start the server:$> /etc/init.d/redis-server start ●Configuration in: /etc/redis/redis.conf ●Log files in:/var/log/redis/redis-server.log ●Database dumps:/var/lib/redis/dump.rdb ●Journal:/var/lib/redis/appendonly.aof
  • 7. Accessing Redis ... ●Command line tool:$> redis-cli ●Socket access:$> telnet <redishost> 6379 ●Libraries: ●redis-py (Python) ●redis-rb (Ruby) ●hiredis (C) ●Jedis(Java) ●... and many more (http://redis.io/clients)
  • 8. More Redis tools ... ●Benchmarking tool: $> redis-benchmark ●Database consistency check: $> redis-check-dump <database dump> ●Journal consistency check: $> redis-check-aof <aof file>
  • 9. General commands: redis> PING# Check server connection PONG redis> INFO# Get server information # Server redis_version:2.8.13 [...] redis> HELP # Command help [...] redis> SELECT 0# Select database #no OK redis> FLUSHDB# Clear current database OK redis> SHUTDOWN# Shutdown the server redis> QUIT# Quit the session
  • 10. Redis stores data in key / value pairs, <value> one of: ●String ●Hash ●List ●Set ●Sorted Set and two special structures (derivative of String): ●Bitmaps ●HyperLogLogs
  • 11. Basic key / value pairs ('Strings') : redis> SET currentuser Max OK redis> GET currentuser "Max" redis> SET count 1 OK redis> INCR count (integer) 2 redis> GET count "2"
  • 12. Hashes: redis> HSET users:123 name Max (integer) 1 redis> HSET users:123 password Super_secret (integer) 1 redis> HGET users:123 name "Max" redis> HGET users:123 password "Super_secret" redis> HKEYS users:123 1) "name" 2) "password"
  • 13. Lists: redis> RPUSH users Max John Peter (integer) 3 redis> LLEN users (integer) 3 redis> LRANGE users 0 -1 1) "Max" 2) "John" 3) "Peter" redis> LPOP users "Max" redis> LINDEX users 1 "Peter"
  • 14. Sets: redis> SADD favorites:news BBC NYT Wired (integer) 3 redis> SADD favorites:tech Wired Heise (integer) 2 redis> SINTER favorites:tech favorites:news 1) "Wired" redis> SUNION favorites:tech favorites:news 1) "Heise" 2) "Wired" 3) "NYT" 4) "BBC"
  • 15. Sorted Sets: (Entries sorted by Score) redis> ZADD favorites 15 BBC 10 NYT 80 Heise 50 Wired (integer) 4 redis> ZSCORE favorites NYT "10" redis> ZRANGEBYSCORE favorites 40 inf 1) "Wired" 2) "Heise"
  • 16. Key expiry: redis> SET icecream "Like ice in the sunshine" OK redis> EXPIRE icecream 20 (integer) 1 [... after 6 seconds ...] redis> TTL icecream (integer) 14 redis> GET icecream "Like ice in the sunshine" [... after half a minute ...] redis> TTL icecream (integer) -1 redis> GET icecream (nil)
  • 17. Publish / Subscribe: redis> SUBSCRIBE channel Reading messages... (press Ctrl-C to quit) 1) "subscribe" 2) "channel" 3) (integer) 1 [...] 1) "message" 2) "channel" 3) "Hi there!" redis> PUBSUB CHANNELS 1) "channel" [...] redis> PUBLISH channel "Hi there!" (integer) 1 Subscriber Publisher 1 2 3 4
  • 18. Bitmaps: redis> SET bitkey "xff" OK redis> SETBIT bitkey 4 0 (integer) 1 redis> GET bitkey "xf7" redis> BITCOUNT bitkey (integer) 7
  • 19. Lua scripting: -- usernames.lua -- Get field "name" from all users local users = redis.call('KEYS', 'users:*') local names = {} for num,key in ipairs(users) do names[num] = redis.call('HGET', key, 'name') end return names $> redis-cli EVAL "$(cat usernames.lua)" 0
  • 20. Hyperloglogs: (approximate cardinality of huge sets with small memory demand) redis> PFADD hll a b c d a a (integer) 1 redis> PFCOUNT hll (integer) 4 redid> PFADD hll a a a a a (integer) 0 redis> PFCOUNT hll (integer) 4
  • 21. Master / Slave DB replication: $> redis-server --port 6380 --slaveof localhost 6379 --dbfilename dumpslave.rdb Master@localhost:6379 Slave@localhost:6380 dump.rdb dumpslave.rdb
  • 22. Redis homepage: ●www.redis.io Books: ●The little Book of Redis (free) ●Redis in Action (Manning) ●Redis Cookbook (O'Reilly)
  • 23. Questions from the SoCraTes 2014 session: (and my attempts at an answer, please feel free to correct) ●Is it possible to access sets via wildcards? -> Doesn't seem so. Looks like only the KEYS command accepts wildcards. ●Is there a performance penalty when accessing different database numbers? -> Didn't find anything, but there shouldn't be any significant penalty.
  • 24. Questions from the SoCraTes 2014 session (cont.): (and my attempts at an answer, please feel free to correct) ●Is there a mechanism to notify a client when a key is changed? -> Yes, 2.8 introduced Keyspace Notifications, see: http://redis.io/topics/notifications