lua redisson执行lua脚本

相关类与接口

RedissonClient

public interface RedissonClient {RScript getScript();RScript getScript(Codec var1);

Redisson

public class Redisson implements RedissonClient {public RScript getScript() {return new RedissonScript(this.commandExecutor);}public RScript getScript(Codec codec) {return new RedissonScript(this.commandExecutor, codec);}

RScript:redissonScript实现了该接口

public interface RScript extends RScriptAsync {<R> R evalSha(RScript.Mode var1, String var2, RScript.ReturnType var3, List<Object> var4, Object... var5);<R> R evalSha(String var1, RScript.Mode var2, String var3, RScript.ReturnType var4, List<Object> var5, Object... var6);<R> R evalSha(RScript.Mode var1, String var2, RScript.ReturnType var3);<R> R eval(String var1, RScript.Mode var2, String var3, RScript.ReturnType var4, List<Object> var5, Object... var6);<R> R eval(RScript.Mode var1, String var2, RScript.ReturnType var3, List<Object> var4, Object... var5);<R> R eval(RScript.Mode var1, String var2, RScript.ReturnType var3);//直接执行脚本String scriptLoad(String var1);     //先加载脚本(缓存到redis),evalSha调用该返回值执行脚本List<Boolean> scriptExists(String... var1);void scriptKill();void scriptFlush();********
内部枚举:RScript.ReturnTypepublic static enum ReturnType {BOOLEAN(RedisCommands.EVAL_BOOLEAN_SAFE),INTEGER(RedisCommands.EVAL_LONG),MULTI(RedisCommands.EVAL_LIST),STATUS(RedisCommands.EVAL_STRING),VALUE(RedisCommands.EVAL_OBJECT),MAPVALUE(RedisCommands.EVAL_MAP_VALUE),MAPVALUELIST(RedisCommands.EVAL_MAP_VALUE_LIST);private final RedisCommand<?> command;private ReturnType(RedisCommand<?> command) {this.command = command;}public RedisCommand<?> getCommand() {return this.command;}}********
内部枚举:RScript.Modepublic static enum Mode {READ_ONLY,     //只读READ_WRITE;    //读写private Mode() {}}
}

使用示例

test.lua

redis.call("set",KEYS[1], ARGV[1])
return redis.call("get", KEYS[1])

RedissonLuaTest

public class RedissonLuaTest {public static void main(String[] args) throws Exception{Config config = new Config();config.useSingleServer().setAddress("redis://localhost:6380");RedissonClient client = Redisson.create(config);RScript rScript = client.getScript();String script = IOUtils.toString(new FileInputStream("./test.lua"), StandardCharsets.UTF_8);String value = rScript.eval(RScript.Mode.READ_WRITE, script, RScript.ReturnType.VALUE, Collections.singletonList("key"), "瓜田李下");System.out.println("直接执行脚本:"+value);String evalSha = rScript.scriptLoad(script);String value2 = rScript.evalSha(RScript.Mode.READ_WRITE, evalSha, RScript.ReturnType.VALUE, Collections.singletonList("key2"), "海贼王");System.out.println("先缓存,后执行脚本:"+value2);}
}

控制台输出

return redis.call("get", KEYS[1]), 1, key, PooledUnsafeDirectByteBuf(ridx: 0, widx: 15, cap: 256)] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using node localhost/127.0.0.1:6380... RedisConnection@32821182 [redisClient=[addr=redis://localhost:6380], channel=[id: 0xac407b67, L:/127.0.0.1:50197 - R:localhost/127.0.0.1:6380], currentCommand=null, usage=1]
20:25:21.595 [redisson-netty-2-3] DEBUG org.redisson.command.RedisExecutor - connection released for command (EVAL) and params [redis.call("set",KEYS[1], ARGV[1])
return redis.call("get", KEYS[1]), 1, key, PooledUnsafeDirectByteBuf(ridx: 0, widx: 15, cap: 256)] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using connection RedisConnection@32821182 [redisClient=[addr=redis://localhost:6380], channel=[id: 0xac407b67, L:/127.0.0.1:50197 - R:localhost/127.0.0.1:6380], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture@5c697f53[Completed normally], command=(EVAL), params=[redis.call("set",KEYS[1], ARGV[1])
return redis.call("get", KEYS[1]), 1, key, PooledUnsafeDirectByteBuf(ridx: 0, widx: 15, cap: 256)], codec=org.redisson.codec.MarshallingCodec], usage=0]
直接执行脚本:瓜田李下20:25:21.596 [main] DEBUG org.redisson.command.RedisExecutor - acquired connection for command (SCRIPT LOAD) and params [redis.call("set",KEYS[1], ARGV[1])
return redis.call("get", KEYS[1])] from slot NodeSource [slot=null, addr=null, redisClient=null, redirect=null, entry=MasterSlaveEntry [masterEntry=[freeSubscribeConnectionsAmount=1, freeSubscribeConnectionsCounter=value:50:queue:0, freeConnectionsAmount=23, freeConnectionsCounter=value:63:queue:0, freezeReason=null, client=[addr=redis://localhost:6380], nodeType=MASTER, firstFail=0]]] using node localhost/127.0.0.1:6380... RedisConnection@41474609 [redisClient=[addr=redis://localhost:6380], channel=[id: 0x30723635, L:/127.0.0.1:50198 - R:localhost/127.0.0.1:6380], currentCommand=null, usage=1]
20:25:21.599 [redisson-netty-2-4] DEBUG org.redisson.command.RedisExecutor - connection released for command (SCRIPT LOAD) and params [redis.call("set",KEYS[1], ARGV[1])
return redis.call("get", KEYS[1])] from slot NodeSource [slot=null, addr=null, redisClient=null, redirect=null, entry=MasterSlaveEntry [masterEntry=[freeSubscribeConnectionsAmount=1, freeSubscribeConnectionsCounter=value:50:queue:0, freeConnectionsAmount=24, freeConnectionsCounter=value:64:queue:0, freezeReason=null, client=[addr=redis://localhost:6380], nodeType=MASTER, firstFail=0]]] using connection RedisConnection@41474609 [redisClient=[addr=redis://localhost:6380], channel=[id: 0x30723635, L:/127.0.0.1:50198 - R:localhost/127.0.0.1:6380], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture@307dbd30[Completed normally], command=(SCRIPT LOAD), params=[redis.call("set",KEYS[1], ARGV[1])
return redis.call("get", KEYS[1])], codec=org.redisson.codec.MarshallingCodec], usage=0]
20:25:21.600 [main] DEBUG org.redisson.command.RedisExecutor - acquired connection for command (EVALSHA) and params [6c45d62f3875095a03105f73b04c64e77b17fa1e, 1, key2, PooledUnsafeDirectByteBuf(ridx: 0, widx: 12, cap: 256)] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using node localhost/127.0.0.1:6380... RedisConnection@2002317052 [redisClient=[addr=redis://localhost:6380], channel=[id: 0xcbb1cd3f, L:/127.0.0.1:50200 - R:localhost/127.0.0.1:6380], currentCommand=null, usage=1]
20:25:21.602 [redisson-netty-2-9] DEBUG org.redisson.command.RedisExecutor - connection released for command (EVALSHA) and params [6c45d62f3875095a03105f73b04c64e77b17fa1e, 1, key2, PooledUnsafeDirectByteBuf(ridx: 0, widx: 12, cap: 256)] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using connection RedisConnection@2002317052 [redisClient=[addr=redis://localhost:6380], channel=[id: 0xcbb1cd3f, L:/127.0.0.1:50200 - R:localhost/127.0.0.1:6380], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture@429c4759[Completed normally], command=(EVALSHA), params=[6c45d62f3875095a03105f73b04c64e77b17fa1e, 1, key2, PooledUnsafeDirectByteBuf(ridx: 0, widx: 12, cap: 256)], codec=org.redisson.codec.MarshallingCodec], usage=0]
先缓存,后执行脚本:海贼王

lua redisson执行lua脚本相关推荐

  1. Lua:01---Lua语言介绍、运行Lua程序(lua解释器)

    一.Lua语言介绍 Lua语言从一开始就被设计为能与C/C++及其他常用语言开发的软件集成在一起使用的语言,这种设计带来了非常多的好处: 一方面, Lua语言不需要在性能.与三方软件交互等C语言已经非 ...

  2. redis-cli redisTemplate执行Lua脚本,解决redisTemplate.opsForSet().members获取数据问题

    解决问题-问题描述 在使用redisTemplate.opsForSet().members(key)获取key String; value Set<Entity>数据时候出现如下问题. ...

  3. PHP中使用redis执行lua脚本示例

    一.引言 redis学了一段时间了,基本的东西都没问题了.从今天开始讲写一些redis和lua脚本的相关的东西,lua这个脚本是一个好东西,可以运行在任何平台上,也可以嵌入到大多数语言当中,来扩展其功 ...

  4. PHP中使用redis 执行lua脚本

    在php中,可以通过redis执行lua脚本 1.脚本 <?php $redis = new Redis(); #实例化redis类 $redis->connect('127.0.0.1' ...

  5. android lua sd卡,记Android层执行Lua脚本的一次实践

    0. 前言 最近一直在写Lua脚本,有时候出了问题,不知道是Lua层的问题,还是上游的问题,不知道从何下手.于是我学习了一点C/C++和JNI,把整个解析Lua脚本包.执行Lua脚本的流程全部都读了一 ...

  6. 转lua解释执行脚本流程

    本文转自:http://www.cnblogs.com/zxh1210603696/p/4458473.html #include "lua.hpp"#include <io ...

  7. lua是编译成c语言再执行嘛,go_lua_c: 使用go编译lua脚本为字节码,通过网络传给c,通过c执行lua脚本。...

    go_lua_c 项目介绍 使用go编译lua脚本为字节码,通过网络传给c,通过c执行lua脚本. 本项目包含go - lua - c之间相互调用的方法,值得学习 如何使用 1.windos先安装mi ...

  8. redisTemplate执行lua脚本

    项目场景: 提示:redisTemplate执行lua脚本 例如:项目场景: 问题描述 提示:执行lua脚本 例如: 原因分析: 提示:这里填写问题的分析: 例如: afadf 解决方案: 提示:这里 ...

  9. Redis:EVAL执行Lua脚本

    EVAL 脚本 numkeys 键[键...] arg [arg ...] 自Redis2.6.0版本起可用. 时间复杂度:取决于执行的脚本. EVAL介绍 EVAL和EVALSHA用于从Redis2 ...

  10. Python通过Django搭建网站执行Lua脚本 (实现数据解析)

    目录 Python通过Django搭建网站执行Lua脚本 (实现数据解析) 一.问题背景和解决 二.执行Lua效果预览 三.主要代码解析: translate.py LuaParser.lua Bin ...

最新文章

  1. 从源码分析DEARGUI之动态绘图的两种方法
  2. 自动化办公之excel教程(3):数据编辑操作,表格的美化操作,应用表格样式和单元格样式,制作报销汇总单
  3. 《剑指offer》和为s的连续正数序列
  4. 计算机社团竞选优势6,社团社长竞选稿六篇
  5. 深挖Kubernetes存储为何如此难及其解决方案
  6. 知识图谱-构建:知识图谱构建流程【本体构建、知识抽取(实体抽取、 关系抽取、属性抽取)、知识表示、知识融合、知识存储】
  7. GIS 矢量数据 编码方式
  8. 基于 IPO 经济理论模型对目前 ICO 的理论研究和分析
  9. 按字段和行项目数量拆单
  10. html dt和dd顺序,dl dt dd使用方法
  11. Azure语音合成再添新声音,“风格迁移”技术为不同音色实现多情感演绎
  12. linux交叉编译 windows,从Windows到Linux的C ++交叉编译器
  13. 客户端连接linux的MySQL数据库出现被自己拒绝的错误
  14. MySQL limit 1,1的含义
  15. 数据指标体系之战略指标
  16. 2018远程案例三星笔记本硬盘错误信息分析
  17. Android获取手机IMEI号和IMSI号
  18. js使原元素获取焦点以及移除焦点的方法
  19. 电子秤c语言编程,基于AT89C51的数字电子秤的设计最终版(样例3)
  20. android 7.0 官方网址,安卓7.0

热门文章

  1. matlab分段函数怎么画图_关于MATLAB中分段函数的画法
  2. 编程器测试软件,CH341A编程器
  3. linu修改open files无效_安卓容器app如何使用 容器app修改机型方法【详解】
  4. 继承几近失传的经典吟诵-余觉中
  5. 巧用主力进出、主力买卖指标进行波段操作——逃顶和抄底
  6. matlab做聚类分析(简单的直接用clusterdata)
  7. 用yum下载安装gcc
  8. php图书管理系统外文文献,JSP图书管理系统论文+源码+英文文献翻译+参考文献 第10页...
  9. 一款相当好用的排版软件
  10. 80x86汇编小站站长简单介绍