public class StringCodec extends Object implements RedisCodec<String,String>, ToByteBufEncoder<String,String>
RedisCodec
encodes and decodes String
keys and values using a specified
Charset
. It accepts provided buffers
so it does not need to allocate buffers during encoding.Modifier and Type | Field and Description |
---|---|
static StringCodec |
ASCII |
static StringCodec |
UTF8 |
Constructor and Description |
---|
StringCodec()
Creates a new
StringCodec with the default charset . |
StringCodec(Charset charset)
Creates a new
StringCodec for the given Charset that encodes and decodes keys and values. |
Modifier and Type | Method and Description |
---|---|
String |
decodeKey(ByteBuffer bytes)
Decode the key output by redis.
|
String |
decodeValue(ByteBuffer bytes)
Decode the value output by redis.
|
void |
encode(String str,
ByteBuf target) |
ByteBuffer |
encodeKey(String key)
Encode the key for output to redis.
|
void |
encodeKey(String key,
ByteBuf target)
Encode the key for output to redis.
|
ByteBuffer |
encodeValue(String value)
Encode the value for output to redis.
|
void |
encodeValue(String value,
ByteBuf target)
Encode the value for output to redis.
|
int |
estimateSize(Object keyOrValue)
Estimates the size of the resulting byte stream.
|
boolean |
isEstimateExact()
Returns
true if ToByteBufEncoder.estimateSize(Object) returns exact size This is used as an optimization to reduce memory
allocations when encoding data. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
of
public static final StringCodec UTF8
public static final StringCodec ASCII
public StringCodec()
StringCodec
with the default charset
. The default is determined
from the file.encoding
system property.public StringCodec(Charset charset)
StringCodec
for the given Charset
that encodes and decodes keys and values.charset
- must not be null
.public void encodeKey(String key, ByteBuf target)
ToByteBufEncoder
encodeKey
in interface ToByteBufEncoder<String,String>
key
- the key, may be null
.target
- the target buffer, must not be null
.public int estimateSize(Object keyOrValue)
ToByteBufEncoder
estimateSize
in interface ToByteBufEncoder<String,String>
keyOrValue
- the key or value, may be null
.public boolean isEstimateExact()
ToByteBufEncoder
true
if ToByteBufEncoder.estimateSize(Object)
returns exact size This is used as an optimization to reduce memory
allocations when encoding data.isEstimateExact
in interface ToByteBufEncoder<String,String>
true
if ToByteBufEncoder.estimateSize(Object)
returns exact size.public void encodeValue(String value, ByteBuf target)
ToByteBufEncoder
encodeValue
in interface ToByteBufEncoder<String,String>
value
- the value, may be null
.target
- the target buffer, must not be null
.public String decodeKey(ByteBuffer bytes)
RedisCodec
decodeKey
in interface RedisCodec<String,String>
bytes
- Raw bytes of the key, must not be null
.null
.public String decodeValue(ByteBuffer bytes)
RedisCodec
decodeValue
in interface RedisCodec<String,String>
bytes
- Raw bytes of the value, must not be null
.null
.public ByteBuffer encodeKey(String key)
RedisCodec
encodeKey
in interface RedisCodec<String,String>
key
- the key, may be null
.null
.public ByteBuffer encodeValue(String value)
RedisCodec
encodeValue
in interface RedisCodec<String,String>
value
- the value, may be null
.null
.Copyright © 2024 lettuce.io. All rights reserved.