Redis: (1) Installation and startup and basic data types

1. Download and install (window)

1.1 Download URL

Download link: https://github.com/tporadowski/redis/releases The
file list after decompression is:
Insert picture description here

1.2 Run start

In the current installation directory, use the cmd command to open the command window, and then run

redis-server.exe redis.windows.conf

You can start the Redis server
Insert picture description here

1.3 Simple test

In the current installation directory, use the cmd command to open the command window, and then run (on the premise that the server window is not closed in the previous step)

redis-cli.exe -h 127.0.0.1 -p 6379

Insert picture description here

2. Redis data type

2.1 String

Features:

  • String is the most basic type of redis, a key corresponds to a value
  • The string type is binary safe, that is, string can contain any data. Such as jpg images or serialized objects
  • The value of string type can store up to 512MB

Syntax command:

  • List item

  • 存:set key value

  • Take: get key

Insert picture description here

2.2 Hash (hash)

Features:

  • Is a collection of key-value (key=>value) pairs
  • It is a mapping table between field and value of string type, hash is especially suitable for storing objects
  • Each hash can store 232-1 key-value pairs (more than 4 billion)

Syntax command:

  • 存:hmset KEY key01 value01 key02 value02
  • 取:hget KEY key
  • Deletion: del KEY key
    Insert picture description here

2.3 List

Features:

  • A simple list of strings, sorted in the order of insertion. You can add an element to the head (left) or tail (right) of the list
  • The list can store up to 232-1 element (4294967295, each list can store more than 4 billion)

command:

  • Save (add element/head to the left end of the list): lpush key value01 value01…
  • Save (add element/tail to the right end of the list): rpush key value01 value01…
  • 取:lrange key start stop
  • Delete (remove an element from the left/head): lpop key
  • Delete (remove an element from the right/tail): rpop key

Insert picture description here

2.4 Set

Features:

  • Is an unordered collection of string type
  • Uniqueness of elements in the set
  • It is implemented through a hash table, so the complexity of adding, deleting, and looking up is O(1)
  • The maximum number of members in the set is 232-1 (4294967295, each set can store more than 4 billion members)

grammar:

  • 存:sadd key value01 value02 …
  • 取:smembers key

Insert picture description here

2.5 zset (sorted set: ordered set)

Features:

  • Is a collection of string type elements, and duplicate members are not allowed
  • Each element will be associated with a double type score. Redis uses scores to sort the members of the set from small to large
  • The member is unique, but the score (score) can be repeated

grammar:

  • 存:zadd key score01 value01 score02 value02 …
  • 取: zrangebyscore key MinScore MaxScore

Insert picture description here

Guess you like

Origin blog.csdn.net/xueguchen/article/details/108027161