-
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.
Rename wrapper type to ComposedRedisCodec. Introduce RedisCodec.of(…) factory method. Add tests. Original pull request: #1123.
- Loading branch information
Showing
4 changed files
with
106 additions
and
78 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/io/lettuce/core/codec/ComposedRedisCodec.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,59 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* http://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.codec; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import io.lettuce.core.internal.LettuceAssert; | ||
|
||
/** | ||
* A {@link ComposedRedisCodec} combines two {@link RedisCodec cdecs} to encode/decode key and value to the command output. | ||
* | ||
* @author Dimitris Mandalidis | ||
* @since 5.2 | ||
*/ | ||
class ComposedRedisCodec<K, V> implements RedisCodec<K, V> { | ||
|
||
private final RedisCodec<K, ?> keyCodec; | ||
private final RedisCodec<?, V> valueCodec; | ||
|
||
ComposedRedisCodec(RedisCodec<K, ?> keyCodec, RedisCodec<?, V> valueCodec) { | ||
LettuceAssert.notNull(keyCodec, "Key codec must not be null"); | ||
LettuceAssert.notNull(valueCodec, "Value codec must not be null"); | ||
this.keyCodec = keyCodec; | ||
this.valueCodec = valueCodec; | ||
} | ||
|
||
@Override | ||
public K decodeKey(ByteBuffer bytes) { | ||
return keyCodec.decodeKey(bytes); | ||
} | ||
|
||
@Override | ||
public V decodeValue(ByteBuffer bytes) { | ||
return valueCodec.decodeValue(bytes); | ||
} | ||
|
||
@Override | ||
public ByteBuffer encodeKey(K key) { | ||
return keyCodec.encodeKey(key); | ||
} | ||
|
||
@Override | ||
public ByteBuffer encodeValue(V value) { | ||
return valueCodec.encodeValue(value); | ||
} | ||
} |
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
71 changes: 0 additions & 71 deletions
71
src/main/java/io/lettuce/core/codec/RedisCodecAdapter.java
This file was deleted.
Oops, something went wrong.
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