Basic data types of redis

One : redis is an open source, written in C language, supports network, can be based on memory and can also be persistent, log type, key-value storage nosql database. As a cache server, the speed and efficiency are very fast, similar to memcache

Data types supported by redis : string string type, list linked list type, set unordered collection type, zset ordered collection type and hash hash type

Redis supports main memory synchronization. Data can be synchronized from the master server to any number of slave servers. Similarly, the slave server can also be used as the master server associated with other slave servers.

 two:

Operate redis data types on linux

(1) Sting type

set key value

get key to get the corresponding value

(2) List type:

lpush key values

lpush list1 1 2 3 4 5 

The data structure of the stack is first in last out (last in first out)

lpush means that the stack operation is performed from the left, and the order of the data taken out is exactly the opposite of the order in which it is pushed into the stack.

rpush means that the stack operation starts from the far right, and the order in which the data is taken out is the same as the order in which the data is inserted.

A key in the set can correspond to multiple value values, which are stored based on linked lists

lrange key 0 -1 

lrange list1 

get the result:

5

4.

3.

2.

1

 

(3) set unordered collection

The set collection does not allow duplicate elements, if there are duplicates, the duplicate data will be automatically deleted

Stored value: sadd key values 

 Example: sadd list2 abc 

Value: smembers key 

 Example: smembers list2

The retrieved data is an unordered collection, with no duplicate data

(4) zset collection: there is order and cannot be repeated

The number when inserting data will be used as the basis for sorting, and the default is in ascending order.

Stored value: by default, it is sorted in ascending order by score

zset   key score1 value1 score2 value2 score3 value3

 Value; the retrieved data is an ordered set with no repetition in ascending order

zrange key 0 -1 ascending output

zrevrange key 0 -1 descending order output

 delete: zrem key value

 

Three: expiration time in redis

Set expiration time: expire key time

Check how long it expires: ttl key

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324713883&siteId=291194637