Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

How to implement redis "HGET" in spring reactive

$
0
0

I tried to make some hash operation with spring reactive and then I got some errors from these codes.
It always told me to convert Mono<Map<String, String>> into Mono<Object.
The idea is to get all values (data) from input(key and field).
Can someone help me with the solution?
Here is the lines:

ReactiveRedisHelper

public <T extends RedisSessionObject<T>> Mono<T> getSessionObjectByValue(String key, String field, boolean autoCreateSession,            String callerClassName, String logIdentifier, Class<T> clazz) {        try {            RedisReactiveCommands<String, String> command = this.reactiveCommandFactory();            try {                T newSession = clazz.newInstance();                Instant startRequest = Instant.now();                Mono<Map<String, String>> getObjectResult = Mono.just("").map(placeholder -> {                    logWriter.logRequest(callerClassName, logIdentifier, redisHost, redisPort, "HGET",                            String.format("{\"key\": \"%s\", \"field\": \"%s\"}", key, field));                    return placeholder;                }).flatMap(placeholder -> {                    return command.hget(key, field);                }).map(getallResult -> {                    Instant endRequest = Instant.now();                    long dateDiff = ChronoUnit.MILLIS.between(startRequest, endRequest);                    List<String> valueArray = new ArrayList<String>();                    getallResult.forEach((k, v) -> {                        valueArray.add(String.format("{\"key\": \"%s\", \"value\":\"%s\"}", k, v));                    });                    logWriter.logResponse(callerClassName, logIdentifier, redisHost, redisPort, "HGET",                            String.format("{\"key\": \"%s\", \"value\": [%s]}", key, String.join(",", valueArray)),                            dateDiff);                    return getallResult;                });                return getObjectResult.flatMap(sessionObject -> {                    if (sessionObject.size() == 0) {                        if (autoCreateSession) {                            Mono<Boolean> initializeObjectResult = this.saveSessionObject(key, newSession,                                    callerClassName, logIdentifier, command);                            return initializeObjectResult.map(initializeStatus -> {                                return newSession;                            });                        }                        return Mono.just("").flatMap(empty -> {                            this.closeConnection(command, callerClassName, logIdentifier);                            return Mono.empty();                        });                    }                    return Mono.just(newSession.deserializeData(sessionObject));                }).map(result -> {                    this.closeConnection(command, callerClassName, logIdentifier);                    return result;                }).onErrorMap(e -> {                    this.closeConnection(command, callerClassName, logIdentifier);                    return this.handleError(e, logIdentifier, callerClassName);                });            } catch (Exception e) {                this.closeConnection(command, callerClassName, logIdentifier);                return Mono.error(this.handleError(e, logIdentifier, callerClassName));            }        } catch (Exception e) {            return Mono.error(this.handleError(e, logIdentifier, callerClassName));        }    }

Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>