org.springframework.data.redis.connection.RedisConnection.getNativeConnection()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(379)

本文整理了Java中org.springframework.data.redis.connection.RedisConnection.getNativeConnection方法的一些代码示例,展示了RedisConnection.getNativeConnection的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisConnection.getNativeConnection方法的具体详情如下:
包路径:org.springframework.data.redis.connection.RedisConnection
类名称:RedisConnection
方法名:getNativeConnection

RedisConnection.getNativeConnection介绍

[英]Returns the native connection (the underlying library/driver object).
[中]返回本机连接(底层库/驱动程序对象)。

代码示例

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Object getNativeConnection() {
  return convertAndReturn(delegate.getNativeConnection(), identityConverter);
}

代码示例来源:origin: 1991wangliang/tx-lcn

@Override
public Object getNativeConnection() {
  return redisConnection.getNativeConnection();
}

代码示例来源:origin: dqeasycloud/easy-cloud

@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);
  }
};

代码示例来源:origin: dqeasycloud/easy-cloud

@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));
  }
};

代码示例来源:origin: ysrc/Liudao

public Object doInRedis(final RedisConnection connection)
      throws DataAccessException {
    ((Jedis) connection.getNativeConnection()).publish(channel, message);
    return null;
  }
});

代码示例来源:origin: ysrc/Liudao

@Override
  public Object doInRedis(RedisConnection connection) throws DataAccessException {
    return ((Jedis) connection.getNativeConnection()).scriptLoad(script);
  }
});

代码示例来源:origin: ysrc/Liudao

@Override
  public Object doInRedis(RedisConnection connection) throws DataAccessException {
    return ((Jedis) connection.getNativeConnection()).evalsha(sha, keycount, args);
  }
});

代码示例来源:origin: ysrc/Liudao

@Override
  public Object doInRedis(RedisConnection connection) throws DataAccessException {
    ((Jedis) connection.getNativeConnection()).subscribe(jedisPubSub, channels);
    return null;
  }
});

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public Object getNativeConnection() {
  return convertAndReturn(delegate.getNativeConnection(), identityConverter);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Object getNativeConnection() {
  return convertAndReturn(delegate.getNativeConnection(), identityConverter);
}

代码示例来源:origin: liuht777/Taroco

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;
}

代码示例来源:origin: com.y3tu/y3tu-tool-web

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;
}

代码示例来源:origin: dqeasycloud/easy-cloud

/**
 * 使用jedis管道测试用例
 */
public static Jedis getJedis() {
  return (Jedis) stringRedisTemplate.getConnectionFactory().getConnection().getNativeConnection();
}

代码示例来源:origin: dqeasycloud/easy-cloud

@Override
  public Object doInRedis(RedisConnection connection) throws DataAccessException {
    Jedis jedis = (Jedis) connection.getNativeConnection();
    jedis.pipelined().lpush("", "");
    return null;
  }
};

代码示例来源:origin: liuht777/Taroco

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;
}

代码示例来源:origin: crossoverJie/distributed-redis-tool

/**
 * 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;
}

代码示例来源:origin: crossoverJie/distributed-redis-tool

/**
 * 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;
}

代码示例来源:origin: aillamsun/devX

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());
}

代码示例来源:origin: gudaoxuri/dew

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);
}

代码示例来源:origin: lord-of-code/loc-framework

@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);
 }
}

相关文章

微信公众号

最新文章

更多

RedisConnection类方法