2
0

introspection-2.tcl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. proc cmdstat {cmd} {
  2. if {[regexp "\r\ncmdstat_$cmd:(.*?)\r\n" [r info commandstats] _ value]} {
  3. set _ $value
  4. }
  5. }
  6. start_server {tags {"introspection"}} {
  7. test {TTL and TYPYE do not alter the last access time of a key} {
  8. r set foo bar
  9. after 3000
  10. r ttl foo
  11. r type foo
  12. assert {[r object idletime foo] >= 2}
  13. }
  14. test {TOUCH alters the last access time of a key} {
  15. r set foo bar
  16. after 3000
  17. r touch foo
  18. assert {[r object idletime foo] < 2}
  19. }
  20. test {TOUCH returns the number of existing keys specified} {
  21. r flushdb
  22. r set key1 1
  23. r set key2 2
  24. r touch key0 key1 key2 key3
  25. } 2
  26. test {command stats for GEOADD} {
  27. r config resetstat
  28. r GEOADD foo 0 0 bar
  29. assert_match {*calls=1,*} [cmdstat geoadd]
  30. assert_match {} [cmdstat zadd]
  31. }
  32. test {command stats for EXPIRE} {
  33. r config resetstat
  34. r SET foo bar
  35. r EXPIRE foo 0
  36. assert_match {*calls=1,*} [cmdstat expire]
  37. assert_match {} [cmdstat del]
  38. }
  39. test {command stats for BRPOP} {
  40. r config resetstat
  41. r LPUSH list foo
  42. r BRPOP list 0
  43. assert_match {*calls=1,*} [cmdstat brpop]
  44. assert_match {} [cmdstat rpop]
  45. }
  46. test {command stats for MULTI} {
  47. r config resetstat
  48. r MULTI
  49. r set foo bar
  50. r GEOADD foo2 0 0 bar
  51. r EXPIRE foo2 0
  52. r EXEC
  53. assert_match {*calls=1,*} [cmdstat multi]
  54. assert_match {*calls=1,*} [cmdstat exec]
  55. assert_match {*calls=1,*} [cmdstat set]
  56. assert_match {*calls=1,*} [cmdstat expire]
  57. assert_match {*calls=1,*} [cmdstat geoadd]
  58. }
  59. test {command stats for scripts} {
  60. r config resetstat
  61. r set mykey myval
  62. r eval {
  63. redis.call('set', KEYS[1], 0)
  64. redis.call('expire', KEYS[1], 0)
  65. redis.call('geoadd', KEYS[1], 0, 0, "bar")
  66. } 1 mykey
  67. assert_match {*calls=1,*} [cmdstat eval]
  68. assert_match {*calls=2,*} [cmdstat set]
  69. assert_match {*calls=1,*} [cmdstat expire]
  70. assert_match {*calls=1,*} [cmdstat geoadd]
  71. }
  72. }