datatype.tcl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. set testmodule [file normalize tests/modules/datatype.so]
  2. start_server {tags {"modules"}} {
  3. r module load $testmodule
  4. test {DataType: Test module is sane, GET/SET work.} {
  5. r datatype.set dtkey 100 stringval
  6. assert {[r datatype.get dtkey] eq {100 stringval}}
  7. }
  8. test {DataType: RM_SaveDataTypeToString(), RM_LoadDataTypeFromString() work} {
  9. r datatype.set dtkey -1111 MyString
  10. set encoded [r datatype.dump dtkey]
  11. r datatype.restore dtkeycopy $encoded
  12. assert {[r datatype.get dtkeycopy] eq {-1111 MyString}}
  13. }
  14. test {DataType: Handle truncated RM_LoadDataTypeFromString()} {
  15. r datatype.set dtkey -1111 MyString
  16. set encoded [r datatype.dump dtkey]
  17. set truncated [string range $encoded 0 end-1]
  18. catch {r datatype.restore dtkeycopy $truncated} e
  19. set e
  20. } {*Invalid*}
  21. test {DataType: ModuleTypeReplaceValue() happy path works} {
  22. r datatype.set key-a 1 AAA
  23. r datatype.set key-b 2 BBB
  24. assert {[r datatype.swap key-a key-b] eq {OK}}
  25. assert {[r datatype.get key-a] eq {2 BBB}}
  26. assert {[r datatype.get key-b] eq {1 AAA}}
  27. }
  28. test {DataType: ModuleTypeReplaceValue() fails on non-module keys} {
  29. r datatype.set key-a 1 AAA
  30. r set key-b RedisString
  31. catch {r datatype.swap key-a key-b} e
  32. set e
  33. } {*ERR*}
  34. }