Skip to content

Commit

Permalink
fix: Return default info with CRLF, fixes #1086 (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh authored May 26, 2021
1 parent ed7156c commit a7e40d9
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 147 deletions.
280 changes: 141 additions & 139 deletions src/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,145 +3,147 @@ export function info() {
return this.data.get('info');
}

const defaultInfo = `# Server
redis_version:5.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6eea854fbb5ddd69
redis_mode:standalone
os:Linux 4.19.76-linuxkit x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:9.2.0
process_id:1
run_id:4787d20e758149c8d52455abc39cf8cf277a334c
tcp_port:6379
uptime_in_seconds:968
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:642868
executable:/data/redis-server
config_file:
# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0
# Memory
used_memory:898376
used_memory_human:877.32K
used_memory_rss:4046848
used_memory_rss_human:3.86M
used_memory_peak:1022480
used_memory_peak_human:998.52K
used_memory_peak_perc:87.86%
used_memory_overhead:847550
used_memory_startup:791264
used_memory_dataset:50826
used_memory_dataset_perc:47.45%
allocator_allocated:1626408
allocator_active:1945600
allocator_resident:8847360
total_system_memory:2086522880
total_system_memory_human:1.94G
used_memory_lua:51200
used_memory_lua_human:50.00K
used_memory_scripts:4528
used_memory_scripts_human:4.42K
number_of_cached_scripts:2
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.20
allocator_frag_bytes:319192
allocator_rss_ratio:4.55
allocator_rss_bytes:6901760
rss_overhead_ratio:0.46
rss_overhead_bytes:-4800512
mem_fragmentation_ratio:4.73
mem_fragmentation_bytes:3190472
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
# Persistence
loading:0
rdb_changes_since_last_save:1
rdb_bgsave_in_progress:0
rdb_last_save_time:1577700205
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
# Stats
total_connections_received:6
total_commands_processed:32
instantaneous_ops_per_sec:0
total_net_input_bytes:6643
total_net_output_bytes:31254
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:1
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:11
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
# Replication
role:master
connected_slaves:0
master_replid:4ca161d4b9cc62b01bb87b9084a71ff229d0bda8
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:4.571514
used_cpu_user:1.065946
used_cpu_sys_children:0.002352
used_cpu_user_children:0.001369
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=38,expires=0,avg_ttl=0`;
const defaultInfo = [
'# Server',
'redis_version:5.0.7',
'redis_git_sha1:00000000',
'redis_git_dirty:0',
'redis_build_id:6eea854fbb5ddd69',
'redis_mode:standalone',
'os:Linux 4.19.76-linuxkit x86_64',
'arch_bits:64',
'multiplexing_api:epoll',
'atomicvar_api:atomic-builtin',
'gcc_version:9.2.0',
'process_id:1',
'run_id:4787d20e758149c8d52455abc39cf8cf277a334c',
'tcp_port:6379',
'uptime_in_seconds:968',
'uptime_in_days:0',
'hz:10',
'configured_hz:10',
'lru_clock:642868',
'executable:/data/redis-server',
'config_file:',
'',
'# Clients',
'connected_clients:1',
'client_recent_max_input_buffer:2',
'client_recent_max_output_buffer:0',
'blocked_clients:0',
'',
'# Memory',
'used_memory:898376',
'used_memory_human:877.32K',
'used_memory_rss:4046848',
'used_memory_rss_human:3.86M',
'used_memory_peak:1022480',
'used_memory_peak_human:998.52K',
'used_memory_peak_perc:87.86%',
'used_memory_overhead:847550',
'used_memory_startup:791264',
'used_memory_dataset:50826',
'used_memory_dataset_perc:47.45%',
'allocator_allocated:1626408',
'allocator_active:1945600',
'allocator_resident:8847360',
'total_system_memory:2086522880',
'total_system_memory_human:1.94G',
'used_memory_lua:51200',
'used_memory_lua_human:50.00K',
'used_memory_scripts:4528',
'used_memory_scripts_human:4.42K',
'number_of_cached_scripts:2',
'maxmemory:0',
'maxmemory_human:0B',
'maxmemory_policy:noeviction',
'allocator_frag_ratio:1.20',
'allocator_frag_bytes:319192',
'allocator_rss_ratio:4.55',
'allocator_rss_bytes:6901760',
'rss_overhead_ratio:0.46',
'rss_overhead_bytes:-4800512',
'mem_fragmentation_ratio:4.73',
'mem_fragmentation_bytes:3190472',
'mem_not_counted_for_evict:0',
'mem_replication_backlog:0',
'mem_clients_slaves:0',
'mem_clients_normal:49694',
'mem_aof_buffer:0',
'mem_allocator:jemalloc-5.1.0',
'active_defrag_running:0',
'lazyfree_pending_objects:0',
'',
'# Persistence',
'loading:0',
'rdb_changes_since_last_save:1',
'rdb_bgsave_in_progress:0',
'rdb_last_save_time:1577700205',
'rdb_last_bgsave_status:ok',
'rdb_last_bgsave_time_sec:-1',
'rdb_current_bgsave_time_sec:-1',
'rdb_last_cow_size:0',
'aof_enabled:0',
'aof_rewrite_in_progress:0',
'aof_rewrite_scheduled:0',
'aof_last_rewrite_time_sec:-1',
'aof_current_rewrite_time_sec:-1',
'aof_last_bgrewrite_status:ok',
'aof_last_write_status:ok',
'aof_last_cow_size:0',
'',
'# Stats',
'total_connections_received:6',
'total_commands_processed:32',
'instantaneous_ops_per_sec:0',
'total_net_input_bytes:6643',
'total_net_output_bytes:31254',
'instantaneous_input_kbps:0.00',
'instantaneous_output_kbps:0.00',
'rejected_connections:0',
'sync_full:0',
'sync_partial_ok:0',
'sync_partial_err:0',
'expired_keys:1',
'expired_stale_perc:0.00',
'expired_time_cap_reached_count:0',
'evicted_keys:0',
'keyspace_hits:0',
'keyspace_misses:11',
'pubsub_channels:0',
'pubsub_patterns:0',
'latest_fork_usec:0',
'migrate_cached_sockets:0',
'slave_expires_tracked_keys:0',
'active_defrag_hits:0',
'active_defrag_misses:0',
'active_defrag_key_hits:0',
'active_defrag_key_misses:0',
'',
'# Replication',
'role:master',
'connected_slaves:0',
'master_replid:4ca161d4b9cc62b01bb87b9084a71ff229d0bda8',
'master_replid2:0000000000000000000000000000000000000000',
'master_repl_offset:0',
'second_repl_offset:-1',
'repl_backlog_active:0',
'repl_backlog_size:1048576',
'repl_backlog_first_byte_offset:0',
'repl_backlog_histlen:0',
'',
'# CPU',
'used_cpu_sys:4.571514',
'used_cpu_user:1.065946',
'used_cpu_sys_children:0.002352',
'used_cpu_user_children:0.001369',
'',
'# Cluster',
'cluster_enabled:0',
'',
'# Keyspace',
'db0:keys=38,expires=0,avg_ttl=0',
].join('\r\n');

return defaultInfo;
}
18 changes: 10 additions & 8 deletions test/commands/info.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import Redis from 'ioredis';

describe('info', () => {
it('should return the specific info', () => {
it('should return the specific info', async () => {
const info = `#Server
redis_version:5.0.7`;
const redis = new Redis({
data: {
info,
},
});
return redis.info().then((value) => {
expect(value).toEqual(info);
});
const value = await redis.info();

expect(value).toEqual(info);
});
it('should return default info', () => {
it('should return default info with CRLF', async () => {
const redis = new Redis();
return redis.info().then((value) => {
expect(value).toMatch(/redis_version/g);
});
const value = await redis.info();
const lines = value.split('\r\n');

expect(lines).toHaveLength(value.split('\n').length);
expect(lines.some(line => line.startsWith('redis_version:'))).toBeTruthy();
});
});

0 comments on commit a7e40d9

Please sign in to comment.