escapeGlob

Escapes this string for use as literal text in a Redis glob pattern, such as a scanKeys pattern or the pattern of KEYS, SCAN ... MATCH, HSCAN, SSCAN or ZSCAN.

Each glob metacharacter (*, ?, [, ] and \) gets a backslash before it, so the result matches only the original text. Build a pattern from request data with it, as in "session:${userId.escapeGlob()}:*": without it, a userId of * matches every user's session keys.

Every other character is left as it is. That includes ^ and -, which mean something only inside a [...] class, so the result is for use outside one; don't put it between brackets. Leaving them alone keeps ordinary ids, such as UUIDs, unchanged, so a cluster {hash-tag} built from one still names the key's slot.

Escaping is not idempotent: escape each value once, as it is put into the pattern.

Return

this string with a backslash before each glob metacharacter