當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.auth方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.auth方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.auth方法的具體用法?Java Jedis.auth怎麽用?Java Jedis.auth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.auth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkJedisIsReusedWhenReturned

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void checkJedisIsReusedWhenReturned() {

  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:JedisPoolTest.java

示例2: testResetStateWithFullyExecutedTransaction

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void testResetStateWithFullyExecutedTransaction() {
  Jedis jedis2 = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
  jedis2.auth("foobared");

  Transaction t = jedis2.multi();
  t.set("mykey", "foo");
  t.get("mykey");

  List<Object> resp = t.exec();
  assertNotNull(resp);
  assertEquals(2, resp.size());

  jedis2.resetState();
  jedis2.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:TransactionCommandsTest.java

示例3: main

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public static void main(String[] args) throws UnknownHostException, IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  Pipeline p = jedis.pipelined();
  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    String key = "foo" + n;
    p.set(key, "bar" + n);
    p.get(key);
  }
  p.sync();

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:23,代碼來源:PipelinedGetSetBenchmark.java

示例4: main

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public static void main(String[] args) throws UnknownHostException, IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    String key = "foo" + n;
    jedis.set(key, "bar" + n);
    jedis.get(key);
  }

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,代碼來源:GetSetBenchmark.java

示例5: timeoutConnection

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test(expected = JedisConnectionException.class)
public void timeoutConnection() throws Exception {
  jedis = new Jedis("localhost", 6379, 15000);
  jedis.auth("foobared");
  jedis.configSet("timeout", "1");
  Thread.sleep(2000);
  jedis.hmget("foobar", "foo");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:JedisTest.java

示例6: getNumActiveReturnsTheCorrectNumber

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void getNumActiveReturnsTheCorrectNumber() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));

  assertEquals(1, pool.getNumActive());

  Jedis jedis2 = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");

  assertEquals(2, pool.getNumActive());

  pool.returnResource(jedis);
  assertEquals(1, pool.getNumActive());

  pool.returnResource(jedis2);

  assertEquals(0, pool.getNumActive());

  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:26,代碼來源:JedisPoolTest.java

示例7: getResource

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private Jedis getResource() {
    Jedis resource = jedisPool.getResource();
    if (StringUtils.isBlank(password)) {
        return resource;
    } else {
        resource.auth(password);
        return resource;
    }
}
 
開發者ID:xubinux,項目名稱:xbin-store,代碼行數:10,代碼來源:JedisClientSingle.java

示例8: makeObject

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public PooledObject<Jedis> makeObject() throws Exception {
    final HostAndPort hostAndPort = this.hostAndPort.get();
    JaRedis.Builder builder = new JaRedis.Builder();
    builder
            .host(hostAndPort.getHost())
            .port(hostAndPort.getPort())
            .connectionTimeout(connectionTimeout)
            .soTimeout(soTimeout);
    Jedis jedis = builder.build();
    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);
}
 
開發者ID:YanXs,項目名稱:nighthawk,代碼行數:28,代碼來源:JaRedisFactory.java

示例9: startWithUrlString

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void startWithUrlString() {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.select(2);
  j.set("foo", "bar");
  Jedis jedis = new Jedis("redis://:[email protected]:6380/2");
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:11,代碼來源:JedisTest.java

示例10: setUp

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
  super.setUp();

  nj = new Jedis(hnp.getHost(), hnp.getPort(), 500);
  nj.connect();
  nj.auth("foobared");
  nj.flushAll();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:10,代碼來源:TransactionCommandsTest.java

示例11: testBitfield

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void testBitfield() {
  Jedis jedis = new Jedis("redis://localhost:6380");
  jedis.auth("foobared");
  jedis.del("mykey");
  try {
    List<Long> responses = jedis.bitfield("mykey", "INCRBY","i5","100","1", "GET", "u4", "0");
    assertEquals(1l, responses.get(0).longValue());
    assertEquals(0l, responses.get(1).longValue());
  } finally {
    jedis.del("mykey");
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:14,代碼來源:JedisTest.java

示例12: setUp

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {

  node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
  node1.auth("cluster");
  node1.flushAll();

  node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
  node2.auth("cluster");
  node2.flushAll();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:12,代碼來源:ClusterCommandsTest.java

示例13: checkCloseableConnections

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void checkCloseableConnections() throws Exception {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();

  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
      "foobared", 2);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:JedisSentinelPoolTest.java

示例14: startWithUrl

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void startWithUrl() throws URISyntaxException {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.select(2);
  j.set("foo", "bar");
  Jedis jedis = new Jedis(new URI("redis://:[email protected]st:6380/2"));
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:11,代碼來源:JedisTest.java

示例15: connectWithoutShardInfo

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * Tests opening a default SSL/TLS connection to redis.
 */
@Test
public void connectWithoutShardInfo() {
  // The "rediss" scheme instructs jedis to open a SSL/TLS connection.
  Jedis jedis = new Jedis(URI.create("rediss://localhost:6390"));
  jedis.auth("foobared");
  jedis.get("foo");
  jedis.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:12,代碼來源:SSLJedisTest.java


注:本文中的redis.clients.jedis.Jedis.auth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。