Skip to content

Compressing Data

Valkey GLIDE supports compressing string values, reducing memory usage and network bandwidth. When enabled, values are transparently compressed before being sent to the server and decompressed on retrieval.

import glide.api.GlideClient;
import glide.api.models.configuration.*;
CompressionConfiguration compression = CompressionConfiguration.builder()
.enabled(true)
.backend(CompressionBackend.ZSTD)
.compressionLevel(3)
.minCompressionSize(128)
.build();
GlideClientConfiguration config = GlideClientConfiguration.builder()
.address(NodeAddress.builder().host("localhost").port(6379).build())
.compressionConfiguration(compression)
.build();
GlideClient client = GlideClient.createClient(config).get();

Compression works well when you primarily use basic read and write commands with large string values. If your application uses commands that read, modify, or compare a stored string, don’t use compression.

See Compatibilityf or the full list of supported and incompatible commands.

OptionDefaultDescription
enabledfalseToggle compression on/off
backendZSTDCompression algorithm: ZSTD or LZ4
compressionLevelBackend default (ZSTD=3, LZ4=0)Compression level; valid ranges are backend-specific
minCompressionSize64 bytesValues below this threshold are not compressed (minimum: 6 bytes)
maxDecompressedSize512 MBMaximum decompressed size; protects against decompression bombs

To understand how compression works under the hood, see our section on Data Compression.