public class RedisTemplateUtils extends Object
redis.call:抛出异常给调用方
redis.pcall:捕获异常并以Lua表的形式返回给调用方
| 构造器和说明 |
|---|
RedisTemplateUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T |
evalScript(org.springframework.data.redis.core.RedisTemplate<?,?> redisTemplate,
org.springframework.data.redis.core.script.RedisScript<T> script,
byte[][] keys,
byte[]... args) |
static <T> T |
evalScript(org.springframework.data.redis.core.RedisTemplate<?,?> redisTemplate,
org.springframework.data.redis.core.script.RedisScript<T> script,
int numKeys,
byte[][] keysAndArgs)
Execute lua script for redis
为了保证脚本里面的所有操作都在相同slot进行,云数据库Redis集群版本会对Lua脚本做如下限制:
1、所有key都应该由KEYS数组来传递,脚本中执行命令`redis.call/pcall`的参数必须是KEYS[i],不能使用本地变量(如`local key1 = KEY[i]; redis.call('get', key1)`)
2、所有key必须在一个slot上,否则报错:ERR eval/evalsha command keys must be in same slot
3、调用必须要带有key,否则报错:ERR for redis cluster, eval/evalsha number of keys can't be negative or zero
|
public static <T> T evalScript(org.springframework.data.redis.core.RedisTemplate<?,?> redisTemplate,
org.springframework.data.redis.core.script.RedisScript<T> script,
byte[][] keys,
byte[]... args)
public static <T> T evalScript(org.springframework.data.redis.core.RedisTemplate<?,?> redisTemplate,
org.springframework.data.redis.core.script.RedisScript<T> script,
int numKeys,
byte[][] keysAndArgs)
Execute lua script for redis
为了保证脚本里面的所有操作都在相同slot进行,云数据库Redis集群版本会对Lua脚本做如下限制:
1、所有key都应该由KEYS数组来传递,脚本中执行命令`redis.call/pcall`的参数必须是KEYS[i],不能使用本地变量(如`local key1 = KEY[i]; redis.call('get', key1)`)
2、所有key必须在一个slot上,否则报错:ERR eval/evalsha command keys must be in same slot
3、调用必须要带有key,否则报错:ERR for redis cluster, eval/evalsha number of keys can't be negative or zero
T - the return typeredisTemplate - the redis templatescript - the lua scriptnumKeys - the number of keyskeysAndArgs - the keys and argumentsRedisTemplate.execute(RedisScript, List, Object...),
RedisTemplate.execute(RedisScript, RedisSerializer, RedisSerializer, List, Object...)Copyright © 2024. All rights reserved.