@@ -405,8 +405,11 @@ defmodule Remixdb.Hash do
405405 end
406406
407407 def handle_call ( { :hstrlen , hash_name , key } , _from , table ) do
408- res = get_hash_key ( table , hash_name , key ) |>
409- :erlang . byte_size
408+ val = get_hash_key ( table , hash_name , key )
409+ res = case val do
410+ nil -> 0
411+ _ -> :erlang . byte_size ( val )
412+ end
410413
411414 { :reply , res , table }
412415 end
@@ -432,19 +435,10 @@ defmodule Remixdb.Hash do
432435 end
433436
434437 def handle_call ( { :hgetall , hash_name } , _from , table ) do
435- # The match spec:
436- # - Pattern: keys matching {hash_name, $"$1"} with value $"$2"
437- # - No guards.
438- # - Return a tuple {field, value} for each match.
439- match_spec = [ { { { hash_name , :"$1" } , :"$2" } , [ ] , [ { :"$1" , :"$2" } ] } ]
440-
441- # ETS.select returns a list of tuples, e.g. [{field1, value1}, {field2, value2}, ...]
442- result = :ets . select ( table , match_spec )
443-
444- # If you want the results as an interleaved list [field1, value1, field2, value2, ...], you can flatten:
445- interleaved = Enum . flat_map ( result , fn { k , v } -> [ k , v ] end )
446-
447- { :reply , interleaved , table }
438+ result =
439+ get_all_entries ( table , hash_name )
440+ |> Enum . flat_map ( fn ( { k , v } ) -> [ k , v ] end )
441+ { :reply , result , table }
448442 end
449443
450444 def handle_call ( :flushall , _from , table ) do
0 commit comments