4

I am using redis to set and filter key value pair in my application. But it return always case sensitive data while filtering using HSCAN. I need to get case insensitive data from redis. How can I get this?

How to set Redis to be case insensitive?

ex: If I search "foo", it should return the following results,

Foo
foo
FOO
fOO

Kindly provide your inputs on this.

SST
  • 2,054
  • 5
  • 35
  • 65
  • did you try to use regex , somthing like `r.keys("*foo*")` – LinPy Jun 13 '19 at 06:01
  • Yes, I am using HSCAN, 'HSCAN myhash 0 match *daily*' which is returning empty results. But when I use HSCAN development_partners 0 match *Daily*, it returns the following, 127.0.0.1:6379> HSCAN myhash 0 match *Daily* 1) "The Daily News" 2) "dailynews" 3) "Daily News Update" 4) "news updated" – SST Jun 13 '19 at 06:11

1 Answers1

1

There's no built-in way to do that, however, you can hack it.

Instead of doing: HSET hash foo val, HSET hash Foo val, and HSET hash fOo val, you make these fields has a common prefix, e.g. FOO:

HSET hash FOO:foo val
HSET hash FOO:Foo val
HSET hash FOO:fOo val

Then instead of call HSCAN hash 0 MATCH foo*, you can use HSCAN hash 0 MATCH FOO:* to scan items case-insensitively.

In a word, encode your field with a case-insensitive prefix, e.g. all chars uppercased or lowercased.

for_stack
  • 21,012
  • 4
  • 35
  • 48