Package redis.clients.jedis

Examples of redis.clients.jedis.ShardedJedis


    }
    redisPool.returnResource(rds);
  }
 
  public boolean exists() {
    ShardedJedis rds = redisPool.getResource();
    boolean ex = rds.exists(getDirNameBytes());
    redisPool.returnResource(rds);
    return ex;
  }
View Full Code Here


  }
 
  private long dirSize() throws IOException {
    long ret = 0;
   
    ShardedJedis rds = redisPool.getResource();
    Map<byte[], byte[]> lst = rds.hgetAll(getDirNameBytes());
    if( lst == null || lst.size() < 1)
      return 0;
    for(byte[] sz: lst.values() ){
      try{ ret += ByteBuffer.wrap(sz).asLongBuffer().get(); }catch(Exception e){}
    }
View Full Code Here

    return ret;
  }

  @Override
  public synchronized void close() throws IOException {
    ShardedJedis rds = redisPool.getResource();
    directorySize = dirSize();
    rds.hset(getDirNameBytes(), ":size".getBytes(), ByteBuffer.allocate(Long.SIZE/8).putLong(directorySize).array());
   
    //Issue save on each
    Collection<Jedis> ls = rds.getAllShards();
    for(Jedis jds: ls){
      try{
        jds.bgsave();
      }catch(JedisDataException e){
        System.err.println(e);
View Full Code Here

  }

  @Override
  public boolean fileExists(String filename) throws IOException {
    boolean ret = false;
    ShardedJedis rds = redisPool.getResource();
    ret = rds.hexists(getDirNameBytes(), filename.getBytes());
    redisPool.returnResourceObject(rds);
    return ret;
  }
View Full Code Here

    return new RedisFile(filename, this, redisPool).size();
  }

  @Override
  public String[] listAll() throws IOException {
    ShardedJedis rds = redisPool.getResource();
    Set<String> ls = rds.hkeys(dirName);
    if( ls == null ){
      return new String[0];
    }
    String[] ret = new String[ls.size()];
    ls.toArray(ret);
View Full Code Here

    size();
    readBuffer();
  }
 
  public synchronized long size() {
    ShardedJedis jd = redisPool.getResource();
    byte [] p = jd.hget(directory.getDirNameBytes(), getNameBytes());
    if( p != null && p.length == Long.SIZE/8 ){
      this.fileLength = ByteBuffer.wrap(p).asLongBuffer().get();
    }
    redisPool.returnResource(jd);
    return this.fileLength;
View Full Code Here

    flushBuffer();
  }
 
  protected synchronized void flushBuffer() throws IOException {
    if( dirtyBuffer ) {
      ShardedJedis jd = redisPool.getResource();
      if( RedisDirectory.COMPRESSED ){
        byte[] compressed = Snappy.compress(buffer);
        jd.set(blockAddress(), compressed);
      }else{
        jd.set(blockAddress(), buffer);
      }
      if( fileExtended ){
        jd.hset(directory.getDirNameBytes(), getNameBytes(), ByteBuffer.allocate(Long.SIZE/8).putLong(fileLength).array());
        directory.reloadSizeFromFiles();
        fileExtended = false;
      }
      redisPool.returnResource(jd);
    }
View Full Code Here

    }
    dirtyBuffer = false;
  }
 
  protected synchronized void readBuffer() throws IOException {
    ShardedJedis jd = redisPool.getResource();
    buffer = jd.get(blockAddress());
    if( buffer != null && RedisDirectory.COMPRESSED) {
      buffer = Snappy.uncompress(buffer);
    }
    if( buffer == null || buffer.length != BufferLength ){
      buffer = new byte [this.BufferLength];
View Full Code Here

      if( bytesWrite > bytesLeft ) bytesWrite = (int) bytesLeft;
    }   
  }
 
  public synchronized void delete() {
    ShardedJedis jd = redisPool.getResource();
    jd.hdel(directory.getDirNameBytes(), getPathBytes());
    redisPool.returnResource(jd);
    dirtyBuffer = false;
  }
View Full Code Here

        for (String field : shardFields) {
            idx.cat(fields.get(field));
            sfields[s++] = fields.get(field);
        }
        idx = idx.fork();
        ShardedJedis jedis = Seek.getPool().getResource();
        Jedis shard = jedis.getShard(idx.key());
        try {
            if (shard.exists(idx.cat(id).key())) {
                seek.remove(id, sfields);
            }
            Pipeline p = shard.pipelined();
View Full Code Here

TOP

Related Classes of redis.clients.jedis.ShardedJedis

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.