Redis is a project by Redis Labs whose sole purpose is to implement an in-memory database that supports various data structures. Originally developed by Salvatore Sanfilippo in 2009, its current version is 6.0.9 as of September 11, 2020.
Redis is open-source and is under BSD license. Mainly its of key-value nature and written in ANSI C.
Useful Redis Commands
- Setting a value:
SET chapter 67 - Retrieving a value:
GET chapter
“67” - Setting multiple key-values:
MSET start “Fatiha” complete “Naas”
OK - Incrementing a value:
INCR chapter
(integer) 68 - Decrementing a value:
DECR chapter
(integer) 67 - If a value exists:
EXISTS chapter
(integer) 1 - When a value exists not:
EXISTS name
(integer) 0 - Removing a value:
DEL chapter
(integer) 1 - Removing all keys:
FLUSHALL
OK - Setting a server name:
SET server:name Zend
OK - Getting a server name:
GET server:name
“Zend” - Setting a server port:
SET server:port 8083
OK - Getting a server port:
GET server:port
“8083” - Renaming a key:
RENAME chapter sura
OK - Authenticating a user:
AUTH MyUserName PasswordIs123
OK - Assigning a name to current connection:
CLIENT SETNAME Farial - Retrieving the current client’s name:
CLIENT GETNAME
“Farial” - Printing any value:
ECHO “Quran.”
“Quran.” - Closing server connection:
QUIT
OK - Setting a hash value:
HSET myhash f1 5
1 - Getting the hash value:
HGET myhash f1
“5” - Getting number of hash fields:
HLEN myhash
1 - Adding key-value to a list:
LPUSH ThisList 1 2 3
(integer) 3 - Sorting a list:
SORT ThisList
1 2 3
(Sorts in ascending order, to reverse the sorting – add DESC to the command) - Removing the last value from list:
LPOP ThisList
“3” - Adding members to aset:
SADD Set 3 2 1
(integer) 3 - Checking members of a set:
SMEMBERS Set
(1)”3″
(2)”2″
(1)”1″ - Joining two sets:
SUNION Set1 Set2 - Difference between two sets:
SDIFF Set1 Set2
There are more commands available to work with a Redis database if you need. You may find them on http://www.redis.io .