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


Java Jedis.connect方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: setUp

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
  jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500);
  jedis.connect();
  jedis.auth("foobared");
  jedis.configSet("timeout", "300");
  jedis.flushAll();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:JedisCommandTestBase.java

示例5: createJedis

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
protected Jedis createJedis() {
  Jedis j = new Jedis(hnp.getHost(), hnp.getPort());
  j.connect();
  j.auth("foobared");
  j.flushAll();
  return j;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:8,代碼來源:JedisCommandTestBase.java

示例6: 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

示例7: main

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  Jedis j = new Jedis(hnp.getHost(), hnp.getPort());
  j.connect();
  j.auth("foobared");
  j.flushAll();
  j.quit();
  j.disconnect();
  long t = System.currentTimeMillis();
  // withoutPool();
  withPool();
  long elapsed = System.currentTimeMillis() - t;
  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:14,代碼來源:PoolBenchmark.java

示例8: main

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Jedis j = new Jedis("127.0.0.1", 6379);
    j.connect();
    j.auth("weimob123");
    j.flushAll();
    j.quit();
    j.disconnect();
    long t = System.currentTimeMillis();
    // withoutPool();
    withPool();
    long elapsed = System.currentTimeMillis() - t;
    System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:14,代碼來源:PoolTest.java

示例9: get

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Dependent
@Produces
public Jedis get(InjectionPoint ip) {
    System.out.println("injecting Jedis into " + ip.getMember().getDeclaringClass().getSimpleName());
    String redisHost = System.getenv().getOrDefault("REDIS_HOST", "192.168.99.100");
    String redisPort = System.getenv().getOrDefault("REDIS_PORT", "6379");

    Jedis jedis = new Jedis(redisHost, Integer.valueOf(redisPort), 10000);
    jedis.connect();
    System.out.println("Redis Connection obtained");
    return jedis;
}
 
開發者ID:abhirockzz,項目名稱:redis-cdi-example,代碼行數:13,代碼來源:JedisProducer.java


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