All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.redis.runtime.datasource.ReactiveHashCommandsImpl Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.redis.runtime.datasource;

import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import io.quarkus.redis.datasource.ReactiveRedisDataSource;
import io.quarkus.redis.datasource.ScanArgs;
import io.quarkus.redis.datasource.hash.ReactiveHashCommands;
import io.quarkus.redis.datasource.hash.ReactiveHashScanCursor;
import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.redis.client.Response;

public class ReactiveHashCommandsImpl extends AbstractHashCommands implements ReactiveHashCommands {

    private final ReactiveRedisDataSource reactive;

    public ReactiveHashCommandsImpl(ReactiveRedisDataSourceImpl redis, Type k, Type f, Type v) {
        super(redis, k, f, v);
        this.reactive = redis;
    }

    @Override
    public ReactiveRedisDataSource getDataSource() {
        return reactive;
    }

    @SafeVarargs
    @Override
    public final Uni hdel(K key, F... fields) {
        return super._hdel(key, fields)
                .map(Response::toInteger);
    }

    @Override
    public Uni hexists(K key, F field) {
        return super._hexists(key, field)
                .map(Response::toBoolean);
    }

    @Override
    public Uni hget(K key, F field) {
        return super._hget(key, field)
                .map(this::decodeV);
    }

    @Override
    public Uni hincrby(K key, F field, long amount) {
        return super._hincrby(key, field, amount)
                .map(Response::toLong);
    }

    @Override
    public Uni hincrbyfloat(K key, F field, double amount) {
        return super._hincrbyfloat(key, field, amount)
                .map(Response::toDouble);
    }

    @Override
    public Uni> hgetall(K key) {
        return super._hgetall(key)
                .map(this::decodeMap);
    }

    @Override
    public Uni> hkeys(K key) {
        return super._hkeys(key)
                .map(this::decodeListOfField);
    }

    @Override
    public Uni hlen(K key) {
        return super._hlen(key)
                .map(Response::toLong);
    }

    @SafeVarargs
    @Override
    public final Uni> hmget(K key, F... fields) {
        return super._hmget(key, fields)
                .map(r -> decodeOrderedMap(r, fields));
    }

    @Override
    public Uni hmset(K key, Map map) {
        return super._hmset(key, map).replaceWithVoid();
    }

    @Override
    public Uni hrandfield(K key) {
        return super._hrandfield(key)
                .map(this::decodeF);
    }

    @Override
    public Uni> hrandfield(K key, long count) {
        return super._hrandfield(key, count)
                .map(this::decodeListOfField);
    }

    @Override
    public Uni> hrandfieldWithValues(K key, long count) {
        return super._hrandfieldWithValues(key, count)
                .map(this::decodeFieldWithValueMap);
    }

    @Override
    public Uni hset(K key, F field, V value) {
        return super._hset(key, field, value)
                .map(Response::toBoolean);
    }

    @Override
    public Uni hset(K key, Map map) {
        return super._hset(key, map)
                .map(Response::toLong);
    }

    @Override
    public Uni hsetnx(K key, F field, V value) {
        return super._hsetnx(key, field, value)
                .map(Response::toBoolean);
    }

    @Override
    public Uni hstrlen(K key, F field) {
        return super._hstrlen(key, field)
                .map(Response::toLong);
    }

    @Override
    public Uni> hvals(K key) {
        return super._hvals(key)
                .map(this::decodeListOfValue);
    }

    public ReactiveHashScanCursor hscan(K key) {
        nonNull(key, "key");
        return new HScanReactiveCursorImpl<>(redis, key,
                marshaller, typeOfField, typeOfValue, Collections.emptyList());
    }

    public ReactiveHashScanCursor hscan(K key, ScanArgs scanArgs) {
        nonNull(key, "key");
        nonNull(scanArgs, "scanArgs");
        return new HScanReactiveCursorImpl<>(redis, key,
                marshaller, typeOfField, typeOfValue, scanArgs.toArgs());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy