Is there any way to configure Redis to be case insensitive with regards to Keys?
So开发者_如何转开发 for example:
Foo : Bar
Could also be looked up as FOO, foo, fOO etc?
No. You should lowercase/uppercase all your keys if you want that.
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.
In C#
public static String toIgnoreCasePattern(String str)
{
StringBuilder sb = new StringBuilder();
char[] chars = str.ToCharArray();
char upperCaseC;
foreach (var c in chars)
{
bool isLowerCase = char.IsLower(c);
upperCaseC = isLowerCase ? char.ToUpper(c) : c;
sb.Append("[").Append(c).Append(upperCaseC).Append("]");
}
return sb.ToString();
}
精彩评论