// Path: src/main/java/biz/paluch/spinach/api/DisqueConnection.java
// public interface DisqueConnection<K, V> extends StatefulConnection<K, V> {
// 
//     /**
//      * Returns the {@link DisqueCommands} API for the current connection. Does not create a new connection.
//      * 
//      * @return the synchronous API for the underlying connection.
//      */
//     DisqueCommands<K, V> sync();
// 
//     /**
//      * Returns the {@link DisqueAsyncCommands} API for the current connection. Does not create a new connection.
//      * 
//      * @return the asynchronous API for the underlying connection.
//      */
//     DisqueAsyncCommands<K, V> async();
// 
//     /**
//      * Returns the {@link DisqueReactiveCommands} API for the current connection. Does not create a new connection.
//      *
//      * @return the reactive API for the underlying connection.
//      */
//     DisqueReactiveCommands<K, V> reactive();
// 
// }
// 
// Path: src/main/java/biz/paluch/spinach/api/sync/DisqueCommands.java
// public interface DisqueCommands<K, V> extends DisqueJobCommands<K, V>, DisqueQueueCommands<K, V>, DisqueServerCommands<K, V>,
//         DisqueClusterCommands<K, V> {
// 
//     /**
//      * Authenticate to the server.
//      *
//      * @param password the password
//      * @return String simple-string-reply
//      */
//     String auth(String password);
// 
//     /**
//      * Close the connection. The connection will become not usable anymore as soon as this method was called.
//      */
//     void close();
// 
//     /**
//      *
//      * @return the underlying connection.
//      */
//     DisqueConnection<K, V> getConnection();
// 
//     /**
//      *
//      * @return true if the connection is open (connected and not closed).
//      */
//     boolean isOpen();
// 
//     /**
//      * Ping the server.
//      *
//      * @return simple-string-reply
//      */
//     String ping();
// 
//     /**
//      * Close the connection.
//      * 
//      * @return String simple-string-reply always OK.
//      */
//     String quit();
// 
//     /**
//      * Set the default timeout for operations.
//      *
//      * @param timeout the timeout value
//      * @param unit the unit of the timeout value
//      */
//     void setTimeout(long timeout, TimeUnit unit);
// }


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.lambdaworks.redis.internal.AbstractInvocationHandler;
import com.lambdaworks.redis.internal.LettuceLists;
import biz.paluch.spinach.api.DisqueConnection;
import biz.paluch.spinach.api.sync.DisqueCommands;
import rx.Observable;
            Object result = targetMethod.invoke(rxApi, args);

            if (result == null || !(result instanceof Observable<?>)) {
                return result;
            }
            Observable<?> observable = (Observable<?>) result;

            Iterable<?> objects = observable.toBlocking().toIterable();

            if (method.getReturnType().equals(List.class)) {
                return LettuceLists.newList(objects);
            }

            if (method.getReturnType().equals(Set.class)) {
                return new LinkedHashSet<>(LettuceLists.newList(objects));
            }

            Iterator<?> iterator = objects.iterator();

            if (iterator.hasNext()) {
                return iterator.next();
            }

            return null;

        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
    }

// Path: src/main/java/biz/paluch/spinach/api/DisqueConnection.java
// public interface DisqueConnection<K, V> extends StatefulConnection<K, V> {
// 
//     /**
//      * Returns the {@link DisqueCommands} API for the current connection. Does not create a new connection.
//      * 
//      * @return the synchronous API for the underlying connection.
//      */
//     DisqueCommands<K, V> sync();
// 
//     /**
//      * Returns the {@link DisqueAsyncCommands} API for the current connection. Does not create a new connection.
//      * 
//      * @return the asynchronous API for the underlying connection.
//      */
//     DisqueAsyncCommands<K, V> async();
// 
//     /**
//      * Returns the {@link DisqueReactiveCommands} API for the current connection. Does not create a new connection.
//      *
//      * @return the reactive API for the underlying connection.
//      */
//     DisqueReactiveCommands<K, V> reactive();
// 
// }
// 
// Path: src/main/java/biz/paluch/spinach/api/sync/DisqueCommands.java
// public interface DisqueCommands<K, V> extends DisqueJobCommands<K, V>, DisqueQueueCommands<K, V>, DisqueServerCommands<K, V>,
//         DisqueClusterCommands<K, V> {
// 
//     /**
//      * Authenticate to the server.
//      *
//      * @param password the password
//      * @return String simple-string-reply
//      */
//     String auth(String password);
// 
//     /**
//      * Close the connection. The connection will become not usable anymore as soon as this method was called.
//      */
//     void close();
// 
//     /**
//      *
//      * @return the underlying connection.
//      */
//     DisqueConnection<K, V> getConnection();
// 
//     /**
//      *
//      * @return true if the connection is open (connected and not closed).
//      */
//     boolean isOpen();
// 
//     /**
//      * Ping the server.
//      *
//      * @return simple-string-reply
//      */
//     String ping();
// 
//     /**
//      * Close the connection.
//      * 
//      * @return String simple-string-reply always OK.
//      */
//     String quit();
// 
//     /**
//      * Set the default timeout for operations.
//      *
//      * @param timeout the timeout value
//      * @param unit the unit of the timeout value
//      */
//     void setTimeout(long timeout, TimeUnit unit);
// }


// Path: src/test/java/biz/paluch/spinach/commands/rx/RxSyncInvocationHandler.java
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.lambdaworks.redis.internal.AbstractInvocationHandler;
import com.lambdaworks.redis.internal.LettuceLists;
import biz.paluch.spinach.api.DisqueConnection;
import biz.paluch.spinach.api.sync.DisqueCommands;
import rx.Observable;

            Object result = targetMethod.invoke(rxApi, args);

            if (result == null || !(result instanceof Observable<?>)) {
                return result;
            }
            Observable<?> observable = (Observable<?>) result;

            Iterable<?> objects = observable.toBlocking().toIterable();

            if (method.getReturnType().equals(List.class)) {
                return LettuceLists.newList(objects);
            }

            if (method.getReturnType().equals(Set.class)) {
                return new LinkedHashSet<>(LettuceLists.newList(objects));
            }

            Iterator<?> iterator = objects.iterator();

            if (iterator.hasNext()) {
                return iterator.next();
            }

            return null;

        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
    }

    public static <K, V> DisqueCommands<K, V> sync(DisqueConnection<K, V> connection) {