commandfilter.tcl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. set testmodule [file normalize tests/modules/commandfilter.so]
  2. start_server {tags {"modules"}} {
  3. r module load $testmodule log-key 0
  4. test {Command Filter handles redirected commands} {
  5. r set mykey @log
  6. r lrange log-key 0 -1
  7. } "{set mykey @log}"
  8. test {Command Filter can call RedisModule_CommandFilterArgDelete} {
  9. r rpush mylist elem1 @delme elem2
  10. r lrange mylist 0 -1
  11. } {elem1 elem2}
  12. test {Command Filter can call RedisModule_CommandFilterArgInsert} {
  13. r del mylist
  14. r rpush mylist elem1 @insertbefore elem2 @insertafter elem3
  15. r lrange mylist 0 -1
  16. } {elem1 --inserted-before-- @insertbefore elem2 @insertafter --inserted-after-- elem3}
  17. test {Command Filter can call RedisModule_CommandFilterArgReplace} {
  18. r del mylist
  19. r rpush mylist elem1 @replaceme elem2
  20. r lrange mylist 0 -1
  21. } {elem1 --replaced-- elem2}
  22. test {Command Filter applies on RM_Call() commands} {
  23. r del log-key
  24. r commandfilter.ping
  25. r lrange log-key 0 -1
  26. } "{ping @log}"
  27. test {Command Filter applies on Lua redis.call()} {
  28. r del log-key
  29. r eval "redis.call('ping', '@log')" 0
  30. r lrange log-key 0 -1
  31. } "{ping @log}"
  32. test {Command Filter applies on Lua redis.call() that calls a module} {
  33. r del log-key
  34. r eval "redis.call('commandfilter.ping')" 0
  35. r lrange log-key 0 -1
  36. } "{ping @log}"
  37. test {Command Filter is unregistered implicitly on module unload} {
  38. r del log-key
  39. r module unload commandfilter
  40. r set mykey @log
  41. r lrange log-key 0 -1
  42. } {}
  43. r module load $testmodule log-key 0
  44. test {Command Filter unregister works as expected} {
  45. # Validate reloading succeeded
  46. r del log-key
  47. r set mykey @log
  48. assert_equal "{set mykey @log}" [r lrange log-key 0 -1]
  49. # Unregister
  50. r commandfilter.unregister
  51. r del log-key
  52. r set mykey @log
  53. r lrange log-key 0 -1
  54. } {}
  55. r module unload commandfilter
  56. r module load $testmodule log-key 1
  57. test {Command Filter REDISMODULE_CMDFILTER_NOSELF works as expected} {
  58. r set mykey @log
  59. assert_equal "{set mykey @log}" [r lrange log-key 0 -1]
  60. r del log-key
  61. r commandfilter.ping
  62. assert_equal {} [r lrange log-key 0 -1]
  63. r eval "redis.call('commandfilter.ping')" 0
  64. assert_equal {} [r lrange log-key 0 -1]
  65. }
  66. }