Most stores/databases support capacity to search in a case insensitive manner (e.g. via 'collations') One place where this would be really useful is case insensitive (collation) support key names in HASH and [Z]SET data structures. Another is the top level key names.
Btw, I am aware about forcing all my keys to be upper (or lower) case, but this is not how my data looks (and you do not have to do this for other databases)
Many thanks for giving this a thought
TM
Comment From: itamarhaber
Hello @technomagos
Thanks for proposing this feature and sharing your thoughts.
From what I know, collation and such are done on textual data in "other databases". Doing the same for key names (or Hash fields) in Redis, which are unique identifiers used for accessing the data, seems wrong to me without any disrespect.
Comment From: zuiderkwast
Just some reflections.
Internally, some hash tables in Redis are case insensitive (they use a case insensitive hash function), so technically it would be possible to implement it. (Ziplist and similar would also need some modification, but I guess it can be done by just replacing memcmp with something like memcasecmp.)
I see two possibilities:
- A compilation flag. Either one for just Hash fields or a global flag making all keys and hash fields, set elements, list elements, etc. case insensitive.
-
Per key. Each hash table has the hash function attached to it, so it would be possible to change it for, say, one Hash independently of other Hashes.
Command possibilities (some worse than others):
- using something like "HCONFIG SET key case 0", but if the hash goes empty, it's deleted and recreated on the next HSET, and then it will be case sensitive again.
- provide a variant of HSET, let's say HSETCASE, or perhaps better a generic HSETxxx (name?) function which can take the options NX, XX, CASE and potentially more in the future. The case parameter would affect the whole Hash, not just the field referenced in the HSETxxx command.
A would prefer a compilation flag, which needs minimal documentation, since I don't think it's worth the added complexity to all the types and documentation affected to have it per key.
Comment From: technomagos
Case insensitivity support for HASH keys, via a compile flag - or some global cconfig/cnf - would be very useful and i suspect a small dev effort?
Comment From: zuiderkwast
If it doesn't make Redis much more complex, e.g. if it only adds a couple of #ifdef, I guess it could be accepted. @itamarhaber WDYT?
Comment From: itamarhaber
I still find the notion of key/field/member case insensitivity weird. Furthermore, I believe this is the first time this request was made here, so I'd be happy to hear from others what they think about it. The main beef I have with it, other than it reminding me of the behavior of Windows' file system, is the assumption that keys/fields/members are textual. In reality, these can be any binary string (byte array) so case (let alone collation) is meaningless and harmful in such cases.
FWIW, I think compile flags are not user-friendly - most peeps don't make their own Redis, and even when they do they rarely mess with compile flags unless they know what they're doing and need it. That said, if this feature is added, it can only be done via compile flags as a global config would probably reduce the performance given the extra conditionals.
Comment From: yossigo
Totally agree with @itamarhaber.
Comment From: madolson
Also agree with @itamarhaber
Comment From: yoav-steinberg
I can imagine two reasons why this might have come up: 1. Where the unique value is case insensitive while the display value has case information (like @itamarhaber's mention of windows file system). You can probably resolve this by storing a display value in addition to the unique key without adding limitations and weird language based assumptions to the key names. 2. When you want to use some collation rules in order to order the results of some ZSET query. If this is the case then indeed Redis's sorted sets, the way they're implemented today, can't help you. There's no collation based ordering in Redis, while other databases do support this. I think it might be worth thinking of a collation based sorting mechanism as some extension to ZSET's pseudo lexicographic ordering. Maybe a module or a script? WDYT?