Redis

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.

redis_icon

Installing On Linux

First of all you go to your Terminal . Create a new File. For create new file type:

mkdir (file_name)

a

Now go to the file directory.

cd (file_name)

b

Now download Redis.For this type this command:

wget http://download.redis.io/releases/redis-6.0.6.tar.gz

2

Downloaded Redis file.But this file was zip. For Unzip Redis file type this command:

 tar xzf redis-6.0.6.tar.gz

3

For install Redis type this command:

make 

4

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

Screenshot from 2020-08-17 23-23-00

Connect to the redis-server type this command:

src/redis-cli

5

Data Type

Strings

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.

String Commands

For set value

set (key) (value)

a1

For get value

get (key)

1

See all keys

keys *

2

For delete key

del (key)

3

Flush all the keys

 flushall

4

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)

5

If you have same key It did not set.If you have not same key It set this value

setnx (key) (value)

6

See key values length

strlen (key)

7

Define time. After this time(millisecond) the key will be delete.

psetex (key) (time) (value)

8

Set multiple keys

mset (key) (value) (key) (value).....

9

Auto increment

incr (key)

Auto decrement

 decr (key)

Increment by number

imcrby (key) (number)

Decrement by number

decrby (key) (number)

10

Add with previous value

append (key) ("value")

11

Lists

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.

Lists command

Set value top

lpush (key) (value) (value)....

22

Show all data

lrange (key) 0 -1

23

Delete from the left side

lpop (key)

Note:Delete data from top side

24

Set value bottom

rpush (key) (value) (value)....

Delete from the right side

rpop (key)

Note:Delete data from bottom side

25

Show the length of list

llen (key)

26

See left value serial number

lindex (key) (index)

27

Add value in the fixed position

linsert (key) (BEFORE|AFTER) (pivot) (value)

28

Sets

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.

Sets commands

Set value

sadd (key) (member)

29

Show values

smembers

30

Length of set

scard (key)

31

Different between key

sdiff (key) (key)

32

Diffrent between key store in the destination

sdiffstore (destination) (key) (key)

33

Like as union set

sunion (key) (key)

34

Union value store in the first destination

sunionstre

35

Delete fixed member

srem (key) (member)

36

Like an inter set

sinter (key) (key)

37

Inter value store in the first destination

sinerstore (destination) (key) (key)

38

Hashes

Redis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects

Hashes command

Set multiple key

hmset (key) (field) (value) (field) (value)....

12

Get field value

hget (key) (field)

13

Get all data with field

hgetall (key)

14

Search field name

hexists (key) (field)

15

Delete fixd field value

hdel (key) (field)

16

If the field exists don't set field value. If the field exists set the field value.

Show all fields

hkeys (key)

17

Increage by number

incrby (key) (field) (number)

18

Show all field values

hvals (key)

19

Show how many field

hlen (key)

20

See multiple field value

hmget (key) (field) (field)....

21

Sorted sets

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.

Shorted sets command

Add score value

zadd (key) (score) (value) (score)....

39

See all score value

zrange (key) 0 -1

40

See value rank

zrank (key) (value)

41