How do i view my Redis database current_size?

I am aware of redis-cli, and the info and config commands. However, they do not have anything that states the size of the current database. How could I figure this out?


Using the INFO command. full details here: http://redis.io/commands/info

sample output:

redis-cli
redis 127.0.0.1:6379> info
redis_version:2.4.11
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:kqueue
gcc_version:4.2.1
process_id:300
uptime_in_seconds:1389779
uptime_in_days:16
lru_clock:1854465
used_cpu_sys:59.86
used_cpu_user:73.02
used_cpu_sys_children:0.15
used_cpu_user_children:0.11
connected_clients:1
connected_slaves:0
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
used_memory:1329424
used_memory_human:1.27M
used_memory_rss:2285568
used_memory_peak:1595680
used_memory_peak_human:1.52M
mem_fragmentation_ratio:1.72
mem_allocator:libc
loading:0
aof_enabled:0
changes_since_last_save:0
bgsave_in_progress:0
last_save_time:1360719404
bgrewriteaof_in_progress:0
total_connections_received:221
total_commands_processed:29926
expired_keys:2
evicted_keys:0
keyspace_hits:1678
keyspace_misses:3
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:379
vm_enabled:0
role:master
db0:keys=23,expires=0

You can use the following command to list the databases for which some keys are defined:

INFO keyspace
# Keyspace
db0:keys=6002,expires=0,avg_ttl=0
db9:keys=20953296,expires=0,avg_ttl=0
db10:keys=1,expires=0,avg_ttl=0

You can also use Select 0 or Select 1 or any db which you want to check with the current size. After selection of db Use dbsize command to display the size of selected db.

Select 9
OK
dbsize
(integer) 20953296

for listing overall information of your redis type info and to view only memory just type

INFO Memory
# Memory
used_memory:1259920
used_memory_human:1.20M
used_memory_rss:1227000
used_memory_peak:2406152
used_memory_peak_human:2.29M
used_memory_lua:36864
mem_fragmentation_ratio:0.97
mem_allocator:dlmalloc-2.8

redis-cli info memory | grep 'used_memory.*human';

Sample output:

used_memory_human:20.66M
used_memory_rss_human:24.26M
used_memory_peak_human:46.14M
used_memory_lua_human:37.00K
used_memory_scripts_human:0B

You can also do this with an one line command:

redis-cli -p 6379 -a  password info| egrep "used_memory_human|total_system_memory_human"

This will display the total memory used by Redis and the total RAM on the server.