SlideShare a Scribd company logo
1 of 17
1
REDIS SERVER
An Introduction to REDIS SERVER, an advanced key value
database
By: Ali MasudianPour <masud.amp@gmail.com>
2
What REDIS is
●
Redis is an open source, BSD licensed, advanced key-value
store. It is often referred to as a data structure server since keys
can contain strings, hashes, lists, sets and sorted sets.
●
REDIS
– It stands for REmote DIctionary Server
3
Features
●
not a plain key-value store, a data structures server
●
supporting different kind of values
●
Free and open source
●
Easy to user
●
Easy to learn
4
Supported Data Types
●
Binary-safe strings.
●
Lists of binary-safe strings.
●
Sets of binary-safe strings, that are collection of unique unsorted
elements.
●
Sorted sets, similar to Sets but where every element is
associated to a floating number score. The elements are taken
sorted by score.
5
KEYS - VALUES
●
In REDIS, Keys are binary safe
– This means that you can use any binary sequence as key
●
From String like 'foo' to the content of a JPEG file
– REDIS keys accept empty
●
In REDIS, Values
– Can not be bigger than 512MB
–
6
SET
●
To set a value to a key we use SET statement
– SET key value
●
Example:
– SET foo bar
– In above example we told redis to set bar value to foo key
●
To set string value we use double quotations
– SET keyname “The string content of value”
7
GET
●
To get a value from redis we use GET statement
– GET keyname
●
Example
– GET foo // it will return bar
– In above example we told redis to get foo key value.
8
INCR, INCRBY
●
Automatic increment by REDIS
– To use automatic increment of redis we use INCR
●
Example:
– Set counter 1
incr counter
// Output wil be 2
●
We can also use INCRBY
– Set counter 1
– Incr counter
– // Output wil be 2
– Incrby counter 10
– //outpur will be 12
9
DECR, DECRBY
●
In opposite of INCR and INCRBY redis contains DESC and
DESCBY
– Just like DECR and DECRBY
– Set counter 10
decr counter
// Output wil be 9
decrby counter 5
//output will be 4
10
EXPIRE and TTL
●
In REDIS we can set keys to expire in a given and specific
amount of time.
– To do that we use EXPIRE command
– Example
●
Set foo bar
●
Expire foo 50
– To find out how many time a key have we use TTL command
●
For instance after 10 second of declaring foo key if we use TTL command the
output will be something like below:
– Ttl foo
//40
11
LISTS
●
To create a list use LPUSH or RPUSH. If a list already exists,
LPUSH will add the given value to the beginning of the list and
RPUSH will add it to the end.
●
Redis lists contain the following commands
– SORT
– RPUSH
– LPUSH
– LLEN
– LTRIM
– LRANGE
– LPOP
– RPOP
– BLPOP
– BRPOP
–
12
LISTS
redis 127.0.0.1:6379> lpush ages 10
(integer) 1
redis 127.0.0.1:6379> lpush ages 13
(integer) 2
redis 127.0.0.1:6379> lpush ages 12
(integer) 3
redis 127.0.0.1:6379> lpush ages 6
(integer) 4
redis 127.0.0.1:6379> LRANGE ages 0 3
1) "6"
2) "12"
3) "13"
4) "10"
redis 127.0.0.1:6379> sort ages
1) "6"
2) "10"
3) "12"
4) "13"
-----------------------------
redis 127.0.0.1:6379> lpop ages
"6"
redis 127.0.0.1:6379> rpop ages
"10"
redis 127.0.0.1:6379> LRANGE ages 0 10
1) "12"
2) "13"
redis 127.0.0.1:6379>
13
SETS
●
Sets are similar to lists but does not support duplication
●
Example:
– Add to sets
●
redis 127.0.0.1:6379> SADD names "Michael"
(integer) 1
redis 127.0.0.1:6379> SADD names "JOHN"
(integer) 1
redis 127.0.0.1:6379> SMEMBERS names
1) "JOHN"
2) "Michael"
14
Lists
●
Now, if you try to add another set member with JOHN value it
will do nothing, because sets do not support duplication.
●
Other useful commands for set
– SADD, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER,
SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE,
SMEMBERS, SRANDMEMBER.
15
HASHES
●
Using a hash, you can assign values to fields in each key.
●
Common Commands in hashes are:
– HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS,
HDEL, HLEN, HKEYS, HVALS, HGETALL
16
Example of HASHESredis 127.0.0.1:6379> hset student name "Ali"
(integer) 1
redis 127.0.0.1:6379> hset student lastName "MasudianPour"
(integer) 1
redis 127.0.0.1:6379> hset student number 101222
(integer) 1
redis 127.0.0.1:6379> hget student name
"Ali"
redis 127.0.0.1:6379> hget student lastName
"MasudianPour"
redis 127.0.0.1:6379> HGETALL student
1) "name"
2) "Ali"
3) "lastName"
4) "MasudianPour"
17
End
●
This document is provided to be a little familiar with REDIS. I
hope it help you to start working with REDIS.

More Related Content

What's hot

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
TO THE NEW | Technology
 

What's hot (20)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis overview
Redis overviewRedis overview
Redis overview
 
Redis persistence in practice
Redis persistence in practiceRedis persistence in practice
Redis persistence in practice
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis and it's data types
Redis and it's data typesRedis and it's data types
Redis and it's data types
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis database
Redis databaseRedis database
Redis database
 
Redis Reliability, Performance & Innovation
Redis Reliability, Performance & InnovationRedis Reliability, Performance & Innovation
Redis Reliability, Performance & Innovation
 
Redis 101
Redis 101Redis 101
Redis 101
 
An Introduction to Redis for Developers.pdf
An Introduction to Redis for Developers.pdfAn Introduction to Redis for Developers.pdf
An Introduction to Redis for Developers.pdf
 
Introduction of Redis as NoSQL Database
Introduction of Redis as NoSQL DatabaseIntroduction of Redis as NoSQL Database
Introduction of Redis as NoSQL Database
 
Redis Overview
Redis OverviewRedis Overview
Redis Overview
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redis
 
redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바redis 소개자료 - 네오클로바
redis 소개자료 - 네오클로바
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Redis basics
Redis basicsRedis basics
Redis basics
 
Ceph and RocksDB
Ceph and RocksDBCeph and RocksDB
Ceph and RocksDB
 
Ceph Performance and Sizing Guide
Ceph Performance and Sizing GuideCeph Performance and Sizing Guide
Ceph Performance and Sizing Guide
 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use Cases
 

Viewers also liked

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
Dvir Volk
 
Redis replication dcshi
Redis replication dcshiRedis replication dcshi
Redis replication dcshi
dcshi
 

Viewers also liked (20)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis Installation Configuration And Implementation
Redis Installation Configuration And ImplementationRedis Installation Configuration And Implementation
Redis Installation Configuration And Implementation
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
 
Redis
RedisRedis
Redis
 
Redis replication dcshi
Redis replication dcshiRedis replication dcshi
Redis replication dcshi
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Lightning Hedis
Lightning HedisLightning Hedis
Lightning Hedis
 
Redis And python at pycon_2011
Redis And python at pycon_2011Redis And python at pycon_2011
Redis And python at pycon_2011
 
Ancient Rome And Present Italy
Ancient Rome And Present ItalyAncient Rome And Present Italy
Ancient Rome And Present Italy
 
REDIS caching explained
REDIS caching explained REDIS caching explained
REDIS caching explained
 
Using Redis at Facebook
Using Redis at FacebookUsing Redis at Facebook
Using Redis at Facebook
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
 
Redis data design by usecase
Redis data design by usecaseRedis data design by usecase
Redis data design by usecase
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examples
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
唯品会大数据实践 Sacc pub
唯品会大数据实践 Sacc pub唯品会大数据实践 Sacc pub
唯品会大数据实践 Sacc pub
 
Building Automated REST APIs with Python
Building Automated REST APIs with PythonBuilding Automated REST APIs with Python
Building Automated REST APIs with Python
 
RESTful API Design, Second Edition
RESTful API Design, Second EditionRESTful API Design, Second Edition
RESTful API Design, Second Edition
 

Similar to An Introduction to REDIS NoSQL database

Redis: REmote DIctionary Server
Redis: REmote DIctionary ServerRedis: REmote DIctionary Server
Redis: REmote DIctionary Server
Ezra Zygmuntowicz
 

Similar to An Introduction to REDIS NoSQL database (20)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Redis Set Go
Redis Set GoRedis Set Go
Redis Set Go
 
#SydPHP - The Magic of Redis
#SydPHP - The Magic of Redis#SydPHP - The Magic of Redis
#SydPHP - The Magic of Redis
 
Serializing Ruby Objects in Redis
Serializing Ruby Objects in RedisSerializing Ruby Objects in Redis
Serializing Ruby Objects in Redis
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 
Paris Redis Meetup Introduction
Paris Redis Meetup IntroductionParis Redis Meetup Introduction
Paris Redis Meetup Introduction
 
Seminar_Final
Seminar_FinalSeminar_Final
Seminar_Final
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
 
REDIS327
REDIS327REDIS327
REDIS327
 
Redis Lua Scripts
Redis Lua ScriptsRedis Lua Scripts
Redis Lua Scripts
 
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
 
Redis
RedisRedis
Redis
 
Fun with Ruby and Redis
Fun with Ruby and RedisFun with Ruby and Redis
Fun with Ruby and Redis
 
Mini-Training: Redis
Mini-Training: RedisMini-Training: Redis
Mini-Training: Redis
 
C from hello world to 010101
C from hello world to 010101C from hello world to 010101
C from hello world to 010101
 
Redis: REmote DIctionary Server
Redis: REmote DIctionary ServerRedis: REmote DIctionary Server
Redis: REmote DIctionary Server
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
Redis Functions, Data Structures for Web Scale Apps
Redis Functions, Data Structures for Web Scale AppsRedis Functions, Data Structures for Web Scale Apps
Redis Functions, Data Structures for Web Scale Apps
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 

More from Ali MasudianPour

More from Ali MasudianPour (7)

Start using less css
Start using less cssStart using less css
Start using less css
 
Rapid postgresql learning, part 4
Rapid postgresql learning, part 4Rapid postgresql learning, part 4
Rapid postgresql learning, part 4
 
Rapid postgresql learning, part 3
Rapid postgresql learning, part 3Rapid postgresql learning, part 3
Rapid postgresql learning, part 3
 
Rapid postgresql learning, part 2
Rapid postgresql learning, part 2Rapid postgresql learning, part 2
Rapid postgresql learning, part 2
 
Rapid postgresql learning, part 1
Rapid postgresql learning, part 1Rapid postgresql learning, part 1
Rapid postgresql learning, part 1
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
 
Xp exterme-programming-model
Xp exterme-programming-modelXp exterme-programming-model
Xp exterme-programming-model
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

An Introduction to REDIS NoSQL database

  • 1. 1 REDIS SERVER An Introduction to REDIS SERVER, an advanced key value database By: Ali MasudianPour <masud.amp@gmail.com>
  • 2. 2 What REDIS is ● Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. ● REDIS – It stands for REmote DIctionary Server
  • 3. 3 Features ● not a plain key-value store, a data structures server ● supporting different kind of values ● Free and open source ● Easy to user ● Easy to learn
  • 4. 4 Supported Data Types ● Binary-safe strings. ● Lists of binary-safe strings. ● Sets of binary-safe strings, that are collection of unique unsorted elements. ● Sorted sets, similar to Sets but where every element is associated to a floating number score. The elements are taken sorted by score.
  • 5. 5 KEYS - VALUES ● In REDIS, Keys are binary safe – This means that you can use any binary sequence as key ● From String like 'foo' to the content of a JPEG file – REDIS keys accept empty ● In REDIS, Values – Can not be bigger than 512MB –
  • 6. 6 SET ● To set a value to a key we use SET statement – SET key value ● Example: – SET foo bar – In above example we told redis to set bar value to foo key ● To set string value we use double quotations – SET keyname “The string content of value”
  • 7. 7 GET ● To get a value from redis we use GET statement – GET keyname ● Example – GET foo // it will return bar – In above example we told redis to get foo key value.
  • 8. 8 INCR, INCRBY ● Automatic increment by REDIS – To use automatic increment of redis we use INCR ● Example: – Set counter 1 incr counter // Output wil be 2 ● We can also use INCRBY – Set counter 1 – Incr counter – // Output wil be 2 – Incrby counter 10 – //outpur will be 12
  • 9. 9 DECR, DECRBY ● In opposite of INCR and INCRBY redis contains DESC and DESCBY – Just like DECR and DECRBY – Set counter 10 decr counter // Output wil be 9 decrby counter 5 //output will be 4
  • 10. 10 EXPIRE and TTL ● In REDIS we can set keys to expire in a given and specific amount of time. – To do that we use EXPIRE command – Example ● Set foo bar ● Expire foo 50 – To find out how many time a key have we use TTL command ● For instance after 10 second of declaring foo key if we use TTL command the output will be something like below: – Ttl foo //40
  • 11. 11 LISTS ● To create a list use LPUSH or RPUSH. If a list already exists, LPUSH will add the given value to the beginning of the list and RPUSH will add it to the end. ● Redis lists contain the following commands – SORT – RPUSH – LPUSH – LLEN – LTRIM – LRANGE – LPOP – RPOP – BLPOP – BRPOP –
  • 12. 12 LISTS redis 127.0.0.1:6379> lpush ages 10 (integer) 1 redis 127.0.0.1:6379> lpush ages 13 (integer) 2 redis 127.0.0.1:6379> lpush ages 12 (integer) 3 redis 127.0.0.1:6379> lpush ages 6 (integer) 4 redis 127.0.0.1:6379> LRANGE ages 0 3 1) "6" 2) "12" 3) "13" 4) "10" redis 127.0.0.1:6379> sort ages 1) "6" 2) "10" 3) "12" 4) "13" ----------------------------- redis 127.0.0.1:6379> lpop ages "6" redis 127.0.0.1:6379> rpop ages "10" redis 127.0.0.1:6379> LRANGE ages 0 10 1) "12" 2) "13" redis 127.0.0.1:6379>
  • 13. 13 SETS ● Sets are similar to lists but does not support duplication ● Example: – Add to sets ● redis 127.0.0.1:6379> SADD names "Michael" (integer) 1 redis 127.0.0.1:6379> SADD names "JOHN" (integer) 1 redis 127.0.0.1:6379> SMEMBERS names 1) "JOHN" 2) "Michael"
  • 14. 14 Lists ● Now, if you try to add another set member with JOHN value it will do nothing, because sets do not support duplication. ● Other useful commands for set – SADD, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SMEMBERS, SRANDMEMBER.
  • 15. 15 HASHES ● Using a hash, you can assign values to fields in each key. ● Common Commands in hashes are: – HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL
  • 16. 16 Example of HASHESredis 127.0.0.1:6379> hset student name "Ali" (integer) 1 redis 127.0.0.1:6379> hset student lastName "MasudianPour" (integer) 1 redis 127.0.0.1:6379> hset student number 101222 (integer) 1 redis 127.0.0.1:6379> hget student name "Ali" redis 127.0.0.1:6379> hget student lastName "MasudianPour" redis 127.0.0.1:6379> HGETALL student 1) "name" 2) "Ali" 3) "lastName" 4) "MasudianPour"
  • 17. 17 End ● This document is provided to be a little familiar with REDIS. I hope it help you to start working with REDIS.