Redis is an open source (BSD licensed), in-memory data structure , used as a database, cache and message . It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.
First of all you go to your Terminal . Create a new File. For create new file type:
mkdir (file_name)
Now go to the file directory.
cd (file_name)
Now download Redis.For this type this command:
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
Downloaded Redis file.But this file was zip. For Unzip Redis file type this command:
tar xzf redis-6.0.6.tar.gz
For install Redis type this command:
make
Now you open a new terminal. Go to the file directory.The binaries that are now compiled are available in the src directory. Run Redis with:
src/redis-server
Connect to the redis-server type this command:
src/redis-cli
Strings are the most basic kind of Redis value. Redis Strings are binary safe, this means that a Redis string can contain any kind of data, for instance a JPEG image or a serialized Ruby object.
A String value can be at max 512 Megabytes in length.
For set value
set (key) (value)
For get value
get (key)
See all keys
keys *
For delete key
del (key)
Flush all the keys
flushall
Define time. After this time(second) the key will be delete.
setex (key) (second) (value)
See how many time to delete the key
ttl (key)
If you have same key It did not set.If you have not same key It set this value
setnx (key) (value)
See key values length
strlen (key)
Define time. After this time(millisecond) the key will be delete.
psetex (key) (time) (value)
Set multiple keys
mset (key) (value) (key) (value).....
Auto increment
incr (key)
Auto decrement
decr (key)
Increment by number
imcrby (key) (number)
Decrement by number
decrby (key) (number)
Add with previous value
append (key) ("value")
Redis Lists are simply lists of strings, sorted by insertion order. It is possible to add elements to a Redis List pushing new elements on the head (on the left) or on the tail (on the right) of the list.
The LPUSH command inserts a new element on the head, while RPUSH inserts a new element on the tail. A new list is created when one of this operations is performed against an empty key. Similarly the key is removed from the key space if a list operation will empty the list. These are very handy semantics since all the list commands will behave exactly like they were called with an empty list if called with a non-existing key as argument.
Set value top
lpush (key) (value) (value)....
Show all data
lrange (key) 0 -1
Delete from the left side
lpop (key)
Note:Delete data from top side
Set value bottom
rpush (key) (value) (value)....
Delete from the right side
rpop (key)
Note:Delete data from bottom side
Show the length of list
llen (key)
See left value serial number
lindex (key) (index)
Add value in the fixed position
linsert (key) (BEFORE|AFTER) (pivot) (value)
Redis Sets are an unordered collection of Strings. It is possible to add, remove, and test for existence of members in O(1) (constant time regardless of the number of elements contained inside the Set).
Redis Sets have the desirable property of not allowing repeated members. Adding the same element multiple times will result in a set having a single copy of this element. Practically speaking this means that adding a member does not require a check if exists then add operation.
Set value
sadd (key) (member)
Show values
smembers
Length of set
scard (key)
Different between key
sdiff (key) (key)
Diffrent between key store in the destination
sdiffstore (destination) (key) (key)
Like as union set
sunion (key) (key)
Union value store in the first destination
sunionstre
Delete fixed member
srem (key) (member)
Like an inter set
sinter (key) (key)
Inter value store in the first destination
sinerstore (destination) (key) (key)
Redis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects
Set multiple key
hmset (key) (field) (value) (field) (value)....
Get field value
hget (key) (field)
Get all data with field
hgetall (key)
Search field name
hexists (key) (field)
Delete fixd field value
hdel (key) (field)
If the field exists don't set field value. If the field exists set the field value.
Show all fields
hkeys (key)
Increage by number
incrby (key) (field) (number)
Show all field values
hvals (key)
Show how many field
hlen (key)
See multiple field value
hmget (key) (field) (field)....
Redis Sorted Sets are, similarly to Redis Sets, non repeating collections of Strings. The difference is that every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated.
Add score value
zadd (key) (score) (value) (score)....
See all score value
zrange (key) 0 -1
See value rank
zrank (key) (value)