Package redis.clients.jedis

Examples of redis.clients.jedis.Transaction


      String object = TicketSerializer.serialize(ticket);
      String journal = TicketSerializer.serialize(change);

      // atomically store ticket
      Transaction t = jedis.multi();
      t.set(key(repository, KeyType.ticket, ticketId), object);
      t.rpush(key(repository, KeyType.journal, ticketId), journal);
      t.exec();

      log.debug("updated ticket {} in Redis @ {}", "" + ticketId, getUrl());
      return true;
    } catch (JedisException e) {
      log.error("failed to update ticket cache in Redis @ " + getUrl(), e);
View Full Code Here


    public static List<?> tx(JedisAtom jedisAtom) {
        List<?> result = null;
        Jedis jedis = pool.getResource();
        try {
            Transaction trans = jedis.multi();
            jedisAtom.action(trans);
            result = trans.exec();
        }catch (Exception e){
            LOG.error(e.getMessage(), e);
        }finally {
            if(null != jedis){
                pool.returnResource(jedis);
View Full Code Here

  public void testMulti() throws Exception {
    byte[] key = "key".getBytes();
    byte[] value = "value".getBytes();

    BinaryJedis jedis = (BinaryJedis) connection.getNativeConnection();
    Transaction multi = jedis.multi();
    //connection.set(key, value);
    multi.set(value, key);
    System.out.println(multi.exec());

    connection.multi();
    connection.set(value, key);
    System.out.println(connection.exec());
  }
View Full Code Here

        try {
//            jedis.pipelined(new PipelineBlock() {
//                @Override
//                public void execute() {
            Transaction multi = jedis.multi();
            while (events.hasNext()) {
                DomainEventMessage domainEvent = events.next();
                multi.rpush(new String(key, IOUtils.UTF8), new String(eventSerializer.serialize(domainEvent, byte[].class)
                                                                             .getData(), IOUtils.UTF8));
            }
            multi.exec();
//                }
//            });
//            redis.clients.jedis.Transaction transaction = jedis.multi();
//            while (events.hasNext()) {
//                DomainEvent domainEvent = events.next();
View Full Code Here

   * @return Score and rank for a member in the named leaderboard
   */
  public Hashtable<String, Object> scoreAndRankForIn(String leaderboardName, String member, boolean useZeroIndexForRank) {
    Hashtable<String, Object> data = new Hashtable<String, Object>();
   
    Transaction transaction = _jedis.multi();
        transaction.zscore(leaderboardName, member);
        transaction.zrevrank(leaderboardName, member);
        List<Object> response = transaction.exec();
               
    data.put("member", member);
    data.put("score", response.get(0));   
    if (useZeroIndexForRank) {
        data.put("rank", response.get(1));
View Full Code Here

    public boolean releaseLock(Jedis conn, String lockName, String identifier) {
        lockName = "lock:" + lockName;
        while (true) {
            conn.watch(lockName);
            if (identifier.equals(conn.get(lockName))) {
                Transaction trans = conn.multi();
                trans.del(lockName);
                List<Object> result = trans.exec();
                // null response indicates that the transaction was aborted due
                // to the watched key changing.
                if (result == null){
                    continue;
                }
View Full Code Here

        if (conn.hget("users:", llogin) != null) {
            return -1;
        }

        long id = conn.incr("user:id:");
        Transaction trans = conn.multi();
        trans.hset("users:", llogin, String.valueOf(id));
        Map<String,String> values = new HashMap<String,String>();
        values.put("login", login);
        values.put("id", String.valueOf(id));
        values.put("name", name);
        values.put("followers", "0");
        values.put("following", "0");
        values.put("posts", "0");
        values.put("signup", String.valueOf(System.currentTimeMillis()));
        trans.hmset("user:" + id, values);
        trans.exec();
        releaseLock(conn, "user:" + llogin, lock);
        return id;
    }
View Full Code Here

            return false;
        }

        long now = System.currentTimeMillis();

        Transaction trans = conn.multi();
        trans.zadd(fkey1, now, String.valueOf(otherUid));
        trans.zadd(fkey2, now, String.valueOf(uid));
        trans.zcard(fkey1);
        trans.zcard(fkey2);
        trans.zrevrangeWithScores("profile:" + otherUid, 0, HOME_TIMELINE_SIZE - 1);

        List<Object> response = trans.exec();
        long following = (Long)response.get(response.size() - 3);
        long followers = (Long)response.get(response.size() - 2);
        Set<Tuple> statuses = (Set<Tuple>)response.get(response.size() - 1);

        trans = conn.multi();
        trans.hset("user:" + uid, "following", String.valueOf(following));
        trans.hset("user:" + otherUid, "followers", String.valueOf(followers));
        if (statuses.size() > 0) {
            for (Tuple status : statuses){
                trans.zadd("home:" + uid, status.getScore(), status.getElement());
            }
        }
        trans.zremrangeByRank("home:" + uid, 0, 0 - HOME_TIMELINE_SIZE - 1);
        trans.exec();

        return true;
    }
View Full Code Here

        if (conn.zscore(fkey1, String.valueOf(otherUid)) == null) {
            return false;
        }

        Transaction trans = conn.multi();
        trans.zrem(fkey1, String.valueOf(otherUid));
        trans.zrem(fkey2, String.valueOf(uid));
        trans.zcard(fkey1);
        trans.zcard(fkey2);
        trans.zrevrange("profile:" + otherUid, 0, HOME_TIMELINE_SIZE - 1);

        List<Object> response = trans.exec();
        long following = (Long)response.get(response.size() - 3);
        long followers = (Long)response.get(response.size() - 2);
        Set<String> statuses = (Set<String>)response.get(response.size() - 1);

        trans = conn.multi();
        trans.hset("user:" + uid, "following", String.valueOf(following));
        trans.hset("user:" + otherUid, "followers", String.valueOf(followers));
        if (statuses.size() > 0){
            for (String status : statuses) {
                trans.zrem("home:" + uid, status);
            }
        }

        trans.exec();
        return true;
    }
View Full Code Here

        return createStatus(conn, uid, message, null);
    }
    public long createStatus(
        Jedis conn, long uid, String message, Map<String,String> data)
    {
        Transaction trans = conn.multi();
        trans.hget("user:" + uid, "login");
        trans.incr("status:id:");

        List<Object> response = trans.exec();
        String login = (String)response.get(0);
        long id = (Long)response.get(1);

        if (login == null) {
            return -1;
        }

        if (data == null){
            data = new HashMap<String,String>();
        }
        data.put("message", message);
        data.put("posted", String.valueOf(System.currentTimeMillis()));
        data.put("id", String.valueOf(id));
        data.put("uid", String.valueOf(uid));
        data.put("login", login);

        trans = conn.multi();
        trans.hmset("status:" + id, data);
        trans.hincrBy("user:" + uid, "posts", 1);
        trans.exec();
        return id;
    }
View Full Code Here

TOP

Related Classes of redis.clients.jedis.Transaction

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.