@Override public Object getNativeConnection() { return convertAndReturn(delegate.getNativeConnection(), identityConverter); }
@Override public Object getNativeConnection() { return redisConnection.getNativeConnection(); }
@Override public String doInRedis(RedisConnection connection) throws DataAccessException { String px = SET_WITH_EXPIRE_TIME_MILL; if (TimeUnit.SECONDS.equals(timeUnit)) { px = SET_WITH_EXPIRE_TIME_SEC; } Jedis jedis = (Jedis) connection.getNativeConnection(); return jedis.set(lockName, lockValue, SET_IF_NOT_EXIST, px, leaseTime); } };
@Override public Object doInRedis(RedisConnection connection) throws DataAccessException { String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end"; Jedis jedis = (Jedis) connection.getNativeConnection(); return jedis.eval(script, Collections.singletonList(lockName), Collections.singletonList(lockValue)); } };
public Object doInRedis(final RedisConnection connection) throws DataAccessException { ((Jedis) connection.getNativeConnection()).publish(channel, message); return null; } });
@Override public Object doInRedis(RedisConnection connection) throws DataAccessException { return ((Jedis) connection.getNativeConnection()).scriptLoad(script); } });
@Override public Object doInRedis(RedisConnection connection) throws DataAccessException { return ((Jedis) connection.getNativeConnection()).evalsha(sha, keycount, args); } });
@Override public Object doInRedis(RedisConnection connection) throws DataAccessException { ((Jedis) connection.getNativeConnection()).subscribe(jedisPubSub, channels); return null; } });
@Override public Object getNativeConnection() { return convertAndReturn(delegate.getNativeConnection(), identityConverter); }
@Override public Object getNativeConnection() { return convertAndReturn(delegate.getNativeConnection(), identityConverter); }
private boolean setRedis(final String key, final long expire) { try { String result = redisTemplate.execute((RedisCallback<String>) connection -> { JedisCommands commands = (JedisCommands) connection.getNativeConnection(); String uuid = UUID.randomUUID().toString(); lockFlag.set(uuid); return commands.set(key, uuid, "NX", "PX", expire); }); return !StringUtils.isEmpty(result); } catch (Exception e) { log.error("set redisDistributeLock occured an exception", e); } return false; }
private boolean setRedis(final String key, final long expire) { try { String result = redisTemplate.execute((RedisCallback<String>) connection -> { JedisCommands commands = (JedisCommands) connection.getNativeConnection(); String uuid = UUID.randomUUID().toString(); lockFlag.set(uuid); return commands.set(key, uuid, "NX", "PX", expire); }); return !StringUtils.isEmpty(result); } catch (Exception e) { log.error("set redisDistributeLock occured an exception", e); } return false; }
/** * 使用jedis管道测试用例 */ public static Jedis getJedis() { return (Jedis) stringRedisTemplate.getConnectionFactory().getConnection().getNativeConnection(); }
@Override public Object doInRedis(RedisConnection connection) throws DataAccessException { Jedis jedis = (Jedis) connection.getNativeConnection(); jedis.pipelined().lpush("", ""); return null; } };
private Object getConnection() { Object connection; if (type == RedisToolsConstant.SINGLE) { RedisConnection redisConnection = jedisConnectionFactory.getConnection(); connection = redisConnection.getNativeConnection(); } else { RedisClusterConnection clusterConnection = jedisConnectionFactory.getClusterConnection(); connection = clusterConnection.getNativeConnection(); } return connection; }
/** * get Redis connection * @return */ private Object getConnection() { Object connection ; if (type == RedisToolsConstant.SINGLE){ RedisConnection redisConnection = jedisConnectionFactory.getConnection(); connection = redisConnection.getNativeConnection(); }else { RedisClusterConnection clusterConnection = jedisConnectionFactory.getClusterConnection(); connection = clusterConnection.getNativeConnection() ; } return connection; }
/** * get Redis connection * @return */ private Object getConnection() { Object connection ; if (type == RedisToolsConstant.SINGLE){ RedisConnection redisConnection = jedisConnectionFactory.getConnection(); connection = redisConnection.getNativeConnection(); }else { RedisClusterConnection clusterConnection = jedisConnectionFactory.getClusterConnection(); connection = clusterConnection.getNativeConnection() ; } return connection; }
private boolean putLockKey(long leaseMillSec) { RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection(); JedisCommands commands = (JedisCommands) redisConnection.getNativeConnection(); String res = commands.set(key, getCurrThreadId(), "NX", "PX", leaseMillSec); redisConnection.close(); return (res != null && "OK".equalsIgnoreCase(res)) || redisTemplate.opsForValue().get(key).equals(getCurrThreadId()); }
private boolean putLockKey(long leaseMillSec) { RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection(); String res = ((JedisCommands) redisConnection.getNativeConnection()).set(key, getCurrThreadId(), "NX", "PX", leaseMillSec); redisConnection.close(); return "OK".equalsIgnoreCase(res); }
@GetMapping(value = "/getRedis") public Problem getRedis() { redisConnectionFactory.getConnection().getNativeConnection(); byte[] bytes = redisConnectionFactory.getConnection().stringCommands().get("key".getBytes()); if (bytes != null) { String value = new String(bytes, StandardCharsets.UTF_8); String stringValue = stringRedisTemplate.opsForValue().get("stringKey"); return Problem.builder().with("data", value + "_" + stringValue).build(); } else { return Problem.valueOf(Status.BAD_REQUEST); } }