Xandra v0.7.1 Xandra.Compressor behaviour
A behaviour to compress and decompress binary data.
Modules implementing this behaviour can be used to compress and decompress data using one of the compression algorithms supported by Cassandra (as of now, lz4 and snappy).
Example
Let’s imagine you implemented the snappy compression algorithm in your application:
defmodule Snappy do
def compress(binary), do: ...
def decompress(binary), do: ...
end
You can then implement a module that implements the Xandra.Compressor
behaviour and can be used to compress and decompress data flowing through the
connection to Cassandra:
defmodule SnappyXandraCompressor do
@behaviour Xandra.Compressor
def algorithm(), do: :snappy
defdelegate compress(binary), to: Snappy
defdelegate decompress(binary), to: Snappy
end
Now, this module can be passed as the value of the :compressor
option to
many functions in Xandra
:
Xandra.start_link(compressor: SnappyXandraCompressor)
For more information on compression, see the “Compression” section in the
documentation for Xandra.
Summary
Callbacks
Specifies which algorithm this module will use to compress and decompress data
Compresses the given iodata according to the algorithm returned by
algorithm/0
Deompresses the given binary according to the algorithm returned by
algorithm/0
Callbacks
Specifies which algorithm this module will use to compress and decompress data.
Compresses the given iodata according to the algorithm returned by
algorithm/0
.
Deompresses the given binary according to the algorithm returned by
algorithm/0
.