redismodules.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from __future__ import annotations
  2. from json import JSONDecoder, JSONEncoder
  3. from typing import TYPE_CHECKING
  4. if TYPE_CHECKING:
  5. from .bf import BFBloom, CFBloom, CMSBloom, TDigestBloom, TOPKBloom
  6. from .json import JSON
  7. from .search import AsyncSearch, Search
  8. from .timeseries import TimeSeries
  9. from .vectorset import VectorSet
  10. class RedisModuleCommands:
  11. """This class contains the wrapper functions to bring supported redis
  12. modules into the command namespace.
  13. """
  14. def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()) -> JSON:
  15. """Access the json namespace, providing support for redis json."""
  16. from .json import JSON
  17. jj = JSON(client=self, encoder=encoder, decoder=decoder)
  18. return jj
  19. def ft(self, index_name="idx") -> Search:
  20. """Access the search namespace, providing support for redis search."""
  21. from .search import Search
  22. s = Search(client=self, index_name=index_name)
  23. return s
  24. def ts(self) -> TimeSeries:
  25. """Access the timeseries namespace, providing support for
  26. redis timeseries data.
  27. """
  28. from .timeseries import TimeSeries
  29. s = TimeSeries(client=self)
  30. return s
  31. def bf(self) -> BFBloom:
  32. """Access the bloom namespace."""
  33. from .bf import BFBloom
  34. bf = BFBloom(client=self)
  35. return bf
  36. def cf(self) -> CFBloom:
  37. """Access the bloom namespace."""
  38. from .bf import CFBloom
  39. cf = CFBloom(client=self)
  40. return cf
  41. def cms(self) -> CMSBloom:
  42. """Access the bloom namespace."""
  43. from .bf import CMSBloom
  44. cms = CMSBloom(client=self)
  45. return cms
  46. def topk(self) -> TOPKBloom:
  47. """Access the bloom namespace."""
  48. from .bf import TOPKBloom
  49. topk = TOPKBloom(client=self)
  50. return topk
  51. def tdigest(self) -> TDigestBloom:
  52. """Access the bloom namespace."""
  53. from .bf import TDigestBloom
  54. tdigest = TDigestBloom(client=self)
  55. return tdigest
  56. def vset(self) -> VectorSet:
  57. """Access the VectorSet commands namespace."""
  58. from .vectorset import VectorSet
  59. vset = VectorSet(client=self)
  60. return vset
  61. class AsyncRedisModuleCommands(RedisModuleCommands):
  62. def ft(self, index_name="idx") -> AsyncSearch:
  63. """Access the search namespace, providing support for redis search."""
  64. from .search import AsyncSearch
  65. s = AsyncSearch(client=self, index_name=index_name)
  66. return s