I'm try to find a solution, of how to get all the fields from a HASH
that has the same values.
For example
redis > HSET my_hash "foo" 1
(integer) 1
redis > HSET my_hash "bar" 1
(integer) 1
redis > HSET my_hash "baz" 0
(integer) 1
redis > HGETALL my_hash
1) "foo"
2) "1"
3) "bar"
4) "1"
5) "baz"
6) "0"
So what I want is to do something like HGETALL my_hash "WHERE VALUE = 1"
. And expected result would be foo
and bar
.
If someone could point me on how to do this using native commands or using Lua
would be awesome.
Thanks.
You can do this
in a lua script named script.lua
lua get hash by sequence key0,val0,key1,val1, etc...
and after you can call it that's way:
you will have :
more information for the eval function here
edit : as said deltheil in comment , for check only the values and don't make unecessary check you can step the for loop by 2 because the rendering of a hash request is key,values,key,value,etc...: