81,092
社区成员
发帖
与我相关
我的任务
分享
String script = "if redis.call('exists', KEYS[1]) == 0 then return redis.call('set', KEYS[1], ARGV[1]) else return 0 end";
ShardedJedis jedis = RedisCacheFactory.getInstance().getResource(cluster);
Jedis shard = jedis.getShard(key);
Object msg = shard.eval(script,
Collections.singletonList(key),
Collections.singletonList(JSONUtil.toJSONStringWithClassName(value)));
自己搞定了,贴一下核心代码,还是写的lua脚本,之所以感觉难,是因为不懂lua,其实只是很基本的语句。