Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know the data type of the value of a given key?

I can't seem to find useful information about Redis commands. I want to know the data type of the value of a given key. For instance to list all the keys of my database I run the following command:

 keys * 

In my setup, I get the following result:

 1) "username:testuser:uid"  2) "uid:1:first"  3) "uid:1:email"  4) "uid:1:hash"  5) "global:next_uid"  6) "members:email"  7) "uid:1:username"  8) "uid:1:last"  9) "uid:1:salt"  10) "uid:1:access"  11) "uid:1:company"  12) "email:[email protected]:uid"  13) "uid:1:phone_number" 

How do I know what data type the key members:email contains? I tried to run get members:email but and I get the error (error) ERR Operation against a key holding the wrong kind of value

Any thoughts?

like image 832
anlogg Avatar asked Sep 29 '13 11:09

anlogg


People also ask

What is the data type of 1)?*?

1 is an integer, 1.0 is a floating-point number. Complex numbers are written in the form, x + yj , where x is the real part and y is the imaginary part.

How do I get all Redis 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.


2 Answers

You could use the type command: http://redis.io/commands/type

like image 51
Didier Spezia Avatar answered Oct 02 '22 15:10

Didier Spezia


See below from docs:

redis> SET key1 "value"     "OK"     redis> LPUSH key2 "value"     (integer) 1     redis> SADD key3 "value"     (integer) 1     redis> TYPE key1     "string"     redis> TYPE key2     "list"     redis> TYPE key3     "set"     redis>  
like image 39
Merlin Avatar answered Oct 02 '22 15:10

Merlin