java.lang.Object
io.lettuce.core.codec.StringCodec
- All Implemented Interfaces:
RedisCodec<String,String>,ToByteBufEncoder<String,String>
- Direct Known Subclasses:
Utf8StringCodec
public class StringCodec extends Object implements RedisCodec<String,String>, ToByteBufEncoder<String,String>
Optimized String codec. This
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.- Since:
- 4.3
- Author:
- Mark Paluch, Dimitris Mandalidis
-
Field Summary
Fields Modifier and Type Field Description static StringCodecASCIIstatic StringCodecUTF8 -
Constructor Summary
Constructors Constructor Description StringCodec()Creates a newStringCodecwith the defaultcharset.StringCodec(Charset charset)Creates a newStringCodecfor the givenCharsetthat encodes and decodes keys and values. -
Method Summary
Modifier and Type Method Description StringdecodeKey(ByteBuffer bytes)Decode the key output by redis.StringdecodeValue(ByteBuffer bytes)Decode the value output by redis.voidencode(String str, ByteBuf target)ByteBufferencodeKey(String key)Encode the key for output to redis.voidencodeKey(String key, ByteBuf target)Encode the key for output to redis.ByteBufferencodeValue(String value)Encode the value for output to redis.voidencodeValue(String value, ByteBuf target)Encode the value for output to redis.intestimateSize(Object keyOrValue)Estimates the size of the resulting byte stream.
-
Field Details
-
UTF8
-
ASCII
-
-
Constructor Details
-
StringCodec
public StringCodec()Creates a newStringCodecwith the defaultcharset. The default is determined from thefile.encodingsystem property. -
StringCodec
Creates a newStringCodecfor the givenCharsetthat encodes and decodes keys and values.- Parameters:
charset- must not benull.
-
-
Method Details
-
encodeKey
Description copied from interface:ToByteBufEncoderEncode the key for output to redis.- Specified by:
encodeKeyin interfaceToByteBufEncoder<String,String>- Parameters:
key- the key, may benull.target- the target buffer, must not benull.
-
estimateSize
Description copied from interface:ToByteBufEncoderEstimates the size of the resulting byte stream. This method is called for keys and values to estimate the size for the temporary buffer to allocate.- Specified by:
estimateSizein interfaceToByteBufEncoder<String,String>- Parameters:
keyOrValue- the key or value, may benull.- Returns:
- the estimated number of bytes in the encoded representation.
-
encodeValue
Description copied from interface:ToByteBufEncoderEncode the value for output to redis.- Specified by:
encodeValuein interfaceToByteBufEncoder<String,String>- Parameters:
value- the value, may benull.target- the target buffer, must not benull.
-
decodeKey
Description copied from interface:RedisCodecDecode the key output by redis.- Specified by:
decodeKeyin interfaceRedisCodec<String,String>- Parameters:
bytes- Raw bytes of the key, must not benull.- Returns:
- The decoded key, may be
null.
-
decodeValue
Description copied from interface:RedisCodecDecode the value output by redis.- Specified by:
decodeValuein interfaceRedisCodec<String,String>- Parameters:
bytes- Raw bytes of the value, must not benull.- Returns:
- The decoded value, may be
null.
-
encodeKey
Description copied from interface:RedisCodecEncode the key for output to redis.- Specified by:
encodeKeyin interfaceRedisCodec<String,String>- Parameters:
key- the key, may benull.- Returns:
- The encoded key, never
null.
-
encodeValue
Description copied from interface:RedisCodecEncode the value for output to redis.- Specified by:
encodeValuein interfaceRedisCodec<String,String>- Parameters:
value- the value, may benull.- Returns:
- The encoded value, never
null.
-
encode
-