SpringBoot超详细笔记之集成Redis

SpringBoot(二十四)SpringBoot集成redis哨兵集群 这里算是一篇总结笔记叭,先从linux服务器redis主从复制,哨兵集群搭建开始。首先我们来准备三个redis.conf配置文件:redis79.conf/redis80.conf/redis81.conf。至此,redis搭建哨兵模式集群,以及springboot集成redis哨兵模式到此完成。我没有多台服务器,因此我在一台服务器上边搭建redis集群,一主二从。哨兵要保证高可用,也要配置集群,需要多个配置文件,监听不同端口,启动多个哨兵。如果redis中和代码中的名称都是mymaster。 阅读详情

关于springboot集成redis,我做了笔记,分享给有需要的小伙伴们,相关学习教程是看的动力节点的视频

动力节点王鹤老师讲解的springboot教程,由浅入深,带你体验Spring Boot的极速开发过程,内容丰富,涵盖了SpringBoot开发的方方面面,并且同步更新到Spring Boot 2.x系列的最新版本。

视频链接:https://www.bilibili.com/video/BV1XQ4y1m7ex

redis能帮我们分散掉数据库的压力,有了它能更好的支持并发性能!

可以这样理解redis位于数据库和springboot框架之间,起到数据缓存的作用。

在idea当中已经集成了redis的插件配置

创建完成后会得到idea的驱动以及工具接口。

之后就要在本地启动redis服务,这个过程就好像类似启动mysql服务。

我们可以到redis的官网下载,根据自己的系统选择x64or x32

windows

https://github.com/tporadowski/redis/releases

Linux

https://redis.io/download

之后在本地需要开启redis服务

使用Java进行链接,向redis当中缓存数据

配置 - -application.yml

spring:
  redis:
    host: 127.0.0.1
    port: 6379
    jedis:
      pool:
        max-active: 8
        max-wait: -1ms
        max-idle: 500
        min-idle: 0
    lettuce:
      shutdown-timeout: 0ms

测试类

package com.example.demo;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

@SpringBootTest
class DemoApplicationTests {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Test
    void contextLoads() {
        redisTemplate.opsForValue().set("myKey3", "4564");
        System.out.println(redisTemplate.opsForValue().get("myKey3"));
    }
}

由于框架已经添加了redis 所以只需要将 redisTemplate 注入到Bean当中就可以调用接口对redis进行数据缓存。

当页面查询数据时首先去缓存当中查找数据, 如果没有数据再向数据库请求资源,因为redis的存储类型,存取速度很快,能在一定程度上减缓数据库的压力。提升并发性能,加固网站的稳定性。

我们可以起线程池对接口进行并发测试,查看是否符合逻辑,必要的加上锁。 

SpringBoot集成redis之Jedis 记录学习redis的一些理解,以及实操过程的雷雷清点。 阅读详情

相关推荐

springboot集成redis主-从模式+哨兵机制

springboot集成redis主-从模式 一、环境准备 (硬件资源:Linux+redis-5.0.3+springboot project) 需redis 3.0以上安装包,这里面以redis-5.0.3为示例。 下面讲解在一台linux上模拟1主、2从、3哨兵的主从模式(实际应用中应需3台服务器,其中一台放1主和1哨兵,另外两台放1从1哨兵)。 redis安装这里不做介绍,解压tar...

u012105362的博客 9654

Springboot 项目 集成redis集群的踩坑(重点踩坑)

redis安装 redis安装6.2或以上的 集群搭建 一定记得不要使用redis-trib.rb搭建 这个已经淘汰了,要使用redis-cli搭建 ip用私网 redis-cli --cluster create 172.29.144.202:7001 172.29.144.202:7002 172.29.144.202:7003 172.29.144.202:7004 172.29.144.202:7005 172.29.144.202:7006 --cluster-repl...

mobingp的博客 1813

springboot整合redis的完整例子

springboot整合redis的完整例子,里面封装了redis五种数据类型的工具类

springboot Redis 集群配置外网读不通

springboot Redis 集群配置外网读不通springboot 配置Redis集群配置文件解决方案 springboot 配置Redis集群 配置文件 spring: redis: database: 0 cluster: nodes: ip:7000,ip:7001,ip:7002,ip:7003,ip:7004,ip:7005 password: 'passwd' pool: max-idle: 500 min-idle:

rainyonelove的专栏 456

保姆级教程:用Wokwi玩转ESP32 MicroPython仿真(含库文件配置指南)

本教程详细介绍了如何使用Wokwi平台进行ESP32 MicroPython仿真开发,包括库文件配置、传感器数据模拟和REPL调试技巧。通过Wokwi的仿真调试系统,开发者可以在浏览器中快速验证代码逻辑,提高开发效率,特别适合物联网项目的快速迭代。

weixin_29195615的博客 446

深入理解「二进制掩码」:从原理到实践

二进制掩码本质上是一个二进制数,用于通过位操作(如与、或、非、异或等)选择性地操作目标数据的某些位。掩码的每一位(bit)可以看作一个“开关”,决定是否对目标数据的对应位进行操作。二进制掩码是位操作的灵魂,掌握它不仅能提升代码效率,还能解锁许多高级编程技巧。从基础的位提取到复杂的子集枚举,掩码的应用无处不在。希望本文的讲解和代码示例能帮助你快速上手,并在实际项目中灵活运用。如果你有更多关于掩码的疑问或应用场景,欢迎在评论区留言交流!

m0_73494933的博客 2432

SpringBoot整合redis

序言 SpringBoot 操作数据的有:spring-data jpa,jdbc ,mongodb ,redis! 项目中必不可少redis,它是非关系型数据库,有很多应用场景,如存储个人信息,最近浏览,评论等等,更重要的是,用redis当做缓存,可以大大减轻数据库访问的压力,提高访问效率。java操作redis, 在 SpringBoot2.x 之后,原来使用的jedis 被替换为了 lettuce。 jedis : 底层采用的直连,如果多个线程操作的话是不安全的,如果想要避免不安全的,使用 je

weixin_44861399的博客 427

LIGGGHTS开源离散元仿真:从基础安装到高级应用实战

本文详细介绍了LIGGGHTS开源离散元仿真软件的基础安装、脚本编写及高级应用实战。从颗粒自由落体模拟到工业级复杂系统建模,涵盖CFD-DEM耦合、高性能计算优化等关键技术,帮助用户快速掌握这一强大的颗粒仿真工具。特别适合需要处理颗粒系统仿真的科研人员和工程师。

l1k9j8h7g6的博客 619

本地连接服务器Redis配置,附带springboot中redis的yml配置

本地连接服务器Redis配置,附带springboot中redis的yml配置,Redis Desktop Manager工具

Tmoon的博客 7093

pytorchDataLoader中调整数据长度不一致问题(lstm等)

数据长度不一致 用pytorch做rnn的时候,如果输入数据不一样长,可以用两种方式解决。 一种是自定义collate方法, #自定义collate_fn dataloader.DataLoader(dataset,4,True,collate_fn=my_collate) 然后里面写数据和标签载入方式即可 def my_collate(batch): data = [item[0] for item in batch] target = [item[1] for item in batc

weixin_48174100的博客 7770

西门子 G120 变频器报文

G120报文

mmxxoo_xxmmp的博客 8080

springboot 项目发现一直连接Redis失败问题

如题,有两种情况:1、自动连接localhost:6379,连接Redis失败,其实并没有配置Redis连接 2、自动任务5000ms一次去连接Redis,Connection failure occurred. Restarting subscription task after 5000 ms 我们在新建项目时,没有依赖Redis发现会报错,RedisConnectionFactory啥啥的报错,然后依赖后会出现1和2的报错 这里介绍解决办法。去除Redis的pom依赖,如果你的项目不需要的.

你当像鸟飞往你的山~~ 3079

华为OD机考双机位C卷 - 信道分配(Java & Python& JS & C/C++ & GO )

华为OD机考双机位C卷 - 信道分配

算法大师! 453

SpringBoot集成redis

今天,日月在这里教大家如何使用springBoot集成redis,说实话比较简单,网上也有大把的教程。先套用一下网上的简介。 定义 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。 Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value...

真的愿意去努力,人生最坏的结果,也不过是大器晚成。 25万+

【PCB专题】Allegro导出3D文件

Allegro中如何导出3D文件,有没有一键导出操作?

一点硬件 4988

外向交货单批次赋值的标准姿势:用 BAPI_OUTB_DELIVERY_CHANGE 把 LIPS-CHARG 改得稳、改得干净

摘要: 外向交货单批次赋值涉及严格的业务约束,包括批次管理状态、单据状态、拆分规则等,直接更新表 LIPS 不可取。推荐使用 BAPI_OUTB_DELIVERY_CHANGE 接口,通过标准业务逻辑实现批次修改。关键点包括:区分单批次分配与批次拆分场景,正确设置 ITEM_CONTROL 控制结构,并确保单位/数量数据完整。附可直接执行的ABAP代码示例,实现安全可靠的批次更新流程。 (字数:149字)

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 397

【SpringBoot】| SpringBoot 集成 Redis

【SpringBoot】| SpringBoot 集成 Redis

m0_61933976的博客 8823

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

SpringBoot集成Redis(全网最详细)

Redis是我们Java开发中,使用频次非常高的一个nosql数据库,数据以key-value键值对的形式存储在内存中。redis的常用使用场景,可以做缓存,分布式锁,自增序列等,使用redis的方式和我们使用数据库的方式差不多,首先我们要在自己的本机电脑或者服务器上安装一个redis的服务器,通过我们的java客户端在程序中进行集成,然后通过客户端完成对redis的增删改查操作。

tangjieqing的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

SpringBoot集成Redis(全流程详解)

通过在SpringBoot中集成Redis,详细梳理集成过程。包括SpringBoot启动过程中,容器的刷新、自动配置的流程、各类注解的处理。 类比在纯Spring中集成Redis,体验SpringBoot自动配置给开发带来了哪些便利。

懒惰蜗牛的博客 3040

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

SpringBoot集成Redis

SpringBoot集成Redis 文章目录SpringBoot集成Redis1、概述2、测试Redis3、自定义redisTemplate 1、概述 Redis是什么? Redis(Remote Dictionary Server ),即远程字典服务。 是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。 与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改操

... 1310

SpringBoot 集成 Redis

一:SpringBoot 集成 Redis①Redis是一个 NoSQL(not only)数据库, 常作用缓存 Cache 使用。②Redis是一个中间件、是一个独立的服务器;常用的数据类型: string , hash ,set ,zset , list③通过Redis客户端可以使用多种语言在程序中,访问 Redis 数据;java 语言中使用的客户端库有 Jedis,lettuce, Redisson 等。

2301_79438104的博客 2353
上一篇: 动力节点王鹤SpringBoot学习笔记—配置多数据源
下一篇: 【SpringBoot笔记分享】用Aspect实现切面(以记录日志为例)
Java_Coding1
博客等级 码龄5年 9粉丝 46原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值