Skip to content

Implemented utility to work with Request parameters#228

Draft
hurynovich wants to merge 1 commit intotonivade:masterfrom
hurynovich:feature/params-scanner
Draft

Implemented utility to work with Request parameters#228
hurynovich wants to merge 1 commit intotonivade:masterfrom
hurynovich:feature/params-scanner

Conversation

@hurynovich
Copy link
Copy Markdown
Contributor

@hurynovich hurynovich commented Jan 19, 2026

Overview

This PR is a proposal, which adds utility classes to simplify implementation of Commands.
Two main ideas can be distinguished:

  • CommandException - exception which automatically converted into ErrorRedisToken.
  • ParamsScanner - utility to simplify parameters parsing for Redis queries. And it actively throws CommandException.

Example

Parsing Redis command:

HSCAN key cursor [MATCH pattern] [COUNT count]
@Command("hscan")
public class HashScanCommand implements DBCommand {
  public static final int DEFAULT_COUNT = 100;
  public static final String DEFAULT_PATTERN = "*";

  @Override
  public RedisToken execute(Database db, Request request) {
    ParamsScanner parser = new ParamsScanner(request);
    String key = parser.nextString();
    int cursor = parser.nextInt();
    GlobPattern pattern = parser.nextGlob("match", DEFAULT_PATTERN);
    int count = parser.nextInt("count", DEFAULT_COUNT);
    parser.verifyHasNoMore();

Motivation

I tried to implement few Redis commands with bunch of optional parameters.
And code contains a lot of boiler plate if/else statements when works with raw request.getParams().
So, at the end I come to utility class which intended to make parameter parsing more concise and readable at the same time.

Note

It is currently a draft.
Tests, naming and docs are not final yet.

Related

#230

@hurynovich hurynovich force-pushed the feature/params-scanner branch from aeb5416 to 24027f9 Compare January 20, 2026 00:58
@hurynovich hurynovich force-pushed the feature/params-scanner branch from 24027f9 to e6d35dc Compare January 23, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant