Initial use of redis

Preface

Redis is a noSql database. The data in it is stored in memory, which can avoid the operation of reading data from the local io. The reading speed will be very fast. It can process tens of millions of data per second, although it It is single-threaded, but the speed is still very fast. Generally used for caching


One, redis installation

You need to install the C language environment first. After installing the redis installation package, you need to install it in the /usr/local directory after decompression, and then compile the C language to form a runnable file

1. Start the service, (bring the configuration file behind to make the configuration effective)
./redis-server redis.conf
2. Start the client:
./redis-cli

Two, three connection methods of redis

1.xshell connection (the startup method above is fine)

2. Client connection (when connecting remotely, you need to pay attention to whether the bind parameter in the configuration file is commented, otherwise you can only connect to the local where redis is located)

	![客户端连接软件](https://img-blog.csdnimg.cn/20201229165851329.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzQzMTEyMw==,size_16,color_FFFFFF,t_70#pic_center)
	输入ip、端口,连接主机

3.java code connection (also need to comment bind parameter)

 Jedis jedis = new Jedis("192.168.37.103",6379);

 String value = jedis.get("name");
 System.out.println(value);

Three. Five storage methods of redis

1.key - value

	最常用的方式,主要方法有:get key,set key value 键值对的方式

2.key - map

	一个key对应一个map,map里面还有键值
	方法:
			hSet key fileds value  
			hGet key fileds
			hkeys fileds   获取对应map的所有key

3.key - list

		。。。

4.key - set

		。。。

5.key - sortSet

		。。。

The corresponding method can refer to:
http://doc.redisfans.com/

There are two ways to persist redis locally:

1.RDB

	在redis.conf中可以配置:
	一般为在多长时间内做了多少操作,只要满足,就会持久化到本地,一个叫dump.rdb的文件中

2. AOF (data durability is very good, will not cause data loss)

	一般是同步用户的新增和删除操作的,查询不会同步,每做一个操作,都会持久化到本地的aof文件中,可以进行查看

Guess you like

Origin blog.csdn.net/weixin_43431123/article/details/111928855