From 12c17bfc436ea6784bbc8b2d327d981520858eb7 Mon Sep 17 00:00:00 2001 From: Chayim Date: Thu, 9 Dec 2021 09:49:35 +0200 Subject: [PATCH] Adding cluster, bloom, and graph docs (#1779) --- docs/index.rst | 20 ++- docs/redis_cluster_commands.rst | 7 + ...s_core_commands.rst => redis_commands.rst} | 6 +- docs/redismodules.rst | 123 +++++++++++++++++- redis/commands/bf/commands.py | 6 +- redis/commands/graph/commands.py | 2 + 6 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 docs/redis_cluster_commands.rst rename docs/{redis_core_commands.rst => redis_commands.rst} (88%) diff --git a/docs/index.rst b/docs/index.rst index 8e243f3e28..d088708e50 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,21 +16,30 @@ redis-py can be installed using pip via ``pip install redis``. Quickly connecting to redis -************ +*************************** There are two quick ways to connect to Redis. -Assuming you run Redis on localhost:6379 (the default):: +**Assuming you run Redis on localhost:6379 (the default)** + +.. code-block:: python + import redis r = redis.Redis() r.ping() -Running redis on foo.bar.com, port 12345:: +**Running redis on foo.bar.com, port 12345** + +.. code-block:: python + import redis r = redis.Redis(host='foo.bar.com', port=12345) r.ping() -Another example with foo.bar.com, port 12345:: +**Another example with foo.bar.com, port 12345** + +.. code-block:: python + import redis r = redis.from_url('redis://foo.bar.com:12345') r.ping() @@ -47,7 +56,8 @@ Redis Command Functions .. toctree:: :maxdepth: 2 - redis_core_commands + redis_commands + redis_cluster_commands sentinel_commands redismodules diff --git a/docs/redis_cluster_commands.rst b/docs/redis_cluster_commands.rst new file mode 100644 index 0000000000..de520de905 --- /dev/null +++ b/docs/redis_cluster_commands.rst @@ -0,0 +1,7 @@ +Redis Cluster Commands +###################### + +The following `Redis commands `_ are available within a `Redis Cluster `_. Generally they can be used as functions on your redis connection. + +.. autoclass:: redis.commands.cluster.RedisClusterCommands + :inherited-members: diff --git a/docs/redis_core_commands.rst b/docs/redis_commands.rst similarity index 88% rename from docs/redis_core_commands.rst rename to docs/redis_commands.rst index edfd7fe939..efb76e79c6 100644 --- a/docs/redis_core_commands.rst +++ b/docs/redis_commands.rst @@ -1,5 +1,5 @@ -Redis Core Commands -#################### +Redis Commands +############### The following functions can be used to replicate their equivalent `Redis command `_. Generally they can be used as functions on your redis connection. For the simplest example, see below: @@ -11,4 +11,4 @@ Getting and settings data in redis:: r.get('mykey') .. autoclass:: redis.commands.core.CoreCommands - :members: \ No newline at end of file + :inherited-members: diff --git a/docs/redismodules.rst b/docs/redismodules.rst index da8c36b7b4..0cb8c49660 100644 --- a/docs/redismodules.rst +++ b/docs/redismodules.rst @@ -5,15 +5,132 @@ Accessing redis module commands requires the installation of the supported `Redi RedisTimeSeries Commands ************************ + +These are the commands for interacting with the `RedisTimeSeries module `_. Below is a brief example, as well as documentation on the commands themselves. + + +**Create a timeseries object with 5 second retention** + +.. code-block:: python + + import redis + r = redis.Redis() + r.timeseries().create(2, retension_msecs=5) + .. automodule:: redis.commands.timeseries.commands - :members: TimeSeriesCommands + :members: TimeSeriesCommands + +----- RedisJSON Commands ****************** + +These are the commands for interacting with the `RedisJSON module `_. Below is a brief example, as well as documentation on the commands themselves. + +**Create a json object** + +.. code-block:: python + + import redis + r = redis.Redis() + r.json().set("mykey", ".", {"hello": "world", "i am": ["a", "json", "object!"]} + + .. automodule:: redis.commands.json.commands - :members: JSONCommands + :members: JSONCommands + +----- RediSearch Commands ******************* + +These are the commands for interacting with the `RediSearch module `_. Below is a brief example, as well as documentation on the commands themselves. + +**Create a search index, and display its information** + +.. code-block:: python + + import redis + r = redis.Redis() + r.ft().create_index(TextField("play", weight=5.0), TextField("ball")) + print(r.ft().info()) + + .. automodule:: redis.commands.search.commands - :members: SearchCommands \ No newline at end of file + :members: SearchCommands + +----- + +RedisGraph Commands +******************* + +These are the commands for interacting with the `RedisGraph module `_. Below is a brief example, as well as documentation on the commands themselves. + +**Create a graph, adding two nodes** + +.. code-block:: python + + import redis + from redis.graph.node import Node + + john = Node(label="person", properties={"name": "John Doe", "age": 33} + jane = Node(label="person", properties={"name": "Jane Doe", "age": 34} + + r = redis.Redis() + graph = r.graph() + graph.add_node(john) + graph.add_node(jane) + graph.add_node(pat) + graph.commit() + +.. automodule:: redis.commands.graph.node + :members: Node + +.. automodule:: redis.commands.graph.edge + :members: Edge + +.. automodule:: redis.commands.graph.commands + :members: GraphCommands + +----- + +RedisBloom Commands +******************* + +These are the commands for interacting with the `RedisBloom module `_. Below is a brief example, as well as documentation on the commands themselves. + +**Create and add to a bloom filter** + +.. code-block:: python + + import redis + filter = redis.bf().create("bloom", 0.01, 1000) + filter.add("bloom", "foo") + +**Create and add to a cuckoo filter** + +.. code-block:: python + + import redis + filter = redis.cf().create("cuckoo", 1000) + filter.add("cuckoo", "filter") + +**Create Count-Min Sketch and get information** + +.. code-block:: python + + import redis + r = redis.cms().initbydim("dim", 1000, 5) + r.cms().incrby("dim", ["foo"], [5]) + r.cms().info("dim") + +**Create a topk list, and access the results** + +.. code-block:: python + + import redis + r = redis.topk().reserve("mytopk", 3, 50, 4, 0.9) + info = r.topk().info("mytopk) + +.. automodule:: redis.commands.bf.commands + :members: BFCommands, CFCommands, CMSCommands, TOPKCommands diff --git a/redis/commands/bf/commands.py b/redis/commands/bf/commands.py index 3c8bf7f31e..7fc507d2d9 100644 --- a/redis/commands/bf/commands.py +++ b/redis/commands/bf/commands.py @@ -51,7 +51,7 @@ class BFCommands: - """RedisBloom commands.""" + """Bloom Filter commands.""" # region Bloom Filter Functions def create(self, key, errorRate, capacity, expansion=None, noScale=None): @@ -166,6 +166,7 @@ def info(self, key): class CFCommands: + """Cuckoo Filter commands.""" # region Cuckoo Filter Functions def create( @@ -283,6 +284,8 @@ def info(self, key): class TOPKCommands: + """TOP-k Filter commands.""" + def reserve(self, key, k, width, depth, decay): """ Create a new Top-K Filter `key` with desired probability of false @@ -432,6 +435,7 @@ def info(self, key): class CMSCommands: + """Count-Min Sketch Commands""" # region Count-Min Sketch Functions def initbydim(self, key, width, depth): diff --git a/redis/commands/graph/commands.py b/redis/commands/graph/commands.py index f0c1d687ed..e097936503 100644 --- a/redis/commands/graph/commands.py +++ b/redis/commands/graph/commands.py @@ -6,6 +6,8 @@ class GraphCommands: + """RedisGraph Commands""" + def commit(self): """ Create entire graph.