SET foo 100
to set a key value pair- You can set values as
SET server:name someserver
and get it withGET server:name
- You can set values as
GET foo
will return 100INCR foo
-> to increment a valueEXISTS foo
-> Determines if the key exits- It will return 1 if the value exists otherwise will return 0
DEL foo
-> to delete a valueFLUSHALL
-> to erease everythingEXPIRE foo 50
-> to give an expiration time to our valuesTTL foo
-> to see how long this value hasSETEX foo 40 "Hello world"
to set the value and the expiration at the same timePERSIST foo
-> to cancel the expiration time.MSET key1 "Hello1" key2 "World"
-> to set multiple values at the same timeAPEND key1 "World"
-> AppendRENAME key1 greeting
-> to change the key name
LPUSH people "Giovanni"
-> to push a name to the people's listLRANGE people 0 -1
-> to output all the values in the list (0 to -1 indecates all the range) Lists are 0 baseRPUSH people "Jenny"
to push a value to the end of the list.LLEN people
-> Gives the lists lengthLPOP people
-> Eliminate the first element of the listRPOP people
-> Eliminate the last element of the listLINSERT people BEFORE "Jenny" "May"
-> Will insert before a certain element.
Is an unorder collection of strings
SADD cars "FORD"
-> to add to the setSISNUMBER cars "FORD"
-> will determinate if it exists.- If return 1 the value exists in the set otherwise returns 0
SMEMBERS cars
-> return all members of the set.SCARD cars
-> Gives how many elementsSMOVE cars mycars "Ford"
to move an element to another set.SREM cars "Ford
-> is to remove an element of the set.
The difference between source sets and sets is that every memeber of the sorce set is associated with a score
ZADD users 1980 "Giovanni"
-> To Add an element to the source set 1980 will be its scoreZRANK users "Giovani"
-> To know it which position is that scoreZRANGE users 0 -1
-> Print all the source setZINCRBY user 1 "Giovanni"
-> Will return 1981 to the score
HSET user:gp1234 name "Giovanni"
HSET user:gp1234 email "giovanni@gmail.com"
HGET user:gp1234 name
HGETALL user:gp1234
-> To return all the valuesHMSET user:gp1234 name "Giovanni" email "giovanni@gmail.com" age: "24"
-> To set multiple values at the same time.HKEYS user:gp1234
-> to get all the keysHVALS user:gp1234
-> to get just the valuesHINCRBY user:gp1234 age 1
-> to increment a valueHDEL user:gp1234 age
-> to delete a key-value pairHHLEN user:gp1234
-> to get the number of key-value pairs
SAVE
-> will create a snapshot of our valuesSAVE 60 1000
-> every 60 seconds save if a 1000 of items have change- You can set
appendonly yes
in the redis configuration file and it will log everything