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