示例#1
0
 private void remove(final int index) {
   commandExecutor.write(
       getName(),
       codec,
       new SyncOperation<V>() {
         @Override
         public V execute(Codec codec, RedisConnection conn) {
           if (index == 0) {
             return conn.sync(codec, RedisCommands.LPOP, getName());
           }
           while (true) {
             conn.sync(RedisCommands.WATCH, getName());
             List<Object> tail =
                 conn.sync(codec, RedisCommands.LRANGE, getName(), index + 1, size());
             conn.sync(RedisCommands.MULTI);
             conn.sync(codec, RedisCommands.LTRIM, getName(), 0, index - 1);
             if (tail.isEmpty()) {
               if (((List<Object>) conn.sync(codec, RedisCommands.EXEC)).size() == 1) {
                 return null;
               }
             } else {
               tail.add(0, getName());
               conn.sync(codec, RedisCommands.RPUSH, tail.toArray());
               if (((List<Object>) conn.sync(codec, RedisCommands.EXEC)).size() == 2) {
                 return null;
               }
             }
           }
         }
       });
 }
示例#2
0
  public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name) {
    super(codec, commandExecutor, name);

    loadComparator();

    commandExecutor.write(
        getName(), StringCodec.INSTANCE, RedisCommands.SETNX, getCurrentVersionKey(), 0L);
  }
示例#3
0
 @Override
 public boolean remove(final Object value) {
   return commandExecutor.write(
       getName(),
       codec,
       new SyncOperation<Boolean>() {
         @Override
         public Boolean execute(Codec codec, RedisConnection conn) {
           return remove(value, codec, conn);
         }
       });
 }
示例#4
0
  @Override
  public boolean trySet(Map<String, ?> buckets) {
    if (buckets.isEmpty()) {
      return false;
    }

    List<Object> params = new ArrayList<Object>(buckets.size());
    for (Entry<String, ?> entry : buckets.entrySet()) {
      params.add(entry.getKey());
      try {
        params.add(codec.getValueEncoder().encode(entry.getValue()));
      } catch (IOException e) {
        throw new IllegalArgumentException(e);
      }
    }

    return commandExecutor.write(params.get(0).toString(), RedisCommands.MSETNX, params.toArray());
  }