Packages

In-memory projection of Redis/Valkey data

Retired package: Release invalid - Replication broken

Current section

7 Versions

Jump to

Compare versions

15 files changed
+383 additions
-17 deletions
  @@ -35,7 +35,7 @@ Add to your `mix.exs`:
35 35 ```elixir
36 36 def deps do
37 37 [
38 - {:veidrodelis, "~> 0.1.9"},
38 + {:veidrodelis, "~> 0.1.10"},
39 39 # Optional, for Sentinel support.
40 40 # Also, some regular Valkey/Redis client is needed if writes are needed.
41 41 {:redix, "~> 1.5"}
  @@ -1,6 +1,6 @@
1 1 {<<"links">>,[{<<"GitHub">>,<<"https://github.com/savonarola/veidrodelis">>}]}.
2 2 {<<"name">>,<<"veidrodelis">>}.
3 - {<<"version">>,<<"0.1.9">>}.
3 + {<<"version">>,<<"0.1.10">>}.
4 4 {<<"description">>,<<"In-memory projection of Redis/Valkey data">>}.
5 5 {<<"elixir">>,<<"~> 1.18">>}.
6 6 {<<"app">>,<<"veidrodelis">>}.
  @@ -41,6 +41,24 @@ defmodule Veidrodelis do
41 41 # Stop the instance
42 42 :ok = Veidrodelis.stop(pid)
43 43 ```
44 +
45 + ## Logging Metadata
46 +
47 + All processes started by Veidrodelis set `Logger.metadata(vdr: <id>)`
48 + so that log messages can be associated with a specific instance.
49 + To reveal this metadata in log output, configure the Elixir Logger formatter:
50 +
51 + ```elixir
52 + config :logger, :default_formatter,
53 + format: "$time $metadata[$level] $message\n",
54 + metadata: [:vdr]
55 + ```
56 +
57 + With this configuration, log messages will include the instance id, for example:
58 +
59 + ```
60 + 14:32:10.123 vdr=my_instance [info] Connected to localhost:6379
61 + ```
44 62 """
45 63
46 64 alias Vdr.RedisStream.Replica
  @@ -367,6 +385,38 @@ defmodule Veidrodelis do
367 385 with_single_command_read_tx(id, db, {:get, key})
368 386 end
369 387
388 + @doc """
389 + Returns up to `count` lexicographically first keys in the database.
390 + """
391 + @spec first(instance_id(), db(), non_neg_integer()) :: {:ok, [key()]} | {:error, term()}
392 + def first(id, db, count) do
393 + with_single_command_read_tx(id, db, {:first, count})
394 + end
395 +
396 + @doc """
397 + Returns up to `count` lexicographically last keys in the database in reverse order.
398 + """
399 + @spec last(instance_id(), db(), non_neg_integer()) :: {:ok, [key()]} | {:error, term()}
400 + def last(id, db, count) do
401 + with_single_command_read_tx(id, db, {:last, count})
402 + end
403 +
404 + @doc """
405 + Returns up to `count` keys after `key` in the database.
406 + """
407 + @spec next(instance_id(), db(), key(), non_neg_integer()) :: {:ok, [key()]} | {:error, term()}
408 + def next(id, db, key, count) do
409 + with_single_command_read_tx(id, db, {:next, key, count})
410 + end
411 +
412 + @doc """
413 + Returns up to `count` keys before `key` in the database in reverse order.
414 + """
415 + @spec prev(instance_id(), db(), key(), non_neg_integer()) :: {:ok, [key()]} | {:error, term()}
416 + def prev(id, db, key, count) do
417 + with_single_command_read_tx(id, db, {:prev, key, count})
418 + end
419 +
370 420 @doc """
371 421 Returns the length of the list stored at key.
372 422 """
  @@ -722,6 +772,10 @@ defmodule Veidrodelis do
722 772 ### Supported Commands
723 773
724 774 * `{:get, key}` - Get string value
775 + * `{:first, count}` - Get up to `count` lexicographically first keys in the database
776 + * `{:last, count}` - Get up to `count` lexicographically last keys in the database
777 + * `{:next, key, count}` - Get up to `count` keys after `key`
778 + * `{:prev, key, count}` - Get up to `count` keys before `key`
725 779 * `{:hget, key, field}` - Get hash field value
726 780 * `{:hmget, key, fields}` - Get multiple hash field values
727 781 * `{:hgetall, key}` - Get all hash fields and values
  @@ -774,6 +828,10 @@ defmodule Veidrodelis do
774 828
775 829 Executes a Lua script atomically under the storage mutex. The script has access to:
776 830 - `ts.get(key)` - Get a string value
831 + - `ts.first(count)` - Get first keys in the database
832 + - `ts.last(count)` - Get last keys in the database
833 + - `ts.next(key, count)` - Get next keys after given key
834 + - `ts.prev(key, count)` - Get previous keys before given key
777 835 - `ts.hget(key, field)` - Get a hash field value
778 836 - `ts.llen(key)` - Get list length
779 837 - `ts.lrange(key, start, stop)` - Get list range
  @@ -58,6 +58,7 @@ defmodule Vdr.Benchmark.LagTracker do
58 58 @impl GenServer
59 59 def init(opts) do
60 60 vdr_id = Keyword.fetch!(opts, :vdr_id)
61 + Logger.metadata(vdr: vdr_id)
61 62 tracker_key = Keyword.get(opts, :tracker_key, "lagmon")
62 63 redis_conn = Keyword.fetch!(opts, :redis_conn)
63 64 timestamp_interval_ms = Keyword.get(opts, :timestamp_interval_ms, 1000)
  @@ -67,6 +67,7 @@ defmodule Vdr.Benchmark.Reader do
67 67 @impl GenServer
68 68 def init(opts) do
69 69 vdr_id = Keyword.fetch!(opts, :vdr_id)
70 + Logger.metadata(vdr: vdr_id)
70 71 reader_count = Keyword.get(opts, :reader_count, 4)
71 72 read_fn = Keyword.fetch!(opts, :read_fn)
72 73 batch_size = Keyword.get(opts, :batch_size, @default_batch_size)
  @@ -164,6 +165,7 @@ defmodule Vdr.Benchmark.Reader do
164 165 batch_size = state.batch_size
165 166
166 167 spawn_link(fn ->
168 + Logger.metadata(vdr: vdr_id)
167 169 reader_loop(reader_id, vdr_id, read_fn, samples_ets, total_ops, start_time, batch_size)
168 170 end)
169 171 end
Loading more files…