sequence

This article focuses on RedisToken

RedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/RedisToken. Java

public interface RedisToken { RedisToken NULL_STRING = string((SafeString) null); RedisToken RESPONSE_OK = status("OK"); RedisTokenType getType(); <T> T accept(RedisTokenVisitor<T> visitor); static RedisToken nullString() { return NULL_STRING; } static RedisToken responseOk() { return RESPONSE_OK; } static RedisToken string(SafeString str) { return new StringRedisToken(str); } static RedisToken string(String str) { return new StringRedisToken(safeString(str)); } static RedisToken status(String str) { return new StatusRedisToken(str); } static RedisToken integer(boolean b) { return new IntegerRedisToken(b ? 1:0); } static RedisToken integer(int i) { return new IntegerRedisToken(i); } static RedisToken error(String str) { return new ErrorRedisToken(str); } static RedisToken array(RedisToken... redisTokens) { return new ArrayRedisToken(ImmutableList.of(redisTokens)); } static RedisToken array(Collection<RedisToken> redisTokens) { return new ArrayRedisToken(ImmutableList.from(redisTokens)); } static RedisToken array(Sequence<RedisToken> redisTokens) { return new ArrayRedisToken(redisTokens.asArray()); } static <T> Stream<T> visit(Stream<RedisToken> tokens, RedisTokenVisitor<T> visitor) { return tokens.map(token -> token.accept(visitor)); }}Copy the code
  • RedisToken interface defines getType and accept methods. It also provides static nullString, responseOk, String, status, INTEGER, error, array, visit methods

AbstractRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

public abstract class AbstractRedisToken<T> implements RedisToken { private static final String SEPARATOR = "=>"; private static final Equal<AbstractRedisToken<? >> EQUAL = Equal.<AbstractRedisToken<? >>of() .comparing(AbstractRedisToken::getType) .comparing(AbstractRedisToken::getValue); private final RedisTokenType type; private final T value; private AbstractRedisToken(RedisTokenType type, T value) { this.type = requireNonNull(type); this.value = value; } @Override public RedisTokenType getType() { return type; } public T getValue() { return value; } @Override public int hashCode() { return Objects.hash(type, value); } @Override public boolean equals(Object obj) { return EQUAL.applyTo(this, obj); } @Override public String toString() { return type + SEPARATOR + value; }}Copy the code
  • Abstract AbstractRedisToken declaration implements RedisToken interface. Its constructor requires input type, value

UnknownRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

  public static final class UnknownRedisToken extends AbstractRedisToken<SafeString> {

    UnknownRedisToken(SafeString value) {
      super(RedisTokenType.UNKNOWN, value);
    }

    @Override
    public <T> T accept(RedisTokenVisitor<T> visitor) {
      return visitor.unknown(this);
    }
  }
Copy the code
  • Unknownrediredistoken AbstractRedisToken, its value is SafeString, its type is RedisTokenType.UNKNOWN, its accept is visitor. UNKNOWN (this)

StringRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

  public static final class StringRedisToken extends AbstractRedisToken<SafeString> {

    StringRedisToken(SafeString value) {
      super(RedisTokenType.STRING, value);
    }

    @Override
    public <T> T accept(RedisTokenVisitor<T> visitor) {
      return visitor.string(this);
    }
  }
Copy the code
  • StringRedisToken derives AbstractRedisToken, and its value is SafeString, its type is RedisTokenType.STRING, and its accept executes visitor. STRING (this).

StatusRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

public static final class StatusRedisToken extends AbstractRedisToken<String> { StatusRedisToken(String value) { super(RedisTokenType.STATUS, value); } @Override public <T> T accept(RedisTokenVisitor<T> visitor) { return visitor.status(this); }}Copy the code
  • StatusRedisToken AbstractRedisToken, whose value is String, whose type is RedisTokenType.STATUS, whose accept is visitor. STATUS (this)

ErrorRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

public static final class ErrorRedisToken extends AbstractRedisToken<String> { ErrorRedisToken(String value) { super(RedisTokenType.ERROR, value); } @Override public <T> T accept(RedisTokenVisitor<T> visitor) { return visitor.error(this); }}Copy the code
  • ErrorRedisToken AbstractRedisToken, value is String, type is RedisTokenType.ERROR, accept is visitor. ERROR (this)

IntegerRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

public static final class IntegerRedisToken extends AbstractRedisToken<Integer> { IntegerRedisToken(Integer value) { super(RedisTokenType.INTEGER, value); } @Override public <T> T accept(RedisTokenVisitor<T> visitor) { return visitor.integer(this); }}Copy the code
  • IntegerRedisToken AbstractRedisToken, whose value is Integer, whose type is RedisTokenType. Integer, whose accept is visitor. Integer (this)

ArrayRedisToken

Resp – server – 0.16.0 / SRC/main/Java/com/lot/tonivade/resp/protocol/AbstractRedisToken. Java

public static final class ArrayRedisToken extends AbstractRedisToken<Sequence<RedisToken>> { ArrayRedisToken(Sequence<RedisToken> value) { super(RedisTokenType.ARRAY, requireNonNull(value).asArray()); } @Override public <T> T accept(RedisTokenVisitor<T> visitor) { return visitor.array(this); } public int size() { return getValue().size(); }}Copy the code
  • ArrayRedisToken: AbstractRedisToken, whose value is Sequence, whose type is RedisTokenType.ARRAY, whose accept is visitor. ARRAY (this)

summary

RedisToken interface defines getType and accept methods. It also provides static nullString, responseOk, string, status, INTEGER, error, array, visit methods; Abstract AbstractRedisToken declaration implements RedisToken interface. Its constructor requires input type, value, It has UnknownRedisToken, StringRedisToken, StatusRedisToken, ErrorRedisToken, IntegerRedisToken, ArrayRedisToken and other implementation classes

doc

  • RedisToken