Package org.jredis

Examples of org.jredis.JRedis


  }

  private void run(String password) {
    try {
      ConnectionSpec spec = DefaultConnectionSpec.newSpec().setCredentials(password);
      JRedis  jredis = new JRedisClient(spec);
      jredis.ping();
     
      if(!jredis.exists(bkey)) {
        jredis.set(bkey, "Hello Again!");
        System.out.format("Hello!  You should run me again!\n");
      }
      else {
        String msg = toStr ( jredis.get(bkey) );
        System.out.format("%s\n", msg);
      }
      jredis.quit();
    }
    catch (RedisException e){
      if (e.getCommand()==Command.PING){
        System.out.format("I'll need that password!  Try again with password as command line arg for this program.\n");
      }
View Full Code Here


      final int wcnt = 10;
      final int opcnt = 20000;
      final Thread[] workers = new Thread[wcnt];
     
      final JRedis client = jredis;
      for(int i=0; i<workers.length; i++) {
        final int j = i;
        workers[i] = new Thread(new Runnable() {
        @Override
        public void run() {
              final String wkey = "foo" + j;
              String wvalue = null;
          for(int i=0; i< opcnt; i++) {
                try {
                  client.incr(wkey);
                  wvalue = toStr(client.get(wkey));
            } catch (RedisException e) {
              e.printStackTrace();
              break;
            }
          }
View Full Code Here

  public static void usingSyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedis jredis = new JRedisClient(spec);

    System.out.println ("\nusing the SyncClient: \n\n");
   
    useMSet (jredis);
    useMSetNX (jredis);
    jredis.quit();
  }
View Full Code Here

  public static void usingSyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedis jredis = new JRedisClient(spec);

    System.out.println ("** using JRedis **");
   
    useZRangeSubset (jredis);
   
    jredis.quit();
  }
View Full Code Here

  }

  @Test
  public void testGetResource() throws RedisException {
    this.pool = new JredisPool(connectionSpec);
    JRedis client = pool.getResource();
    assertNotNull(client);
    client.ping();
  }
View Full Code Here

  public void testGetResourcePoolExhausted() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    this.pool = new JredisPool(connectionSpec, poolConfig);
    JRedis client = pool.getResource();
    assertNotNull(client);
    try {
      pool.getResource();
      fail("PoolException should be thrown when pool exhausted");
    } catch (PoolException e) {
View Full Code Here

  @Test
  public void testGetResourceValidate() {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setTestOnBorrow(true);
    this.pool = new JredisPool(connectionSpec, poolConfig);
    JRedis client = pool.getResource();
    assertNotNull(client);
  }
View Full Code Here

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    this.pool = new JredisPool(connectionSpec);
    JRedis client = pool.getResource();
    assertNotNull(client);
    pool.returnResource(client);
    assertNotNull(pool.getResource());
  }
View Full Code Here

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxTotal(1);
    poolConfig.setMaxWaitMillis(1);
    this.pool = new JredisPool(connectionSpec, poolConfig);
    JRedis client = pool.getResource();
    assertNotNull(client);
    pool.returnBrokenResource(client);
    JRedis client2 = pool.getResource();
    assertNotSame(client, client2);
    try {
      client.ping();
      fail("Broken resouce connection should be closed");
    } catch (NotConnectedException e) {}
View Full Code Here

TOP

Related Classes of org.jredis.JRedis

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.