Package org.jredis.ri.alphazero

Examples of org.jredis.ri.alphazero.JRedisClient


    public static final String indexdir = "index/";

    @Before
    public void setUp() throws IOException, RedisException {
        Runtime.getRuntime().exec("rm -rf " + indexdir);
        JRedisClient redis = new JRedisClient();
        redis.del("_0_exampletag", "_0_updatedtag");
    }
View Full Code Here


    private String segmentName;
    private JRedisClient redis;

    public RedisUpdatingFieldsConsumer(SegmentWriteState state) {
        segmentName = state.segmentInfo.name;
        redis = new JRedisClient();     // TODO: host, port, etc!
    }
View Full Code Here

    private JRedisClient redis;
    private String segment;

    public RedisUpdatingFieldsProducer(SegmentReadState state) {
        this.segment = state.segmentInfo.name;
        this.redis = new JRedisClient();    // TODO: host, port, etc
    }
View Full Code Here

        }

    }

    private static void updateSegment(String segment, BitSet docs, Diff diff) throws IOException {
        JRedisClient redis = new JRedisClient();
        try {
            for (Term add : diff.getAdds()) {
                String key = segment + "_" + add.text();
                if (!redis.exists(key)) {
                    // New key - just add it with the current bitset
                    //int[] docset = new int[docs.cardinality()];
                    ByteBuffer bytes = ByteBuffer.allocate(docs.cardinality() * 4);
                    IntBuffer docset = bytes.asIntBuffer();
                    for (int i = docs.nextSetBit(0), j = 0; i >= 0; i = docs.nextSetBit(i + 1), j++) {
                        docset.put(j, i);
                    }
                    redis.set(key, bytes.array());
                }
                else {
                    byte[] orig = redis.get(key);
                    int[] origpostings = new int[orig.length / 4];
                    int[] newpostings = new int[origpostings.length + docs.cardinality()];
                    ByteBuffer.wrap(orig).asIntBuffer().get(origpostings);
                    //ByteBuffer buffer = ByteBuffer.allocate(orig.length + docs.cardinality() * 4);
                    //IntBuffer postings = buffer.asIntBuffer();
                    int spos = 0, dpos = 0, ndoc = -1;
                    while ((ndoc = docs.nextSetBit(ndoc + 1)) >= 0) {
                        if (spos >= origpostings.length) {
                            newpostings[dpos++] = ndoc;
                        }
                        else {
                            int upto = Arrays.binarySearch(origpostings, ndoc);
                            if (upto < 0) {
                                upto = -(upto + 1);
                                System.arraycopy(origpostings, spos, newpostings, dpos, upto - spos);
                                dpos += upto - spos;
                                spos = upto;
                                newpostings[dpos++] = ndoc;
                            }
                            else {
                                // We already exist in this document, so just copy the old stuff up
                                System.arraycopy(origpostings, spos, newpostings, dpos, upto - spos);
                                dpos += upto - spos;
                                spos = upto;
                            }
                        }
                    }
                    ByteBuffer bb = ByteBuffer.allocate(newpostings.length * 4);
                    bb.asIntBuffer().put(newpostings);
                    redis.set(key, bb.array());
                }
            }
            for (Term del : diff.getDeletes()) {
                String key = segment + "_" + del.text();
                if (!redis.exists(key)) {
                    continue;
                }
                byte[] orig = redis.get(key);
                int[] origpostings = new int[orig.length / 4];
                int[] newpostings = new int[origpostings.length - docs.cardinality()];
                ByteBuffer.wrap(orig).asIntBuffer().get(origpostings);

                int spos = 0, dpos = 0, ndoc = -1;
                while ((ndoc = docs.nextSetBit(ndoc + 1)) >= 0) {
                    if (spos >= origpostings.length)
                        break;
                    while (origpostings[spos++] < ndoc) {
                        newpostings[dpos++] = origpostings[spos];
                    }
                    spos++;
                }
                if (spos < origpostings.length) {
                    System.arraycopy(origpostings, spos, newpostings, dpos, origpostings.length - spos);
                }
                ByteBuffer bb = ByteBuffer.allocate(newpostings.length * 4);
                bb.asIntBuffer().put(newpostings);
                redis.set(key, bb.array());
            }
        } catch (RedisException e) {
            throw new IOException(e);
        }
    }
View Full Code Here

  }


  @Override
  public RedisConnection getConnection() {
    return postProcessConnection(new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec))));
  }
View Full Code Here

    protected Map<String, RedisIndex> indices = new HashMap<String, RedisIndex>();
    protected Map<String, RedisAutomaticIndex> autoIndices = new HashMap<String, RedisAutomaticIndex>();

    public RedisGraph() {
        database = new JRedisClient();
    }
View Full Code Here

    public RedisGraph() {
        database = new JRedisClient();
    }

    public RedisGraph(String password) {
        database = new JRedisClient(password);
    }
View Full Code Here

    public RedisGraph(String password) {
        database = new JRedisClient(password);
    }

    public RedisGraph(String host, int port) {
        database = new JRedisClient(host, port);
    }
View Full Code Here

    public RedisGraph(String host, int port) {
        database = new JRedisClient(host, port);
    }

    public RedisGraph(String host, int port, String password, int database) {
        this.database = new JRedisClient(host, port, password, database);
    }
View Full Code Here

    new JRedisClientBenchmark().runBenchmarks (host, port, workerCnt, reqCnt, size, db);
  }
 
  @Override
  protected final JRedis newConnection(String host, int port, int db, String password) throws ClientRuntimeException {
    return new JRedisClient(host, port, password, db);
  }
View Full Code Here

TOP

Related Classes of org.jredis.ri.alphazero.JRedisClient

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.