-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JsonType introduced to help typization
- Loading branch information
Showing
15 changed files
with
158 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2024, Redis Ltd. and Contributors | ||
* All rights reserved. | ||
* | ||
* Licensed under the MIT License. | ||
* | ||
* This file contains contributions from third-party contributors | ||
* licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.lettuce.core.json; | ||
|
||
/** | ||
* JSON types as returned by the JSON.TYPE command | ||
* | ||
* @see io.lettuce.core.api.sync.RedisCommands#jsonType | ||
* @since 6.5 | ||
* @author Tihomir Mateev | ||
*/ | ||
public enum JsonType { | ||
|
||
OBJECT, ARRAY, STRING, INTEGER, NUMBER, BOOLEAN, UNKNOWN; | ||
|
||
public static JsonType fromString(String s) { | ||
switch (s) { | ||
case "object": | ||
return OBJECT; | ||
case "array": | ||
return ARRAY; | ||
case "string": | ||
return STRING; | ||
case "integer": | ||
return INTEGER; | ||
case "number": | ||
return NUMBER; | ||
case "boolean": | ||
return BOOLEAN; | ||
default: | ||
return UNKNOWN; | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/io/lettuce/core/output/JsonTypeListOutput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2011-Present, Redis Ltd. and Contributors | ||
* All rights reserved. | ||
* | ||
* Licensed under the MIT License. | ||
*/ | ||
package io.lettuce.core.output; | ||
|
||
import io.lettuce.core.codec.RedisCodec; | ||
import io.lettuce.core.json.JsonType; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* {@link List} of {@link JsonType} output. | ||
* | ||
* @param <K> Key type. | ||
* @param <V> Value type. | ||
* @author Tihomir Mateev | ||
*/ | ||
public class JsonTypeListOutput<K, V> extends CommandOutput<K, V, List<JsonType>> { | ||
|
||
private boolean initialized; | ||
|
||
public JsonTypeListOutput(RedisCodec<K, V> codec) { | ||
super(codec, Collections.emptyList()); | ||
} | ||
|
||
@Override | ||
public void set(ByteBuffer bytes) { | ||
if (!initialized) { | ||
multi(1); | ||
} | ||
|
||
output.add(JsonType.fromString(decodeAscii(bytes))); | ||
} | ||
|
||
@Override | ||
public void multi(int count) { | ||
|
||
if (!initialized) { | ||
output = OutputFactory.newList(count); | ||
initialized = true; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters