Redis overview detailed explanation-data types-instructions-application scenarios

1. Overview of Redis

  Redis (Remote Dictionary Server) remote dictionary service, a non-relational database (NOSQL database)

  Redis is generally used to store frequently accessed but infrequently changed data (the stored data is not a lot) [for example, the provinces, cities, districts, and sites of 12306 will not change, but are frequently accessed]

2. Redis features

  Redis is based on key-value key-value pairs of memory-based NoSQL database (non-relational database) using C language development , obtain data directly from memory, read and write performance is very good. Provide persistence to prevent data loss.

3. What are the application scenarios of Redis? (Provide persistence)

  1. Session Cache, used to process some temporary data
  2. Online friends list in chat room
  3. Website visit statistics
  4. Leaderboard/Counter
  5. Publish/subscribe function

4. Redis download and install

  1. The Linux version of Redis
    officially promotes the use of Linux version of Redis, so the official website value provides Linux version of Redis download
  2. Download the Windows version of Redis from the official website or GitHub. Download
    address: http://redis.io/download
    github Download address: https://github.com/MSOpenTech/redis/tags

5. Redis directory structure

redis file directory description
reids-server.exe Redis server
redis-cli.exe Redis command line client
redis-check-aof .exe AOF file repair tool
redis-check-dump.exe RDB file checking tool
redis-benchmark.exe Redis performance test tool
redis.conf / redis.windows.conf reids configuration file

6. Start Redis (the target computer actively refuses and cannot connect error)

By start.batstarting, if an error is reported:

Could not connect to Redis at 127.0.0.1:6379: Could not connect because the target computer actively refused.

Entering in the current directory: redis-server.exe redis.windows.confto start / or modify the content of start.bat to redis-server.exe redis.windows.conf
still not work, then I see my memory usage, delete some background to release memory, and the startup is successful!

Successful startup:
Insert picture description here

Use it to open the server without closing it reids-server.exe, then open the client to use redis-cli.exe, or connect to someone else's server.

7. Redis port number (6379)

  • The Redis port is: 6379
  • The T-omcat port is: 8080
  • MySql port is: 3306

8. Redis execution process

Insert picture description here

9. Redis data type

  Redis stores data in the form of keys and values. Redis can be understood as a Map collection

  • Keys: all strings
  • Value: There are five data types
Redis-value-get data type description
String Map<String,String>
Hash Map<String,Map<String,String>> (It can also correspond to multiple small key-value pairs in one big key [key: {key:value; key:value}])
List of strings Map<String,LinkedList> (one key with multiple values)
String collection (set) Map<String,HashSet>
Sorted set Map<String,LinkedHashSet>, the values ​​are ordered, according to the order of entry

Insert picture description here

Only need to master the first form of value string

  The other four collections can be converted into json strings for operation

10. Redis instructions (corresponding to five data types)

10.1 String type

  set key value		//添加一个键值对  如果键存在,则修改  相当于set()方法
  get key            //根据键获取值(如果没有返回null)
  del key            //根据键删除键值对
  mget key1 key2      //根据多个键查看值

10.2 Hash type

  hset myhashkey key value	//添加数据 myhashkey : Map(key , value)
  hget myhashkey key 		//根据大键和小键获取值
  hdel myhashkey key 		//根据大键和小键删除值

10.3 List type List

Value can be repeated, stack storage: first in, last out

	lpush mylist a b c d e f //压栈 添加数据,键为mylist 值为:a b c d e f
	lpop  mylist         	 //从左边弹栈 f(左边栈底) <删除操作,删除的顺序和添加的顺序相反>
	rpop  mylist        	 //从右边弹栈 a(右边是栈底) <删除操作,删除的顺序和添加的顺序相同>

10.4 Collection types

The value cannot be repeated, only one of the same value is stored

	  sadd myset a b c a b   //添加数据(只会存储a b c)
	  smembers myset    	 //获取所有数据
	  srem myset a b   		 //删除数据

10.5 General instructions (all types can be used)

	  keys *      //查看Redis中所有的键  
	  del  myset  //删除指定的键值对
	  exists key  //判断键是否存在   0表示不存在,  1表示存在
	  type myset  //测试你的键是什么类型

Guess you like

Origin blog.csdn.net/qq_40542534/article/details/108708569