cabol / nebulex_redis_adapter

Nebulex adapter for Redis

Home Page:https://hexdocs.pm/nebulex_redis_adapter/NebulexRedisAdapter.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow storing raw strings, not the whole `Nebulex.Object.t()`

cabol opened this issue · comments

Currently, bay default, all values except the counters are stored as Nebulex.Object.t() (before to put the data on Redis, the object is encoded as binary). The idea is to allow storing raw strings, not within the object, and improve the memory consumption for string data types.

Proposed solution

Supporting for "data types" starting with strings. Two additional options:

  • :dt - This option is for write-like operations like set, add, replace, set_many, etc., and allows to change how to store the data in Redis, for example, by default is the Nebulex object, but if we pass :string, there shouldn't be any encoding if the given value is a valid string.

  • default_data_type - In order to avoid always passing the previous option for all write-like commands, we can change the default data type encoding globally.

By default, for both options the value is :object (the current behavior).

Usage Example

Cache.set("foo", "bar", dt: :string)

# the string dt is applied to all given values
Cache.set_many(%{"a" => "a", "b" => "b"}, dt: :string)

Globally:

config :my_app, MyApp.Cache,
  default_data_type: :string