Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to configure Redis to be case insensitive with regards to Keys?

Tags:

redis

So for example:

Foo : Bar

Could also be looked up as FOO, foo, fOO etc?

like image 710
Handloomweaver Avatar asked Jul 15 '11 16:07

Handloomweaver


People also ask

How Redis read all keys?

To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.

Are Redis keys always strings?

Keys in Redis are all strings, so it doesn't really matter what kind of value you pass into a client.

Which command can be used to confirm key present in Redis or not?

Redis and PHPRedis EXISTS command is used to check whether the key exists in Redis or not.

What is Keys command in Redis?

The Redis KEYS command returns all the keys in the database that match a pattern (or all the keys in the key space). Similar commands for fetching all the fields stored in a hash is HGETALL and for all fetching the members of a SMEMBERS. The keys in Redis themselves are stored in a dictionary (aka a hash table).


2 Answers

No. You should lowercase/uppercase all your keys if you want that.

like image 103
seppo0010 Avatar answered Sep 20 '22 08:09

seppo0010


redis keys is case sensitive,my solution is that: key-->Foo:Bar keyword-->f

keys("[fF]*") or keyword-->foo

keys("[fF][oO][oO]*") you have to convert normal string to this format '[Ff][Oo]';

i write a method for this:

public static String toIgnoreCasePattern(String str){
    StringBuilder sb = new StringBuilder();
    char []chars = str.toCharArray();
    char upperCaseC;
    for(char c : chars){
        boolean isLowerCase = Character.isLowerCase(c);
        upperCaseC = isLowerCase ? Character.toUpperCase(c) : c;
        sb.append("[").append(c).append(upperCaseC).append("]");
    }
    return sb.toString();
}

I hope this answer can help you.

like image 44
Jettylee.com Avatar answered Sep 19 '22 08:09

Jettylee.com