标签:ttext 依赖 inf cat Lua脚本 return rip img ali
一、添加maven依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
二、application.yml配置redis环境信息
spring:
redis:
host: 172.16.2.95
timeout: 1000ms
三、依赖注入
/** * Redis工具类 * * @author zjc * @date 2021/2/4 14:35 */ @Component public class RedisUtil { /** * redis模板 */ private RedisTemplate redisTemplate; private ValueOperations<String, String> valueOperations; private HashOperations<String, String, String> hashOperations; private ListOperations<String, String> listOperations; private SetOperations<String, String> setOperations; private ZSetOperations<String, String> zSetOperations; @Autowired public RedisUtil(StringRedisTemplate redisTemplate) { this.redisTemplate = redisTemplate; this.valueOperations = redisTemplate.opsForValue(); this.hashOperations = redisTemplate.opsForHash(); this.listOperations = redisTemplate.opsForList(); this.setOperations = redisTemplate.opsForSet(); this.zSetOperations = redisTemplate.opsForZSet(); } private static final String LUA_SCRIPT_HGETALL = "local r = {} for _, v in pairs(KEYS) do r[#r+1] = redis.call(‘HGETALL‘, v) end return r"; public void lua() { List<String> keys = new ArrayList<>(); keys.add("key1"); keys.add("key2"); // DefaultRedisScript<List> getRedisScript = new DefaultRedisScript(); // getRedisScript.setScriptText(LUA_SCRIPT_HGETALL); // getRedisScript.setResultType(List.class); Object ob = redisTemplate.execute(RedisScript.of(LUA_SCRIPT_HGETALL, List.class), keys); System.out.println(JSONUtil.toJsonStr(ob)); } }
注意:
返回值只能为Long,Boolean,List,或deserialized。
标签:ttext 依赖 inf cat Lua脚本 return rip img ali
原文地址:https://www.cnblogs.com/Jackbao/p/14873298.html