Redis
基于内存进行存储,支持key-value的存储形式,底层是用C语言进行编写的
基于key-value形式的数据字典,结构简单,没有数据表的概念,直接用键值对形式完成数据的管理。
支持5种数据类型:
- 字符串
- 列表
- 集合
- 有序集合
- 哈希
搭建Redis环境
在windows上安装Redis
-
下载Redis
https://github.com/MicrosoftArchive/redis/tags

如不能进入Github,可以到https://download.youkuaiyun.com/download/zjojk/20886379下载
-
下载完成后解压缩到硬盘中,在安装目录中打开Windows Terminal或者cmd并且进入到对应的Redis解压目录,输入
redis-server.exe redis.windows.conf出现如下图案则证明安装成功

-
启动后窗口不要关,新开一个Windows Terminal或者cmd窗口,输入
redis-cli出现如下结果证明默认连接本机127.0.0.1 端口号 6379,连接成功:

-
将Redis 加入 Windows 服务,输入
redis-server --service-install redis.windows.conf
提示:Redis successfully installed as a service. 表示加入服务成功
启动Redis服务
-
进入Redis目录,在安装目录中打开Windows Terminal或者cmd并且进入到对应的Redis解压目录,输入
redis-server.exe redis.windows.conf -
新开一个Windows Terminal或者cmd窗口,输入
redis-cli
关闭Redis
-
输入shutdown

对数据进行操作
//存值
set key value
//取值
get key
SpringBoot 整合Redis
用Spring Data Redis 操作 Redis
-
创建一个Maven工程


-
在pom文件中引入相关得依赖:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sakura</groupId> <artifactId>springbootredis001</artifactId> <version>1.0-SNAPSHOT</version> <parent> <artifactId>spring-boot-starter-parent</artifactId> <groupId>org.springframework.boot</groupId> <version>2.5.3</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency> <dependency>
Spring Boot与Redis的整合实战

本文详细介绍了如何在Spring Boot应用中整合Redis,包括Redis的环境搭建、启动与关闭,以及Spring Data Redis操作Redis的方法。文章通过实例演示了Redis的五种数据类型:字符串、列表、集合、有序集合和哈希的使用,并提供了相应的代码示例。
最低0.47元/天 解锁文章
435





