Your SlideShare is downloading. ×
0
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

An Introduction to REDIS NoSQL database

1,535

Published on

In this document you will be familiar with redis and it can be called as a stimulus to work pro with REDIS.

In this document you will be familiar with redis and it can be called as a stimulus to work pro with REDIS.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,535
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
50
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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.

×