noSQL database study notes
A, Nosql database
Commonly used NoSQL have redis, mogoDB and so on, this time to redis learning
all learning content reference rookie tutorial
1.1 Features
- Advantages: Fast query, often used as a cache processing, scalable, flexible data model, high availability
- Weaknesses: The lack of structured data storage
1.2 Classification
- Key (key-value) is stored
- Column stores
- Document database
- Graphics Database
1.3 redis data types
- String type
- Hash type
- List Type
- Indexed collections
1.4 redis scenarios
- Cache
- Task Queue
- Website statistics
- Data processing expired
- Application Ranking
- Distributed cluster architecture separate session
Second, the use redis
Installation Reference: Installation redis
2.1 install redis (windows environment)
- Download redis
you can download the installation according to the actual situation
(a technique to tell you install these software are generally outside the network, download a long time to download may not down, very uncomfortable, so we can put the download link copy it, then paste it into Thunder in, one second is just great)
- Uncompress the file, and save it to disk c
- Use the command prompt, enter the directory, use the temporary service installation command
redis-server.exe redis.windows.conf
, see the following manner, indicating the success of the launch.
It should be note that this window we opened a redis server, so you want to keep this window, we open another window, the same is to enter the directory, enter the command redis-cli
Use redis 2.2 Linux environment (to be updated)
To be added. . .
Third, the simple use of redis
3.1 Setting key-value pair
3.2 View property configuration
Reference: Redis configuration
view all the configuration information:CONFIG GET *
3.3 redis commonly used commands
Numbering | command | description | Examples |
---|---|---|---|
1 | set key value | Setting a key (name of key), the value of value | |
2 | get key | Obtaining a value corresponding key | |
3 | of the key | Delete key | |
4 | keys * | Viewing current database which there are key-value pairs |
Initial use, currently only use these, more details can be found in the documentation:http://doc.redisfans.com/
3.4 jedis use
3.4.1 jedis Download
jedis download
using the Java Connector redis, there are two development kit used.
Share jar package download link: jedis two jar package download
3.4.2 using java connected redis
Here I use a unit test to achieve
package com.imooc.jedis;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* jedis 测试
* @author Gorit
* */
public class JedisDemo1 {
@Test
/**
* 单实例测试
* */
public void demo1() {
// 1. 设置 id 和端口号
Jedis jedis = new Jedis("127.0.0.1",6379);
// 2. 保存数据
jedis.set("name", "imooc");
// 3. 获取数据
System.out.println(jedis.get("name"));
jedis.close();
}
/**
* 类似 jdbc 连接池操作
* */
@Test
public void demo2() {
// 获取连接池的配置对象
JedisPoolConfig config = new JedisPoolConfig();
// 设置最大连接数
config.setMaxTotal(10);
// 设置最大空闲连接数
config.setMaxIdle(10);
// 获得连接池
JedisPool jdp = new JedisPool(config, "127.0.0.1", 6379);
// 获取核心对象
Jedis jedis = null;
try {
// 通过连接池获得连接
jedis = jdp.getResource();
// 设置数据
jedis.set("name","张三");
// 获得数据
jedis.get("name");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
// 释放资源
if (jedis != null) {
jedis.close();
}
if (jdp != null) {
jdp.close();
}
}
}
}