Package org.jredis

Examples of org.jredis.JRedis


    return factory;
  }

  @Test
  public void testRaw() throws Exception {
    JRedis jr = (JRedis) factory.getConnection().getNativeConnection();

    System.out.println(jr.dbsize());
    System.out.println(jr.exists("foobar"));
    jr.set("foobar", "barfoo");
    System.out.println(jr.get("foobar"));
  }
View Full Code Here


        return list;
    }

    public void dropIndex(final String indexName) {
        String idxName = RedisIndex.normalizeName(indexName);
        JRedis db = this.graph.getDatabase();

        try {
            List<String> keyList = db.keys(RedisIndexKeys.AUTO + idxName + ":*");
            for(String key : keyList){
                    db.del(key);
            }

            keyList = db.keys(RedisIndexKeys.META_AUTO + idxName + ":*");
            for(String key : keyList){
                    db.del(key);
            }

            db.lrem(RedisIndexKeys.META_INDICES_AUTO, idxName, 0);

            keyList = db.keys(RedisIndexKeys.MANUAL + idxName + ":*");
            for(String key : keyList){
                    db.del(key);
            }

            keyList = db.keys(RedisIndexKeys.META_MANUAL + idxName + ":*");
            for(String key : keyList){
                    db.del(key);
            }

            db.lrem(RedisIndexKeys.META_INDICES_MANUAL, idxName, 0);
        } catch (RedisException e) {
            e.printStackTrace();
        }

        this.manualIndices.remove(idxName);
View Full Code Here

        }
        return list;
    }

    private void saveIndexMeta(final String type, final String indexName, final String className, Set<String> keys){
        JRedis db = this.graph.getDatabase();

        try {
            if (type.equals(RedisIndexKeys.AUTO)) {
                db.lpush(RedisIndexKeys.META_INDICES_AUTO, indexName);
                db.set(RedisIndexKeys.META_AUTO + indexName + ":class", className);
                if(null != keys){
                    String key_list = RedisIndexKeys.META_AUTO + indexName + ":keys";
                    for(String key : keys){
                        db.sadd(key_list, key);
                    }
                }
            } else {
                db.lpush(RedisIndexKeys.META_INDICES_MANUAL, indexName);
                db.set(RedisIndexKeys.META_MANUAL + indexName + ":class", className);
            }
        } catch (RedisException e) {
            e.printStackTrace();
        }
    }
View Full Code Here

        this.restoreIndices(RedisIndexKeys.MANUAL);
        this.restoreMode = false;
    }

    public void restoreIndices(String type){
        JRedis db = this.graph.getDatabase();

        String metaIndices = type.equals(RedisIndexKeys.AUTO) ? RedisIndexKeys.META_INDICES_AUTO : RedisIndexKeys.META_INDICES_MANUAL;
        String metaType    = type.equals(RedisIndexKeys.AUTO) ? RedisIndexKeys.META_AUTO : RedisIndexKeys.META_MANUAL;

        try {
            List<byte[]> indices = db.lrange(metaIndices, 0, db.llen(metaIndices));

            if(null == indices) return;

            for(byte[] idx: indices){
                String indexName = new String(idx);

                String className = new String(db.get(metaType + indexName + ":class"));

                Class indexClass = Class.forName(className);

                List<byte[]> keys = db.smembers(metaType + indexName + ":keys");
                HashSet<String> indexKeys = new HashSet<String>();

                if(null != keys){
                    for(byte[] key : keys){
                        indexKeys.add(new String(key));
View Full Code Here

  }

  private void run() throws RedisException {
    int database = 11;
    ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes());
    JRedis jredis = new JRedisClient(connSpec);
   
    byte[] key = "bench-jredis-pipeline-key".getBytes();
    int iters = 100 * 1000;
   
    try {
      cleandb(jredis);
    } catch (Throwable e) {
      e.printStackTrace();
      return;
    }
   
    for(;;){
      Long counter = null;
      long start = System.nanoTime();
      for(int i=0;i<iters; i++){
        counter = jredis.incr(key);
      }
      long delta_ns = System.nanoTime() - start;
      long delta_ms = TimeUnit.MILLISECONDS.convert(delta_ns, TimeUnit.NANOSECONDS);
      float opsrate = iters/delta_ms;
      System.out.format("counter: %d  msec:%d ops/msecs:%f  [delta:%d]\n", counter, delta_ms, opsrate, delta_ns);
View Full Code Here

*/

public class JRedisClientJProfileSubject extends JRedisJProfileSubject{

  public static void main(String[] args) throws RedisException {
    JRedis jredis;
        jredis = new JRedisClient("localhost", 6379, "jredis", 0);
    new JRedisJProfileSubject (jredis).run();
  }
View Full Code Here

    new HelloAgain().run(password);
  }

  private void run(String password) {
    try {
      JRedis  jredis = new JRedisClient("localhost", 6379, "jredis", 0);
      jredis.ping();
     
      if(!jredis.exists(key)) {
        jredis.set(key, "Hello Again!");
        System.out.format("Hello!  You should run me again!\n");
      }
      else {
        String msg = toStr ( jredis.get(key) );
        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

  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

  /* (non-Javadoc)
   * @see org.jredis.ri.alphazero.JRedisProviderTestNGBase#newJRedisProviderInstance()
   */
  protected JRedis newProviderInstance () {
    JRedis provider = null;
    try {
      provider = new JRedisClient (this.host, this.port, this.password, this.db1);
        }
        catch (ClientRuntimeException e) {
          Log.error(e.getLocalizedMessage());
View Full Code Here

   */
  @AfterTest
  public void testQuit() {
    Log.log("TEST: QUIT command");
    try {
      JRedis provider = getProviderInstance();
      provider.quit ();
    }
    catch (Exception e) {
      fail("QUIT" + 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.