SlideShare una empresa de Scribd logo
1 de 11
Descargar para leer sin conexión
The Redis
Wondering what’s redis? is it a red thing? can we
eat that? Well, so much for questions, let’s start diggin
what redis really 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. ”
Fore more info : http://redis.io/topics/introduction

The Installation
We need to install the service of course to make it work. Jerome (PHP) already prepared
the documentation on how to install redis in your mac. Thanks to Jerome!
Installing on mac : http://goo.gl/000DmC
Installing on ubuntu : http://goo.gl/utn659
NOTE :
“The Redis project does not directly support Windows, however the Microsoft Open Tech group develops and
maintains an experimental Windows port targeting Win32/64”

Working on Redis
After the installation, of course we need to use and work on it. So let’s get started!
● Starting the redis-server
○ in the terminal/command line execute redis-server.
● Executing commands (SET, GET, etc..)
○ in the terminal/command line execute redis-cli and you will be prompted to
enter some redis commands.

DID YOU KNOW?
Redis means “REmote DIctionary Server”

	
  
Redis Data Types and Basic Commands
Strings
● The most basic kind of Redis value.
● Binary safe (http://en.wikipedia.org/wiki/Binary-safe)
● Can be at max 512MB in length.
Basic Commands ( for more string commands : http://redis.io/commands/#string )
●

SET key value
- Set the string value of a key.
- If the key already exists, the value will be overwritten.
Return : Status code “OK”

●

GET key
- Get the value of a key
- Will return an error if the value of the key is not a string.
- if the key does not exist it will return (nil) or null.
Return : Value of the key
Example : (for GET and SET)

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

●

redis>	
  SET	
  foo	
  “bar”
OK
redis>	
  GET	
  foo
“bar”

APPEND key append_string
- Append a value to a key.
- If the key does not exist, the key will be created with the value of the string to
append.
Return : Length of the value of the key.
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

	
  

	
  

	
  

	
  

redis>	
  SET	
  foo	
  “Hello”
OK
redis>	
  APPEND	
  foo	
  “	
  World”
(integer)	
  11
redis>	
  GET	
  foo
“Hello	
  World”
●

INCR key
- Increment the integer value of a key by one.
- Will return an error if the value is not an integer
- If key does not exist, initial value will be 0 then perform increment.
Return : The value of the key after the increment
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

	
  

	
  

	
  

●

redis>	
  SET	
  foo	
  10
OK
redis>	
  INCR	
  foo
(integer)	
  11
redis>	
  GET	
  foo
11

INCRBY key increment
- Increment the integer value of a key by the given number.
- Will return an error if the value is not an integer.
- If key does not exist, initial value will be 0 then perform decrement.
Return : The value of the key after the increment
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

	
  

	
  

	
  
●

redis>	
  SET	
  foo	
  10
OK
redis>	
  INCRBY	
  foo	
  10
(integer)	
  20
redis>	
  GET	
  foo
20

DECR key
- Decrement the integer value of a key by one.
- Will return an error if the value is not an integer
- If key does not exist, initial value will be 0 then perform decrement.
Return : The value of the key after the decrement
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

	
  

	
  

	
  

	
  

redis>	
  SET	
  foo	
  10
OK
redis>	
  DECR	
  foo
(integer)	
  9
redis>	
  GET	
  foo
9
●

DECRBY key decrement
- Decrement the integer value of a key by the given number.
- Will return an error if the value is not an integer.
- If key does not exist, initial value will be 0 then perform decrement.
Return : The value of the key after the decrement
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

	
  

	
  

	
  
●

redis>	
  SET	
  foo	
  10
OK
redis>	
  DECRBY	
  foo	
  9
(integer)	
  1
redis>	
  GET	
  foo
1

STRLEN key
- Returns the length of value stored in a key
Return : length of the value, 0 if key does not exist
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

redis>	
  SET	
  foo	
  “I	
  am	
  legend.”
OK
redis>	
  STRLEN	
  foo
(integer)	
  12

Lists
● List of strings sorted by insertion order
● Can append or prepend in a list
Basic Commands ( for more list commands : http://redis.io/commands#list )
●

{L,R}PUSH(X) key value [value…]
- Prepend/Append multiple values to a list. (LPUSH prepend, RPUSH append)
- If key does not exist, it will create an empty list then execute the push process.
- {L,R}PUSHX appends/prepends only if the list exists.
Return : length of the list after the push process
Example :

	
  
	
  

	
  

	
  

redis>	
  RPUSH	
  todo_list	
  “Clean	
  house”	
  “Workout”
(integer)	
  2
 
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

redis>	
  LRANGE	
  todo_list	
  0	
  -­‐1
1)	
  “Clean	
  House”
2)	
  “Workout”

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  

redis>	
  LPUSH	
  todo_list	
  “Clean	
  house”	
  “Workout”
(integer)	
  2
redis>	
  LRANGE	
  todo_list	
  0	
  -­‐1
1)	
  “Workout”
2)	
  “Clean	
  House”

DID YOU KNOW?
To display all elements of the list, execute LRANGE key 0 -1

●

LINDEX key index
- Prepend/Append multiple values to a list. (LPUSH prepend, RPUSH append)
- If key does not exist, it will create an empty list then execute the push process.
Return : length of the list after the push process
Example :

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

redis>	
  LPUSH	
  foo	
  “bar”	
  “fizz”	
  “bazz”
(integer)	
  3
redis>	
  LINDEX	
  foo	
  0
“bar”
redis>	
  LINDEX	
  foo	
  1
“fizz”
redis>	
  LINDEX	
  foo	
  2
“bazz”
redis>	
  LINDEX	
  foo	
  3
(nil)

● LRANGE	
  key start end	
  
- Get a range of elements from a list
Return : Elements within the range specified
Example :

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

redis>	
  LPUSH	
  foo	
  “bar”	
  “fizz”	
  “bazz”
(integer)	
  3
redis>	
  LRANGE	
  foo	
  0	
  1
1)	
  “bazz”
2)	
  “fizz”
 

	
  

	
  

Sets
● Unordered collection of strings.
Basic Commands ( for more string commands : http://redis.io/commands#set )

● SADD key member [ member… ]
- Add specified member to a set
- if key doesn’t exist, new set will be created and then add the specified keys.
- Existing member will be ignored.
- Will return an error if the value stored in the key is not a set.
Return : The number of members/elements that were added to the set.
Example :

	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

redis>	
  SADD	
  foo	
  “bar”	
  “fizz”	
  “fizz”
(integer)	
  2
redis>	
  SMEMBERS	
  foo
1)	
  “bazz”
2)	
  “fizz”

● SMEMBERS key
- Get all the members in a set
- if key does not exist, empty set will be returned.
Return : All members of a set
Example :

	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

redis>	
  SADD	
  foo	
  “bar”	
  “fizz”	
  “fizz”
(integer)	
  2
redis>	
  SMEMBERS	
  foo
1)	
  “bazz”
2)	
  “fizz”

● SCARD key
- Get the number of elements in a set
Return : The number of elements in the set. 0 if key does not exist.
Example :

	
  
	
  
	
  

	
  
	
  

	
  
	
  

redis>	
  SADD	
  foo	
  “bar”	
  “fizz”	
  “fizz”
(integer)	
  2
redis>	
  SADD	
  foo	
  “bazz”
 
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

(integer)	
  1
redis>	
  SCARD	
  foo
(integer)	
  3

● SISMEMBER key member
- Check if a member is a member of the set stored in specified key .
Return : 1 if member exist, 0 if not

	
  
	
  
	
  
	
  
	
  

Example :
redis>	
  SADD	
  foo	
  “bar”
	
  
(integer)	
  1
	
  
redis>	
  SISMEMBER	
  foo	
  “bar”
	
  
(integer)	
  1
	
  
redis>	
  SISMEMBER	
  foo	
  “test”
	
  
(integer)	
  0

	
  
	
  
	
  
	
  
	
  

● SDIFF key [ key… ]
- Differentiate the first key to the other specified key
Return : The members of the first set not existing on the specified set/s.
Example :

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

redis>	
  SADD	
  foo	
  “bar”
(integer)	
  1
redis>	
  SADD	
  foo	
  “test”
(integer)	
  1
redis>	
  SADD	
  foo2	
  “bar”
(integer)	
  1
redis>	
  SADD	
  foo2	
  “fizz”
(integer)	
  1
redis>	
  SDIFF	
  foo	
  foo2
1)	
  “test”

Hashes
● maps between string fields and string values.
● perfect for data type to represent objects (like a user with id, name, username, password, etc).
Basic Commands ( for more string commands : http://redis.io/commands#hash )
●

	
  

HSET key field value
- Set a field in hash stored at key.
- If field already exist, value of the field will be overwritten.
Return : 1 if field is new and value was set, 0 if field exists and value was
overwritten.
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

●

redis>	
  HSET	
  hashtest	
  hashfield	
  “hashvalue”
(integer)	
  1
redis>	
  HSET	
  hashtest	
  hashfield	
  “hashvalueoverwrite”
(integer)	
  0

HMSET key field value [field value…]
- Set multiple field in hash stored at key.
- If fields already exist, value of the field will be overwritten.
Return : OK if no error in setting the key
Example :

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

●

redis>	
  HMSET	
  hashtest	
  field1	
  “hashval1”	
  field2	
  “hashval2”
OK
redis>	
  HGET	
  hashtest	
  field1
“hashval1”
redis>	
  HGET	
  hashtest	
  field2
“hashval2”
redis>	
  HMSET	
  hashtest	
  field1	
  “hashvaloverwrite1”
OK
redis>	
  HGET	
  hashtest	
  field1
“hashvaloverwrite1”

HGET key field
- Returns the value of the specified field.
Return : Value of the field. If field does not exist nil will be returned.
Example :

	
  
	
  
	
  

	
  
	
  
	
  

	
  
	
  
	
  

●

	
  

redis>	
  HSET	
  hashtest	
  field1	
  “hashval1”
OK
redis>	
  HGET	
  hashtest	
  field1
“hashval1”

HMGET key field [field…]
- Returns the value of the specified field/s.
Return : List of values associated with the field/s specified.
Example :

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  

●

redis>	
  HMSET	
  hashtest	
  field1	
  “hashval1”	
  field2	
  “hashval2”
OK
redis>	
  HGET	
  hashtest	
  field1	
  field2	
  field3
1)	
  “hashval1”
2)	
  “hashval2”
3)	
  (nil)

HDEL key field [field…]
- Removes the specified field/s from the hash
Return : Number of fields that were removed.
Example :

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  

redis>	
  HSET	
  hashkey	
  field1	
  “hashval1”
OK
redis>	
  HDEL	
  hashkey	
  field0
(integer)	
  0
redis>	
  HDEL	
  hashkey	
  field1
(integer)	
  1

Sorted Sets
● almost similar to SETS. (collection of strings)
● associated with scores that will be used in ordering the set.
● members are unique, scores can be repeated.
● in games, this is often used for computing ranks.
Basic Commands ( for more string commands : http://redis.io/commands#sorted_set )
●

ZADD key score member [score member...]
- Adds a member with specific score in the sorted set.
- If a specified member is existing, score will be overwritten.
Return : Number of elements added in the sorted set not including the existing
member value update.
Example :

	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  

redis>	
  ZADD	
  sstest	
  1	
  “ssmember1”
(integer)	
  1
redis>	
  ZADD	
  sstest	
  2	
  “ssmember2”
(integer)	
  1
redis>	
  ZADD	
  sstest	
  3	
  “ssmember3”
 
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
●

(integer)	
  1
redis>	
  ZRANGE	
  sstest	
  0	
  -­‐1	
  WITHSCORES
1)	
  “ssmember1”
2)	
  “1”
3)	
  “ssmember2”
4)	
  “2”
5)	
  “ssmember3”
6)	
  “3”

ZREM key member [member...]
- Removes specified member/s in a sorted set.
- If a specified member is existing, score will be overwritten.
Return : Number of members removed from the sorted set.
Example :

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
●

redis>	
  ZADD	
  sstest	
  1	
  “ssmember1”
(integer)	
  1
redis>	
  ZADD	
  sstest	
  2	
  “ssmember2”
(integer)	
  1
redis>	
  ZREM	
  sstest	
  “ssmember2”
(integer)	
  1
redis>	
  ZRANGE	
  sstest	
  0	
  -­‐1	
  WITHSCORES
1)	
  “ssmember1”
2)	
  “1”

ZRANGE key start stop [WITHSCORES]
- Returns elements within the specified range. (elements are in ascending order,
use ZREVRANGE to make the order in descending)
- start and stop option are both zero-based indexes, 0 is the first element,
1 is next and so on.
- WITHSCORES option will also return the element with the score.
Return : List of elements based on the range specified.
Example :

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

	
  
	
  
	
  
	
  
	
  
	
  
	
  
	
  

redis>	
  ZADD	
  sstest	
  1	
  “ssmember1”
(integer)	
  1
redis>	
  ZADD	
  sstest	
  2	
  “ssmember2”
(integer)	
  1
redis>	
  ZADD	
  sstest	
  3	
  “ssmember3”
(integer)	
  1
redis>	
  ZRANGE	
  sstest	
  0	
  1
1)	
  “ssmember1”
2)	
  “ssmember2”
Redis Configuration
Redis can be started without any configuration file. It will use the default configuration of
redis. Easy right? But using default configuration is recommended only for testing and
development phase of your application.
3 Ways to configure redis server
1. Using a configuration file
●

create a redis.conf file containing your configurations (see this link for redis configurations
directives -> https://raw.github.com/antirez/redis/2.6/redis.conf)

●

start redis server with the config file you made
○

redis-­‐server	
  /path/to/redis.conf	
  

2. Passing arguments in the command line
●

arguments passed are the same with the directives in redis.conf file. You just have to add
the prefix --.
○

●

redis-­‐server	
  -­‐-­‐daemonize	
  yes	
  -­‐-­‐port	
  6380	
  

this will generate an in-memory configuration file.

3. On the fly
●

While the redis-server is running you can execute a command in redis-cli
○

CONFIG	
  SET	
  timeout	
  0	
  

●
●

	
  

arguments passed to CONFIG SET are also the same in the config file directives.
note that setting configuration on the fly will not affect the redis.conf file you made.

Más contenido relacionado

La actualidad más candente

Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunJIHUN KIM
 
The Ring programming language version 1.5.2 book - Part 177 of 181
The Ring programming language version 1.5.2 book - Part 177 of 181The Ring programming language version 1.5.2 book - Part 177 of 181
The Ring programming language version 1.5.2 book - Part 177 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185Mahmoud Samir Fayed
 
Rx-Java - Como compor sua aplicacao com Observables
Rx-Java - Como compor sua aplicacao com ObservablesRx-Java - Como compor sua aplicacao com Observables
Rx-Java - Como compor sua aplicacao com Observableslokimad
 
Introducing redis
Introducing redisIntroducing redis
Introducing redisNuno Caneco
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to GroovyAnton Arhipov
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS TestingEyal Vardi
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAhmed Salama
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - FunctionCody Yun
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with itFlavien Raynaud
 

La actualidad más candente (20)

Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
 
The Magic Of Elixir
The Magic Of ElixirThe Magic Of Elixir
The Magic Of Elixir
 
The Ring programming language version 1.5.2 book - Part 177 of 181
The Ring programming language version 1.5.2 book - Part 177 of 181The Ring programming language version 1.5.2 book - Part 177 of 181
The Ring programming language version 1.5.2 book - Part 177 of 181
 
Codes
CodesCodes
Codes
 
The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185The Ring programming language version 1.5.4 book - Part 181 of 185
The Ring programming language version 1.5.4 book - Part 181 of 185
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
Rx-Java - Como compor sua aplicacao com Observables
Rx-Java - Como compor sua aplicacao com ObservablesRx-Java - Como compor sua aplicacao com Observables
Rx-Java - Como compor sua aplicacao com Observables
 
Introducing redis
Introducing redisIntroducing redis
Introducing redis
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
Vcs28
Vcs28Vcs28
Vcs28
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9Hidden Gems of Ruby 1.9
Hidden Gems of Ruby 1.9
 
Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 
Sp ch05
Sp ch05Sp ch05
Sp ch05
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
 

Similar a Redis Set Go

Similar a Redis Set Go (20)

Try Redis - interactive Tutorial
Try Redis - interactive TutorialTry Redis - interactive Tutorial
Try Redis - interactive Tutorial
 
Redis basics
Redis basicsRedis basics
Redis basics
 
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
 
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
 
Redis
RedisRedis
Redis
 
Redis Lua Scripts
Redis Lua ScriptsRedis Lua Scripts
Redis Lua Scripts
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Five
FiveFive
Five
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redis
 
Use PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language ParserUse PEG to Write a Programming Language Parser
Use PEG to Write a Programming Language Parser
 
Redis introduction
Redis introductionRedis introduction
Redis introduction
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 
Tuga IT 2017 - Redis
Tuga IT 2017 - RedisTuga IT 2017 - Redis
Tuga IT 2017 - 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
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Mips1
Mips1Mips1
Mips1
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 

Más de KLabCyscorpions-TechBlog (13)

Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
Auto Layout on Xcode 5
Auto Layout on Xcode 5Auto Layout on Xcode 5
Auto Layout on Xcode 5
 
Code Review for iOS
Code Review for iOSCode Review for iOS
Code Review for iOS
 
Object Calisthenics
Object CalisthenicsObject Calisthenics
Object Calisthenics
 
Why You're A Bad PHP Programmer
Why You're A Bad PHP ProgrammerWhy You're A Bad PHP Programmer
Why You're A Bad PHP Programmer
 
Redis Beyond
Redis BeyondRedis Beyond
Redis Beyond
 
X-Debug in Php Storm
X-Debug in Php StormX-Debug in Php Storm
X-Debug in Php Storm
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Php + MySql Optimization
Php + MySql OptimizationPhp + MySql Optimization
Php + MySql Optimization
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
MVC Web Application
MVC Web ApplicationMVC Web Application
MVC Web Application
 
AfNetworking vs. Native + Caching
AfNetworking vs. Native + CachingAfNetworking vs. Native + Caching
AfNetworking vs. Native + Caching
 
Bash
BashBash
Bash
 

Último

Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 

Último (20)

Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 

Redis Set Go

  • 1. The Redis Wondering what’s redis? is it a red thing? can we eat that? Well, so much for questions, let’s start diggin what redis really 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. ” Fore more info : http://redis.io/topics/introduction The Installation We need to install the service of course to make it work. Jerome (PHP) already prepared the documentation on how to install redis in your mac. Thanks to Jerome! Installing on mac : http://goo.gl/000DmC Installing on ubuntu : http://goo.gl/utn659 NOTE : “The Redis project does not directly support Windows, however the Microsoft Open Tech group develops and maintains an experimental Windows port targeting Win32/64” Working on Redis After the installation, of course we need to use and work on it. So let’s get started! ● Starting the redis-server ○ in the terminal/command line execute redis-server. ● Executing commands (SET, GET, etc..) ○ in the terminal/command line execute redis-cli and you will be prompted to enter some redis commands. DID YOU KNOW? Redis means “REmote DIctionary Server”  
  • 2. Redis Data Types and Basic Commands Strings ● The most basic kind of Redis value. ● Binary safe (http://en.wikipedia.org/wiki/Binary-safe) ● Can be at max 512MB in length. Basic Commands ( for more string commands : http://redis.io/commands/#string ) ● SET key value - Set the string value of a key. - If the key already exists, the value will be overwritten. Return : Status code “OK” ● GET key - Get the value of a key - Will return an error if the value of the key is not a string. - if the key does not exist it will return (nil) or null. Return : Value of the key Example : (for GET and SET)                   ● redis>  SET  foo  “bar” OK redis>  GET  foo “bar” APPEND key append_string - Append a value to a key. - If the key does not exist, the key will be created with the value of the string to append. Return : Length of the value of the key. Example :                           redis>  SET  foo  “Hello” OK redis>  APPEND  foo  “  World” (integer)  11 redis>  GET  foo “Hello  World”
  • 3. ● INCR key - Increment the integer value of a key by one. - Will return an error if the value is not an integer - If key does not exist, initial value will be 0 then perform increment. Return : The value of the key after the increment Example :                         ● redis>  SET  foo  10 OK redis>  INCR  foo (integer)  11 redis>  GET  foo 11 INCRBY key increment - Increment the integer value of a key by the given number. - Will return an error if the value is not an integer. - If key does not exist, initial value will be 0 then perform decrement. Return : The value of the key after the increment Example :                         ● redis>  SET  foo  10 OK redis>  INCRBY  foo  10 (integer)  20 redis>  GET  foo 20 DECR key - Decrement the integer value of a key by one. - Will return an error if the value is not an integer - If key does not exist, initial value will be 0 then perform decrement. Return : The value of the key after the decrement Example :                           redis>  SET  foo  10 OK redis>  DECR  foo (integer)  9 redis>  GET  foo 9
  • 4. ● DECRBY key decrement - Decrement the integer value of a key by the given number. - Will return an error if the value is not an integer. - If key does not exist, initial value will be 0 then perform decrement. Return : The value of the key after the decrement Example :                         ● redis>  SET  foo  10 OK redis>  DECRBY  foo  9 (integer)  1 redis>  GET  foo 1 STRLEN key - Returns the length of value stored in a key Return : length of the value, 0 if key does not exist Example :                   redis>  SET  foo  “I  am  legend.” OK redis>  STRLEN  foo (integer)  12 Lists ● List of strings sorted by insertion order ● Can append or prepend in a list Basic Commands ( for more list commands : http://redis.io/commands#list ) ● {L,R}PUSH(X) key value [value…] - Prepend/Append multiple values to a list. (LPUSH prepend, RPUSH append) - If key does not exist, it will create an empty list then execute the push process. - {L,R}PUSHX appends/prepends only if the list exists. Return : length of the list after the push process Example :         redis>  RPUSH  todo_list  “Clean  house”  “Workout” (integer)  2
  • 5.                   redis>  LRANGE  todo_list  0  -­‐1 1)  “Clean  House” 2)  “Workout”                               redis>  LPUSH  todo_list  “Clean  house”  “Workout” (integer)  2 redis>  LRANGE  todo_list  0  -­‐1 1)  “Workout” 2)  “Clean  House” DID YOU KNOW? To display all elements of the list, execute LRANGE key 0 -1 ● LINDEX key index - Prepend/Append multiple values to a list. (LPUSH prepend, RPUSH append) - If key does not exist, it will create an empty list then execute the push process. Return : length of the list after the push process Example :                                                       redis>  LPUSH  foo  “bar”  “fizz”  “bazz” (integer)  3 redis>  LINDEX  foo  0 “bar” redis>  LINDEX  foo  1 “fizz” redis>  LINDEX  foo  2 “bazz” redis>  LINDEX  foo  3 (nil) ● LRANGE  key start end   - Get a range of elements from a list Return : Elements within the range specified Example :                           redis>  LPUSH  foo  “bar”  “fizz”  “bazz” (integer)  3 redis>  LRANGE  foo  0  1 1)  “bazz” 2)  “fizz”
  • 6.       Sets ● Unordered collection of strings. Basic Commands ( for more string commands : http://redis.io/commands#set ) ● SADD key member [ member… ] - Add specified member to a set - if key doesn’t exist, new set will be created and then add the specified keys. - Existing member will be ignored. - Will return an error if the value stored in the key is not a set. Return : The number of members/elements that were added to the set. Example :                         redis>  SADD  foo  “bar”  “fizz”  “fizz” (integer)  2 redis>  SMEMBERS  foo 1)  “bazz” 2)  “fizz” ● SMEMBERS key - Get all the members in a set - if key does not exist, empty set will be returned. Return : All members of a set Example :                         redis>  SADD  foo  “bar”  “fizz”  “fizz” (integer)  2 redis>  SMEMBERS  foo 1)  “bazz” 2)  “fizz” ● SCARD key - Get the number of elements in a set Return : The number of elements in the set. 0 if key does not exist. Example :               redis>  SADD  foo  “bar”  “fizz”  “fizz” (integer)  2 redis>  SADD  foo  “bazz”
  • 7.                   (integer)  1 redis>  SCARD  foo (integer)  3 ● SISMEMBER key member - Check if a member is a member of the set stored in specified key . Return : 1 if member exist, 0 if not           Example : redis>  SADD  foo  “bar”   (integer)  1   redis>  SISMEMBER  foo  “bar”   (integer)  1   redis>  SISMEMBER  foo  “test”   (integer)  0           ● SDIFF key [ key… ] - Differentiate the first key to the other specified key Return : The members of the first set not existing on the specified set/s. Example :                                                       redis>  SADD  foo  “bar” (integer)  1 redis>  SADD  foo  “test” (integer)  1 redis>  SADD  foo2  “bar” (integer)  1 redis>  SADD  foo2  “fizz” (integer)  1 redis>  SDIFF  foo  foo2 1)  “test” Hashes ● maps between string fields and string values. ● perfect for data type to represent objects (like a user with id, name, username, password, etc). Basic Commands ( for more string commands : http://redis.io/commands#hash ) ●   HSET key field value - Set a field in hash stored at key. - If field already exist, value of the field will be overwritten.
  • 8. Return : 1 if field is new and value was set, 0 if field exists and value was overwritten. Example :                   ● redis>  HSET  hashtest  hashfield  “hashvalue” (integer)  1 redis>  HSET  hashtest  hashfield  “hashvalueoverwrite” (integer)  0 HMSET key field value [field value…] - Set multiple field in hash stored at key. - If fields already exist, value of the field will be overwritten. Return : OK if no error in setting the key Example :                                                       ● redis>  HMSET  hashtest  field1  “hashval1”  field2  “hashval2” OK redis>  HGET  hashtest  field1 “hashval1” redis>  HGET  hashtest  field2 “hashval2” redis>  HMSET  hashtest  field1  “hashvaloverwrite1” OK redis>  HGET  hashtest  field1 “hashvaloverwrite1” HGET key field - Returns the value of the specified field. Return : Value of the field. If field does not exist nil will be returned. Example :                   ●   redis>  HSET  hashtest  field1  “hashval1” OK redis>  HGET  hashtest  field1 “hashval1” HMGET key field [field…] - Returns the value of the specified field/s.
  • 9. Return : List of values associated with the field/s specified. Example :                               ● redis>  HMSET  hashtest  field1  “hashval1”  field2  “hashval2” OK redis>  HGET  hashtest  field1  field2  field3 1)  “hashval1” 2)  “hashval2” 3)  (nil) HDEL key field [field…] - Removes the specified field/s from the hash Return : Number of fields that were removed. Example :                               redis>  HSET  hashkey  field1  “hashval1” OK redis>  HDEL  hashkey  field0 (integer)  0 redis>  HDEL  hashkey  field1 (integer)  1 Sorted Sets ● almost similar to SETS. (collection of strings) ● associated with scores that will be used in ordering the set. ● members are unique, scores can be repeated. ● in games, this is often used for computing ranks. Basic Commands ( for more string commands : http://redis.io/commands#sorted_set ) ● ZADD key score member [score member...] - Adds a member with specific score in the sorted set. - If a specified member is existing, score will be overwritten. Return : Number of elements added in the sorted set not including the existing member value update. Example :                           redis>  ZADD  sstest  1  “ssmember1” (integer)  1 redis>  ZADD  sstest  2  “ssmember2” (integer)  1 redis>  ZADD  sstest  3  “ssmember3”
  • 10.                                                 ● (integer)  1 redis>  ZRANGE  sstest  0  -­‐1  WITHSCORES 1)  “ssmember1” 2)  “1” 3)  “ssmember2” 4)  “2” 5)  “ssmember3” 6)  “3” ZREM key member [member...] - Removes specified member/s in a sorted set. - If a specified member is existing, score will be overwritten. Return : Number of members removed from the sorted set. Example :                                                 ● redis>  ZADD  sstest  1  “ssmember1” (integer)  1 redis>  ZADD  sstest  2  “ssmember2” (integer)  1 redis>  ZREM  sstest  “ssmember2” (integer)  1 redis>  ZRANGE  sstest  0  -­‐1  WITHSCORES 1)  “ssmember1” 2)  “1” ZRANGE key start stop [WITHSCORES] - Returns elements within the specified range. (elements are in ascending order, use ZREVRANGE to make the order in descending) - start and stop option are both zero-based indexes, 0 is the first element, 1 is next and so on. - WITHSCORES option will also return the element with the score. Return : List of elements based on the range specified. Example :                                                   redis>  ZADD  sstest  1  “ssmember1” (integer)  1 redis>  ZADD  sstest  2  “ssmember2” (integer)  1 redis>  ZADD  sstest  3  “ssmember3” (integer)  1 redis>  ZRANGE  sstest  0  1 1)  “ssmember1” 2)  “ssmember2”
  • 11. Redis Configuration Redis can be started without any configuration file. It will use the default configuration of redis. Easy right? But using default configuration is recommended only for testing and development phase of your application. 3 Ways to configure redis server 1. Using a configuration file ● create a redis.conf file containing your configurations (see this link for redis configurations directives -> https://raw.github.com/antirez/redis/2.6/redis.conf) ● start redis server with the config file you made ○ redis-­‐server  /path/to/redis.conf   2. Passing arguments in the command line ● arguments passed are the same with the directives in redis.conf file. You just have to add the prefix --. ○ ● redis-­‐server  -­‐-­‐daemonize  yes  -­‐-­‐port  6380   this will generate an in-memory configuration file. 3. On the fly ● While the redis-server is running you can execute a command in redis-cli ○ CONFIG  SET  timeout  0   ● ●   arguments passed to CONFIG SET are also the same in the config file directives. note that setting configuration on the fly will not affect the redis.conf file you made.