show processlist [all]

Available since 1.0.0.

命令说明

获取当前所有连接的信息,如果指定all,表示同时显示正在sleep的连接信息. 通过json格式输出,重定向到文本中显示会更清晰

  1. shell> redis-cli -p 8903 show processlist all > a
  2. shell> cat a
  3. [
  4. {
  5. "id": 767, # session id
  6. "host": "127.0.0.1:50834",
  7. "args": [
  8. "set",
  9. "a",
  10. "b"
  11. ],
  12. "authed": 1,
  13. "dbid": 0,
  14. "start_time": 1587451514479, # 命令开始的毫秒时间戳
  15. "duration": 153550, # 执行的时间(毫秒)
  16. "session_ref": 3,
  17. "holdinglocks": [ # 持有锁信息
  18. [
  19. 5, # 锁的store id
  20. "a", # key级锁
  21. "X" # 锁的类型
  22. ]
  23. ]
  24. },
  25. {
  26. "id": 3303,
  27. "host": "127.0.0.1:51056",
  28. "args": [
  29. "get",
  30. "a"
  31. ],
  32. "authed": 1,
  33. "dbid": 0,
  34. "start_time": 1587451643100,
  35. "duration": 24929,
  36. "session_ref": 3,
  37. "waitlock": [ # 等待锁的信息
  38. 5,
  39. "a",
  40. "X"
  41. ]
  42. },
  43. {
  44. "id": 3589,
  45. "host": "127.0.0.1:51069",
  46. "args": [
  47. "show",
  48. "processlist",
  49. "all"
  50. ],
  51. "authed": 1,
  52. "dbid": 0,
  53. "start_time": 1587451668029,
  54. "duration": 0,
  55. "session_ref": 3
  56. }
  57. ]

命令返回

Array reply

Examples

如上

show locks

命令说明

获取当前tendis进程上所有线程持有的锁信息,主要用来获取当前所有锁的状态 以及 归属于哪个线程, 用于排查死锁,重复上锁等问题

如果当前没有锁, 显示如下:

  1. 127.0.0.1:51002> show locks
  2. (empty list or set)

当前线程中包含锁的时候显示锁列表如下:

  1. 127.0.0.1:51003> show locks
  2. 1) "running: {id:12037349 target:store_4 targetHash:12626945507335128354 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  3. 2) "running: {id:12037353 target:store_8 targetHash:5894286778622387524 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  4. 3) "running: {id:12037352 target:store_7 targetHash:14410881189481979652 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  5. 4) "running: {id:12037348 target:store_3 targetHash:2921060641710983428 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  6. 5) "pending: {id:12037356 target:store_3 targetHash:2921060641710983428 LockMode:IX LockRes:1 threadId:0x7fbc211cb700}"
  7. 6) "running: {id:12037345 target:store_0 targetHash:8597937682813753033 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  8. 7) "pending: {id:12037355 target:store_0 targetHash:8597937682813753033 LockMode:IX LockRes:1 threadId:0x7fbc219cc700}"
  9. 8) "pending: {id:12037359 target:store_0 targetHash:8597937682813753033 LockMode:IS LockRes:1 threadId:0x7fbc0e3e0700}"
  10. 9) "running: {id:12037354 target:store_9 targetHash:227896731122534032 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  11. 10) "running: {id:12037351 target:store_6 targetHash:875462629852764501 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  12. 11) "running: {id:12037347 target:store_2 targetHash:11940324784125777240 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  13. 12) "running: {id:12037350 target:store_5 targetHash:7939884790480503227 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  14. 13) "pending: {id:12037358 target:store_5 targetHash:7939884790480503227 LockMode:IX LockRes:1 threadId:0x7fbc201c9700}"
  15. 14) "running: {id:12037346 target:store_1 targetHash:11400597207708767293 LockMode:X LockRes:0 threadId:0x7fbc345f0700}"
  16. 15) "pending: {id:12037357 target:store_1 targetHash:11400597207708767293 LockMode:IX LockRes:1 threadId:0x7fbc209ca700}"

running表示以及获取的锁,pending表示正在等待的锁

  1. id:锁id
  2. target: 上锁的对象,可能是store锁,chunk锁或者key
  3. targetHash:上锁shard等信息做hash得到的值,一般不需要关注
  4. lockMode: 锁的类型,有S锁,IS锁,X锁,IX
  5. threadId: 当前锁是属于哪个线程ID, 主要这个不是pid 而是pstack输出的进程堆栈信息中的ID

Examples

如上