redis.clients.jedis.Jedis.auth()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(353)

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

Jedis.auth介绍

暂无

代码示例

代码示例来源:origin: shuzheng/zheng

/**
 * 同步获取Jedis实例
 * @return Jedis
 */
public synchronized static Jedis getJedis() {
  poolInit();
  Jedis jedis = null;
  try {
    if (null != jedisPool) {
      jedis = jedisPool.getResource();
      try {
        jedis.auth(PASSWORD);
      } catch (Exception e) {
      }
    }
  } catch (Exception e) {
    LOGGER.error("Get jedis error : " + e);
  }
  return jedis;
}

代码示例来源:origin: qiurunze123/miaosha

/**
   * 统计访问次数
   */
  public static void vistorCount(String key) {

    Jedis jedis = null;
    Object object = null;
    try {
      jedis = RedisManager.getJedis();
      String count =
          "local num=redis.call('incr',KEYS[1]) return num";
      List<String> keys = new ArrayList<String>();
      keys.add(key);
      List<String> argves = new ArrayList<String>();
      jedis.auth("youxin11");
      String luaScript = jedis.scriptLoad(count);
      System.out.println(luaScript);
      jedis.evalsha(luaScript, keys, argves);
    } catch (Exception e) {
      logger.error("统计访问次数失败!!!",e);
    }
  }
}

代码示例来源:origin: qiurunze123/miaosha

/**
   * 未完成  需 evalsha更方便 限制ip 或者 手机号访问次数
   */
  public static void getLuaLimit() {

    Jedis jedis = null;
    try {
      jedis = RedisManager.getJedis();
    } catch (Exception e) {
      e.printStackTrace();
    }
    String lua =
        "local num=redis.call('incr',KEYS[1]) if tonumber(num)==1 " +
            "then redis.call('expire',KEYS[1],ARGV[1]) " +
            "return 1 elseif tonumber(num)>" +
            "tonumber(ARGV[2]) then return 0 else return 1 end";

    List<String> keys = new ArrayList<String>();
    keys.add("ip:limit:127.0.0.1");
    List<String> argves = new ArrayList<String>();
    argves.add("6000");
    argves.add("5");
    jedis.auth("xxxx");
//        Object evalSha = jedis.evalsha(lua);
    String luaScript = jedis.scriptLoad(lua);
    System.out.println(luaScript);
    Object object = jedis.evalsha(luaScript, keys, argves);
    System.out.println(object);
  }

代码示例来源:origin: Dreampie/Resty

private Jedis getJedis() {
 Jedis jedis = null;
 if (pool != null && pool instanceof JedisPool) {
  jedis = (Jedis) pool.getResource();
 }
 //hp[0] is hostname,hp[1] is port,hp[2] is the password of redis
 if (jedis == null) {
  String[] hp = host.split(":");
  jedis = new Jedis(hp[0], Integer.parseInt(hp[1]), timeout);
  if (hp.length >= 3) {
   jedis.auth(hp[2]);
  }
 }
 return jedis;
}

代码示例来源:origin: qiurunze123/miaosha

/**
 * 统计访问次数
 */
public static Object getVistorCount(String key) {
  Jedis jedis = null;
  Object object = null;
  try {
    jedis = RedisManager.getJedis();
  String count =
      "local num=redis.call('get',KEYS[1]) return num";
  List<String> keys = new ArrayList<String>();
  keys.add(key);
  List<String> argves = new ArrayList<String>();
  jedis.auth("youxin11");
  String luaScript = jedis.scriptLoad(count);
  System.out.println(luaScript);
  object = jedis.evalsha(luaScript, keys, argves);
  } catch (Exception e) {
    logger.error("统计访问次数失败!!!",e);
    return "0";
  }
  return  object;
}

代码示例来源:origin: caoxinyu/RedisClient

public void execute() {
  server = service.listById(id);
  this.jedis = new Jedis(server.getHost(), Integer.parseInt(server.getPort()), timeout);
  if(server.getPassword() != null && server.getPassword().length() > 0)
    jedis.auth(server.getPassword());
  
  runCommand();
  
  jedis.close();
}

代码示例来源:origin: sohutv/cachecloud

@Override
public PooledObject<Jedis> makeObject() throws Exception {
 final HostAndPort hostAndPort = this.hostAndPort.get();
 final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout,
   soTimeout);
 try {
  jedis.connect();
  if (null != this.password) {
   jedis.auth(this.password);
  }
  if (database != 0) {
   jedis.select(database);
  }
  if (clientName != null) {
   jedis.clientSetname(clientName);
  }
 } catch (JedisException je) {
  jedis.close();
  throw je;
 }
 return new DefaultPooledObject<Jedis>(jedis);
}

代码示例来源:origin: zendesk/maxwell

public MaxwellRedisProducer(MaxwellContext context, String redisPubChannel, String redisListKey, String redisType) {
  super(context);
  channel = redisPubChannel;
  listkey = redisListKey;
  redistype = redisType;
  jedis = new Jedis(context.getConfig().redisHost, context.getConfig().redisPort);
  jedis.connect();
  if (context.getConfig().redisAuth != null) {
    jedis.auth(context.getConfig().redisAuth);
  }
  if (context.getConfig().redisDatabase > 0) {
    jedis.select(context.getConfig().redisDatabase);
  }
}

代码示例来源:origin: Impetus/Kundera

connection.auth(password);

代码示例来源:origin: knightliao/disconf-demos-java

public static Jedis createJedis(String host, int port, String passwrod) {
    Jedis jedis = new Jedis(host, port);

    if (!StringUtils.isNotBlank(passwrod))
      jedis.auth(passwrod);

    return jedis;
  }
}

代码示例来源:origin: knightliao/disconf-demos-java

public static Jedis createJedis(String host, int port, String password) {
    Jedis jedis = new Jedis(host, port);

    if (!StringUtils.isNotBlank(password)) {
      jedis.auth(password);
    }

    return jedis;
  }
}

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public String auth(String password) {
 String command = "auth";
 return instrumented(command, () -> delegated.auth(password));
}

代码示例来源:origin: zhangyingwei/cockroach

public RedisTaskQueue(String host, Integer port, String auth, Integer index, String key,String failedKey) {
  this.key = key;
  this.failedKey = failedKey;
  this.jedis = new Jedis(host, port);
  this.jedis.auth(auth);
  this.jedis.select(index);
}

代码示例来源:origin: gresrun/jesque

private void authenticateAndSelectDB() {
  if (this.config.getPassword() != null) {
    this.jedis.auth(this.config.getPassword());
  }
  this.jedis.select(this.config.getDatabase());
}

代码示例来源:origin: gresrun/jesque

private void authenticateAndSelectDB() {
  if (this.config.getPassword() != null) {
    this.jedis.auth(this.config.getPassword());
  }
  this.jedis.select(this.config.getDatabase());
}

代码示例来源:origin: com.lordofthejars/nosqlunit-redis

public RedisConfiguration build() {
  
  Jedis jedis = new Jedis(this.redisConfiguration.getHost(), this.redisConfiguration.getPort());
  
  if(this.redisConfiguration.getPassword() != null) {
    String status = jedis.auth(this.redisConfiguration.getPassword());
    
    if(!"OK".equalsIgnoreCase(status)) {
      throw new IllegalStateException("Password is not valid and Redis access cannot be accept commands.");
    }
    
  }
  this.redisConfiguration.setDatabaseOperation(new RedisOperation(jedis));
  return redisConfiguration;
}

代码示例来源:origin: lordofthejars/nosql-unit

public RedisConfiguration build() {
  
  Jedis jedis = new Jedis(this.redisConfiguration.getHost(), this.redisConfiguration.getPort());
  
  if(this.redisConfiguration.getPassword() != null) {
    String status = jedis.auth(this.redisConfiguration.getPassword());
    
    if(!"OK".equalsIgnoreCase(status)) {
      throw new IllegalStateException("Password is not valid and Redis access cannot be accept commands.");
    }
    
  }
  this.redisConfiguration.setDatabaseOperation(new RedisOperation(jedis));
  return redisConfiguration;
}

代码示例来源:origin: gresrun/jesque

private void authenticateAndSelectDB() {
  if (this.config.getPassword() != null) {
    this.jedis.auth(this.config.getPassword());
  }
  this.jedis.select(this.config.getDatabase());
}

代码示例来源:origin: org.caiguoqing/uyuni-registry

private void init(){
  jedis = new Jedis(config.getHost(),config.getPort(),config.getTimeout());
  jedis.auth(config.getPass());
  jedis.select(config.getDatabase());
}

代码示例来源:origin: org.caiguoqing/uyuni-monitor

private void init(){
  jedis = new Jedis(config.getHost(),config.getPort(),config.getTimeout());
  jedis.auth(config.getPass());
  jedis.select(config.getDatabase());
}

相关文章

Jedis类方法