Is there any way to get values without key in redis?
My data is as below. Assume that I inserted the three records using hset
.
key field value
a-7-1 param1 1
a-7-2 param2 2
a-7-3 param1 3
As you can see, there are three keys and I want to extract rows containing param1
.
So, when I run a redis-cli command, I want to get records as below.
Note that I want to enter single redis command, not for the script containing multiple shell and other commands.
key field value
a-7-1 param1 1
a-7-3 param1 3
I am hard to find any redis-cli that enables those functionality.
I would appreciate it if you could any guidance to me.
2
Answers
you can use hscan to fetch data with patterns
In your case, you can
This sounds like a problem for RediSearch. You can create an index over your Hashes and then query it. Like this:
You’ll need a version of Redis with RediSearch installed—I used Redis Stack via Docker—for this sort of stuff.
RediSearch is a big topic—bigger than I can reasonably post here—so you’ll need to do some digging on the details. But it’s the sort of thing that lets you query Redis and will hopefully be a good starting point for you.