expire.tcl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. start_server {tags {"expire"}} {
  2. test {EXPIRE - set timeouts multiple times} {
  3. r set x foobar
  4. set v1 [r expire x 5]
  5. set v2 [r ttl x]
  6. set v3 [r expire x 10]
  7. set v4 [r ttl x]
  8. r expire x 4
  9. list $v1 $v2 $v3 $v4
  10. } {1 5 1 10}
  11. test {EXPIRE - It should be still possible to read 'x'} {
  12. r get x
  13. } {foobar}
  14. tags {"slow"} {
  15. test {EXPIRE - After 6 seconds the key should no longer be here} {
  16. after 6000
  17. list [r get x] [r exists x]
  18. } {{} 0}
  19. }
  20. test {EXPIRE - write on expire should work} {
  21. r del x
  22. r lpush x foo
  23. r expire x 1000
  24. r lpush x bar
  25. r lrange x 0 -1
  26. } {bar foo}
  27. test {EXPIREAT - Check for EXPIRE alike behavior} {
  28. r del x
  29. r set x foo
  30. r expireat x [expr [clock seconds]+15]
  31. r ttl x
  32. } {1[345]}
  33. test {SETEX - Set + Expire combo operation. Check for TTL} {
  34. r setex x 12 test
  35. r ttl x
  36. } {1[012]}
  37. test {SETEX - Check value} {
  38. r get x
  39. } {test}
  40. test {SETEX - Overwrite old key} {
  41. r setex y 1 foo
  42. r get y
  43. } {foo}
  44. tags {"slow"} {
  45. test {SETEX - Wait for the key to expire} {
  46. after 3000
  47. r get y
  48. } {}
  49. }
  50. test {SETEX - Wrong time parameter} {
  51. catch {r setex z -10 foo} e
  52. set _ $e
  53. } {*invalid expire*}
  54. test {PERSIST can undo an EXPIRE} {
  55. r set x foo
  56. r expire x 50
  57. list [r ttl x] [r persist x] [r ttl x] [r get x]
  58. } {50 1 -1 foo}
  59. test {PERSIST returns 0 against non existing or non volatile keys} {
  60. r set x foo
  61. list [r persist foo] [r persist nokeyatall]
  62. } {0 0}
  63. }