已解决redis.clients.jedis.exceptions.JedisNoScriptException异常的正确解决方法,亲测有效,嘿嘿嘿

详细解决redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool的多种详细的解决方法 阅读详情

问题分析

redis.clients.jedis.exceptions.JedisNoScriptException 异常通常发生在尝试在 Redis 中执行 Lua 脚本时,但 Redis 服务器并没有加载该脚本,或者客户端尝试使用不存在的脚本 ID 来执行脚本。Jedis 客户端在执行 Lua 脚本时,通常会先将脚本加载到 Redis 服务器上,并获取一个唯一的脚本 ID,之后使用这个 ID 来执行脚本,以提高性能。如果在尝试执行一个脚本时未找到对应的 ID,就会抛出 JedisNoScriptException 异常。

报错原因

  1. 脚本未加载:在尝试执行 Lua 脚本之前,没有先将其加载到 Redis 服务器上。
  2. 脚本 ID 错误:可能使用了错误的脚本 ID 来执行脚本。
  3. Redis 服务器重启:如果 Redis 服务器在加载脚本后重启了,所有之前加载的脚本及其 ID 都会被清除,再次尝试使用旧的 ID 执行脚本会失败。

解决思路

  1. 确保脚本已加载:在执行 Lua 脚本之前,确保已使用 EVALSHA 或 Jedis 的 scriptLoad 方法将脚本加载到 Redis 服务器上。
  2. 使用正确的脚本 ID:确保在执行脚本时使用了正确的脚本 ID。
  3. 处理 Redis 重启:如果 Redis 服务器可能会重启,确保在重启后重新加载脚本并获取新的 ID。

解决方法

示例代码

首先,加载 Lua 脚本到 Redis 服务器,并获取脚本 ID:

String luaScript = "return redis.call('set', KEYS[1], ARGV[1])";
String sha1 = jedis.scriptLoad(luaScript);

然后,使用获取到的脚本 ID 来执行脚本:

List<String> keys = Arrays.asList("mykey");
List<String> args = Arrays.asList("myvalue");
Object result = jedis.evalsha(sha1, keys, args);
处理 Redis 重启

如果 Redis 服务器可能会重启,你可以将脚本内容保存在客户端,并在每次尝试执行脚本之前检查是否已经加载了脚本。如果没有加载,就重新加载并获取新的 ID。这可以通过将脚本内容和对应的 ID 存储在缓存或数据库中来实现。

完整示例(包含 Redis 重启处理)

下滑查看解决方法

以下是一个简单的示例,展示了如何在 Redis 重启后重新加载 Lua 脚本:

// 假设你有一个方法来加载和获取脚本 ID
String loadScriptAndGetSha1(Jedis jedis, String luaScript) {
    String sha1 = jedis.scriptExists(luaScript).stream()
            .findFirst()
            .orElseGet(() -> {
                // 脚本不存在,加载它
                return jedis.scriptLoad(luaScript);
            });
    return sha1;
}

// ...

// 当需要执行脚本时
String luaScript = "return redis.call('set', KEYS[1], ARGV[1])";
String sha1 = loadScriptAndGetSha1(jedis, luaScript);
List<String> keys = Arrays.asList("mykey");
List<String> args = Arrays.asList("myvalue");
Object result = jedis.evalsha(sha1, keys, args);

注意:在上面的 loadScriptAndGetSha1 方法中,我们使用了 jedis.scriptExists 来检查脚本是否已经存在。但实际上,scriptExists 方法用于检查多个脚本是否存在,并返回一个列表,其中每个元素是一个整数,表示对应位置的脚本是否存在(存在为 1,不存在为 0)。为了简化示例,我们只检查了列表中的第一个元素(即我们关心的脚本)。在真实场景中,你可能需要根据你的具体需求来处理多个脚本的情况。

施耐德EcoStruxure平台深度体验:IEC 61499在智慧物流中心的真实应用案例解析 本文深度解析施耐德EcoStruxure平台在智慧物流中心的应用,重点探讨IEC 61499标准如何通过分布式控制和功能块技术重构自动化逻辑。通过上海某物流中心的真实案例,展示了该平台在提升系统弹性、降低停机成本方面的显著成效,为工业自动化转型提供实践参考。 阅读详情

相关推荐

Cy7c68013A速度测试教程

手里有一个cypress的CY7C68013A模块,一直没空玩。今天便测一下,这个模块的USB2.0速率。 1、开发工具下载 在cypress下载如下开发工具包(开发工具包下载地址) 2、驱动安装 一路Next即可 3、下载CyControl.exe 4、驱动安装 模块连接电脑,此时由于没有安装驱动,在设备管理器中显示未知设备...

LV9586的博客 5894

redis连接异常 redis.clients.jedis.exceptions.JedisClusterException CLUSTERDOWN The cluster is down

遇到一个问题,因为是在测试环境,之前退出使用的kill -9暴力方式,再重新启动redis集群的时候,先并没有恢复rdb和aof,使用redis-cli客户端可以连接,说明集群已经启动来了,但是使用jedis客户端代码连接不上,抛异常: 1、异常信息: Exception in thread “main” redis.clients.jedis.exceptions.JedisClusterException: CLUSTERDOWN The cluster is down at redis.clients

sebeefe的博客 2150

第 4 课 树莓派5的换源与中文输入法

树莓派换源、中文输入法的安装

嵌入式老牛的博客 2288

已解决redis.clients.jedis.exceptions.JedisNoScriptException异常的正确解决方法,亲测有效!!!

已解决redis.clients.jedis.exceptions.JedisNoScriptException异常的正确解决方法,亲测有效!!!

小明的Java问道之路 1725

宝塔面板+pbootCMS建站全流程:从服务器选购到上线优化(附常见问题排查)

本文提供了一份详尽的宝塔面板与pbootCMS建站实战指南。内容涵盖从云服务器选购、宝塔面板部署与安全加固,到pbootCMS安装、权限配置、数据库连接等核心步骤。同时深入讲解了PHP环境优化、Nginx伪静态设置、缓存开启等性能与SEO优化技巧,并附有常见问题排查与后期维护建议,帮助用户高效、稳健地完成专业网站构建。

e4f5g6h的博客 661

【sap2000】部分模型通过.s2k文件合并模型generating a global model through partial models by .s2k text file

现在需要通过选项File → Import → SAP2000 .s2k Text File → Add to existing model(如果使用其中一个部分模型作为基础)或New model(如果使用新文件)添加部分模型,并使用以下导入选项。模型A(阶段1/5) Model A (Phase 1/5)模型B(阶段2/5) Model B (Phase 2/5)模型C(阶段3/5) Model C (Phase 3/5)模型E(阶段5/5) Model E (Phase 5/5)

hmywillstronger的博客 1750

redis.clients.jedis.exceptions.JedisConnectionException之异常解决

文章简单介绍了redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out和redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool两种异常的产生原因,并最后给出解决方法,亲测有效。

Vincent2014Linux 8297

SpotBugs使用

spotbugs命令行参数解析

javajingling的专栏 2947

lua执行redis脚本找不到脚本的问题

写在前面 最近遇到了一个坑,给大家分享下。 有个项目,利用redis做统计功能。一向对性能追求极致的我怎么能随便写几条redis的统计语句就应付呢。于是我打算使用lua脚本把用到的几条redis指令封装一起,这样减少和redis的IO交互,还可以保证操作原子性。我为自己的聪明才智沾沾自喜。 脚本如下(下面并不是我项目中实际的脚本,做了一些修改,大家不用纠结语法和能否运行。不过不影响本文的分析): private final static String luaScript = "re

lucasma的博客 2517

基于AMD AU15P FPGA的SLVS-EC桥PCIe设计方案分享

各位FPGAer周末愉快,今天熊猫君分享一个基于AMD AU15P FPGA的SLVS-EC桥PCIe设计方案。

haoxingheng的专栏 1447

Dify智能体开发:发布嵌入网站

Dify 支持将你的 AI 应用嵌入到业务网站中,你可以使用该能力在几分钟内制作具有业务数据的官网 AI 客服、业务知识问答等应用。点击 WebApp 卡片上的嵌入按钮,复制嵌入代码,粘贴到你网站的目标位置。

王国平的博客 3244

【Redis】已解决:redis.clients.jedis.exceptions.JedisNoScriptException

在使用Redis进行缓存或数据处理时,Lua脚本是一种常用的扩展手段,用于保证操作的原子性和高效性。Jedis是Java中使用Redis的一个常用客户端库,但在执行Lua脚本时,开发者可能会遇到。为了解决该报错问题,可以在执行脚本之前先加载脚本并获取其SHA值,然后使用该SHA值进行脚本调用。场景:在一个Spring Boot项目中,开发者使用Jedis来执行Redis Lua脚本进行分布式锁的实现。在上述代码中,开发者希望通过Lua脚本在Redis中设置一个分布式锁,但在执行时可能会遇到。

屿小夏.的知识博客 3397

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

如果你无法导入`redis.clients.jedis.Jedis`类,可能是因为没有添加Jedis的依赖库。

如果你无法导入`redis.clients.jedis.Jedis`类,可能是因为没有添加Jedis的依赖库。

Java&Develop的博客 3281

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

深度学习工具包 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")

Redis常见异常汇总

在阿里云文档中看到一篇Redis错误排查的内容,作者整理的比较详细,感觉很有参考意义,摘录下来,方便个人后续参考使用…Jedis虽然使用起来比较简单,但是不能根据使用场景设置合理的参数(例如连接池参数),或者不合理地使用了一些功能(例如Lua和事务)时,也会产生很多问题,本文对这些常见问题进行逐一说明。

Huangjiazhen711的博客 1万+

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

java: 程序包redis.clients.jedis不存在

java: 程序包redis.clients.jedis不存在

A乐神的博客 1503

redis.clients.jedis.exceptions.JedisException: Could not return the broken resource to the pool

直接释放的是线程池,而线程池释放的时候又会去调用jedis.close,所以会造成二次释放。正确的使用方法应该是,直接调用jedis.close()方法。

u012925692的博客 3009

已解决redis.clients.jedis.exceptions.JedisConnectionException异常的正确解决方法,亲测有效!!!

已解决redis.clients.jedis.exceptions.JedisConnectionException异常的正确解决方法,亲测有效!!!

小明的Java问道之路 1万+

ClassNotFound找不到 redis.clients.jedis.JedisShardInfo

升级jedis版本异常

bubble21的博客 3605

Redis 客户端常见异常分析

在Redis客户端的使用过程中,无论是客户端使用不当或者Redis服务端出现问题,客户端会反应出一些异常,下面分析一下Jedis使用过程中常见的异常情况

若明天不见 6174

redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'SENTINEL'

Exception in thread "Thread-3" redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'SENTINEL' at redis.clients.jedis.Protocol.processError(Protocol.java:118) at redis.clients

小马哥(新博客地址 http://maruifu.cn ) 2万+

redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reac

错误原因:Redis集群启动失败。 解决方式: 1.win-R 打开cmd,输入 netstat -ano | findstr "报错的端口号" 2.之后如果显示有一个或两个进程占用了这个端口,那就是端口占用,导致Redis集群无法启动。 3.解决方法: 继续输入 taskkill -pid 进程id -f 把第二步出现的进程id 全部终结。 4.重新启动redis,完...

此人很懒,什么也没有留下~ 7235

redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set 异常解决

这个异常信息是在使用jedis连接windows下的redis服务端时抛出的异常我使用的是github上的解压版redisan安装包,从启动窗口看到默认读取的配置文件并不是文件夹里的两个配置文件,原因是因为我没有把redis注册成服务,下面是安装redis服务流程。1.在CMD窗口下进入redis解压目录2.输入命令:redis-server --service-install redis.wi...

Let_me_tell_you的博客 3485

IntelliJ IDEA Maven Project Dependencies红色波浪线报错

原文地址:https://www.jianshu.com/p/45a609b2049f 本人使用了第一种方法就解决了 第一问题描述 对于 idea 下的 maven 工程,特别是从其他地方导入的新工程,右边 maven 管理工具中 dependencies 若出现红色波浪线。通常用以下方式尝试解决。 1、 检查 repository 和 setting

sunny_12138的博客 3万+

在IDEA中使用Jedis操作redis出现build运行报错,出现“程序包不存在,找不到符号”问题

bug为找不到jedis的包,虽然maven已经加载jedis依赖成功。参考网上,特此记录一下,原因是IDEA的build操作和maven的build操作是分开的,不是一回事。需要将两者统一。 具体做法: 需要注意,编译器需要设置为Java8 运行成功: ...

qq_44250808的博客 2254

在IDEA中使用Jedis操作redis出现build运行报错

在IDEA中使用Jedis操作redis出现build运行报错,出现“程序包不存在,找不到符号”问题 问题描述 原因分析: idea自身的原因 解决方案: 在terminal中执行这个命令mvn idea:idea

Charlieyuyue的博客 752
上一篇: redis.clients.jedis.exceptions.JedisBusyException:无法处理异常的解决方法,亲测有效
下一篇: redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cl异常的解决方法,亲测有效,嘿嘿嘿
代码无疆
博客等级 码龄3年 4万+粉丝 305原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值