redis查看最大连接数及其他参数、版本号等

场景

集群项目总是报连接超时,想看下到底是有多少连接。

过程

连接并查看参数

客户端可以看redis参数么,肯定是可以的,命令:

/usr/bin/redis -a ***password  # 连接redis

查看参数:

info # 查看所有信息
info clients # 查看连接数等客户端信息,可用值有server,memory等

info命令报错:NOAUTH Authentication required.

无密码连接,然后输入 info 命令就会报这个错。 是因为默认连接方式没有查看权限。
使用带密码的登录方式即可。

info参数列表

info可以查看所有参数。
info 模块名可以看对应的模块,如 info server,info memory等。
一般用 info clients 命令就可以了,输出内容如下:

# Clients
connected_clients:865  # 链接数
client_recent_max_input_buffer:4
client_recent_max_output_buffer:0
blocked_clients:0

client list 查看连接列表

有很多字段,age表示创建时间(秒) idle表示空闲时间(秒)
idle时间过长 表示一直空置,可以干掉
age=idle 表示创建后就没有用过,也可以干掉

查看超时设置

config get timeout  # 查看超时设置
config set timeout 300 # 设置超时时间(秒)

config get *   # 查看所有的配置列表 

info 所有参数列表

所有参数列表:

# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-957.21.3.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:29031
run_id:c810b029bd8eea504cbcd4b466cf1e18c6948f7e
tcp_port:6379
uptime_in_seconds:7308611
uptime_in_days:84
hz:10
lru_clock:13908165
executable:/usr/bin/redis-server
config_file:/etc/redis.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:813696
used_memory_human:794.62K
used_memory_rss:1810432
used_memory_rss_human:1.73M
used_memory_peak:5022056
used_memory_peak_human:4.79M
total_system_memory:3973533696
total_system_memory_human:3.70G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:2.22
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1590722687
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
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

# Stats
total_connections_received:446262
total_commands_processed:1143019
instantaneous_ops_per_sec:0
total_net_input_bytes:110594091
total_net_output_bytes:724507868
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:9814
evicted_keys:0
keyspace_hits:54673
keyspace_misses:10209
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:212
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:2315.55
used_cpu_user:1439.36
used_cpu_sys_children:1.90
used_cpu_user_children:1.28

# Cluster
cluster_enabled:0

# Keyspace

查看版本号

本机redis的版本

这种比较简单:

redis-server --version

返回结果为:
Redis server v=3.2.12 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 \ 
build=7897e7d0e13773f

v=3.2.12 redis的版本
远程redis的版本
redis-cli -h hostname -p 6379 -a password info | grep redis_version 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,Jedis是Redis官方推荐的Java连接开发工具。在Java项目中整合Jedis并连接Redis数据库的步骤如下: 1. 在pom.xml文件中添加Jedis的Maven依赖: ```xml <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.7.0</version> </dependency> ``` 请确保版本号与您使用的Redis版本兼容。 2. 编写Jedis连接代码: ```java import redis.clients.jedis.Jedis; public class JedisTest { public static void main(String[] args) { // 创建连接 Jedis jedis = new Jedis("192.168.56.103", 6379); // 执行命令 jedis.set("name", "fengxiansheng"); // 释放连接 jedis.close(); } } ``` 请将`192.168.56.103`替换为您的Redis服务器IP地址,并根据需要执行其他命令。 另外,为了提高性能和线程安全性,可以使用连接池来管理Jedis对象。以下是使用Jedis连接池的示例代码: ```java import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; public class JedisPoolTest { public static void main(String[] args) { JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxTotal(2); // 设置最大连接数 poolConfig.setMaxIdle(2); // 设置最大空闲连接数 poolConfig.setTestOnBorrow(true); // 获取jedis时做有效性检测 JedisPool jedisPool = new JedisPool(poolConfig, "192.168.56.103", 6379); Jedis jedis1 = jedisPool.getResource(); Jedis jedis2 = jedisPool.getResource(); // jedis1、jedis2 不需要手动释放连接 Jedis jedis3 = jedisPool.getResource(); } } ``` 这样可以复用连接对象,提高性能并避免频繁创建和销毁Jedis对象。 回答完问题后的相关问题: 相关问题: 1. Redis Jedis支持哪些数据类型? 2. Jedis连接池的作用是什么? 3. 如何在Jedis中使用事务操作?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值