summaryrefslogtreecommitdiff
path: root/redis/commands/redismodules.py
blob: 457a69e2a24f739901fce674345f90f8a8a9adc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from json import JSONEncoder, JSONDecoder
from redis.exceptions import ModuleError


class RedisModuleCommands:
    """This class contains the wrapper functions to bring supported redis
    modules into the command namepsace.
    """

    def json(self, encoder=JSONEncoder(), decoder=JSONDecoder()):
        """Access the json namespace, providing support for redis json."""
        try:
            modversion = self.loaded_modules['rejson']
        except IndexError:
            raise ModuleError("rejson is not a loaded in the redis instance.")

        from .json import JSON
        jj = JSON(
                client=self,
                version=modversion,
                encoder=encoder,
                decoder=decoder)
        return jj

    def ft(self, index_name="idx"):
        """Access the search namespace, providing support for redis search."""
        try:
            modversion = self.loaded_modules['search']
        except IndexError:
            raise ModuleError("search is not a loaded in the redis instance.")

        from .search import Search
        s = Search(client=self, version=modversion, index_name=index_name)
        return s

    def ts(self, index_name="idx"):
        """Access the timeseries namespace, providing support for
        redis timeseries data.
        """
        try:
            modversion = self.loaded_modules['timeseries']
        except IndexError:
            raise ModuleError("timeseries is not a loaded in "
                              "the redis instance.")

        from .timeseries import TimeSeries
        s = TimeSeries(client=self, version=modversion, index_name=index_name)
        return s