noSQL database learning notes
1, Nosql database
Commonly used NoSQL includes redis, mogoDB, etc. this time, we will learn from redis Refer to the rookie tutorial for all contents
1.1 features
- Advantages: fast query, often used as cache processing, easy to expand, flexible data model and high availability
- Disadvantage: the stored data is not structured
1.2 classification
- Key value storage
- Column storage
- Document database
- Graphic database

1.3 redis data type
- String type
- Hash type
- List type
- Ordered set type
1.4 redis application scenario
- cache
- Task queue
- Website access statistics
- Data expiration processing
- App Leaderboard
- session separation in distributed cluster architecture
2, Using redis
Installation reference: Install redis
2.1 installing redis (under windows Environment)
- Download redis You can download and install according to the actual situation

(tell us about the installation skills. These software are usually on the Internet. It may be hard to download directly for half a day, so we can copy the download link and paste it into Xunlei in one second.)

- Unzip the file and save it to disk c

- Use the command prompt to enter the directory, and use the temporary service installation command redis-server.exe redis.windows.conf to see the following image, indicating that the startup is successful.

It should be noted that in this window, we open a redis server, so this window should be kept. We open another window to enter the directory and enter the command redis cli

2.2 using redis in Linux environment (to be updated)
To be added...
3, Simple use of redis
3.1 setting key value pairs

3.2 view attribute configuration
reference resources: redis configuration View all configuration information: CONFIG GET*

3.3 common redis commands
number | command | describe | Example |
---|---|---|---|
1 | set key value | Set a key (the name is key) and the value is value | |
2 | get key | Get the value corresponding to the key | |
3 | del key | Delete key | |
4 | keys * | View the key value pairs in the current database |

Only these are used for the first time. For more information, please refer to the detailed documents: http://doc.redisfans.com/
3.4 jedis usage
3.4.1 jedis Download
jedis Download Use Java to connect to redis. There are two development packages used.
Share the jar package download link: jedis download two jar packages

3.4.2 connecting redis using java
Here I use unit tests to implement
package com.imooc.jedis; import org.junit.Test; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; /** * jedis test * @author Gorit * */ public class JedisDemo1 { @Test /** * Single instance test * */ public void demo1() { // 1. Set id and port number Jedis jedis = new Jedis("127.0.0.1",6379); // 2. Save data jedis.set("name", "imooc"); // 3. Obtain data System.out.println(jedis.get("name")); jedis.close(); } /** * Similar to jdbc connection pool operation * */ @Test public void demo2() { // Gets the configuration object of the connection pool JedisPoolConfig config = new JedisPoolConfig(); // Set maximum connections config.setMaxTotal(10); // Set the maximum number of free connections config.setMaxIdle(10); // Get connection pool JedisPool jdp = new JedisPool(config, "127.0.0.1", 6379); // Get core object Jedis jedis = null; try { // Get connection through connection pool jedis = jdp.getResource(); // Set data jedis.set("name","Zhang San"); // Obtain data jedis.get("name"); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { // Release resources if (jedis != null) { jedis.close(); } if (jdp != null) { jdp.close(); } } } }