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
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?
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command.
Redis GET all Keys To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.
The Redis command line interface ( redis-cli ) is a terminal program used to send commands to and read replies from the Redis server.
Redis - Hash Hgetall CommandRedis HGETALL command is used to get all the fields and values of the hash stored at the key. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With