10

I've been experimenting with Redis today. I've managed to store cached values from Drupal, but I'm looking to investigate a bit further and view the value stored in cache_my_custom_cache..

127.0.0.1:6379> keys *
 1) "ff3169bd93659dc31322abc32835ef3e:cache_bootstrap:lookup_cache"
 2) "ff3169bd93659dc31322abc32835ef3e:cache_bootstrap:module_implements"
 3) "ff3169bd93659dc31322abc32835ef3e:cache_bootstrap:bootstrap_modules"
 4) "ff3169bd93659dc31322abc32835ef3e:cache_bootstrap:system_list"
 5) "ff3169bd93659dc31322abc32835ef3e:cache_bootstrap:variables"
 6) "ff3169bd93659dc31322abc32835ef3e:path:a:und"
 7) "myhash"
 8) "ff3169bd93659dc31322abc32835ef3e:path:s:und"
 9) "ff3169bd93659dc31322abc32835ef3e:cache_my_custom_cache:custom_cache_markup"
10) "ff3169bd93659dc31322abc32835ef3e:cache_bootstrap:hook_info"
127.0.0.1:6379> type ff3169bd93659dc31322abc32835ef3e:cache_my_custom_cache:custom_cache_markup
hash
  • this reveals it's of type hash.. But when I run:
127.0.0.1:6379> HGET ff3169bd93659dc31322abc32835ef3e:cache_qbe:qbe_markup
(error) ERR wrong number of arguments for 'hget' command

It doesn't like it! Completely new to this, can someone offer a solution?

2 Answers 2

14

Besides the key you will need to specify the field in the HGET command.

To get a list of all fields in the hash you can run this:

hkeys ff3169bd93659dc31322abc32835ef3e:cache_my_custom_cache:custom_cache_markup

Then you can do:

hget ff3169bd93659dc31322abc32835ef3e:cache_my_custom_cache:custom_cache_markup FIELD

You can also get all the values in the hash like this:

hvals ff3169bd93659dc31322abc32835ef3e:cache_my_custom_cache:custom_cache_markup
9

HGET expects an additional parameter after the key name that enumerates which field of your hash you would like returned. Something like this:

HGET my_hash_key my_hash_field

If you're trying to retrieve all fields of your hash at once, you should use HGETALL:

HGETALL my_hash_key

Documentation for HGET: here

Documentation for HGETALL: here

Discussion of Redis types (including hashes): here

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.