The example key you give is for a set, set lookup methods are O(1). The more complex operations on a set (SDIFF, SUNION, SINTER) are O(N). Chances are that populating $userId
was a more expensive operation than using a longer key.
Redis comes with a benchmark utility called redis-benchmark
, if you modify the "GET" test in src/redis-benchmark.c so that they key is just "foo", you can run the short key test after a make install
:
diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c
--- a/src/redis-benchmark.c
+++ b/src/redis-benchmark.c
@@ -475,11 +475,11 @@
benchmark("MSET (10 keys)",cmd,len);
free(cmd);