valkey-glide 2.0.0rc3__cp310-cp310-macosx_11_0_arm64.whl → 2.2.3__cp310-cp310-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. glide/__init__.py +160 -106
  2. glide/async_commands/cluster_commands.py +108 -105
  3. glide/async_commands/core.py +637 -444
  4. glide/async_commands/{server_modules/ft.py → ft.py} +8 -7
  5. glide/async_commands/{server_modules/glide_json.py → glide_json.py} +15 -92
  6. glide/async_commands/standalone_commands.py +27 -58
  7. glide/glide.cpython-310-darwin.so +0 -0
  8. glide/glide.pyi +26 -1
  9. glide/glide_client.py +269 -125
  10. glide/logger.py +33 -21
  11. glide/opentelemetry.py +185 -0
  12. glide_shared/__init__.py +330 -0
  13. glide_shared/commands/__init__.py +0 -0
  14. {glide/async_commands → glide_shared/commands}/batch.py +476 -64
  15. glide_shared/commands/batch_options.py +261 -0
  16. glide_shared/commands/core_options.py +407 -0
  17. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +3 -3
  18. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +4 -2
  19. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +4 -4
  20. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +4 -2
  21. {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +4 -4
  22. glide_shared/commands/server_modules/json_options.py +93 -0
  23. {glide/async_commands → glide_shared/commands}/sorted_set.py +2 -2
  24. {glide/async_commands → glide_shared/commands}/stream.py +1 -1
  25. {glide → glide_shared}/config.py +386 -61
  26. {glide → glide_shared}/constants.py +3 -3
  27. {glide → glide_shared}/exceptions.py +27 -1
  28. glide_shared/protobuf/command_request_pb2.py +56 -0
  29. glide_shared/protobuf/connection_request_pb2.py +56 -0
  30. {glide → glide_shared}/protobuf/response_pb2.py +6 -6
  31. {glide → glide_shared}/routes.py +54 -15
  32. valkey_glide-2.2.3.dist-info/METADATA +211 -0
  33. valkey_glide-2.2.3.dist-info/RECORD +40 -0
  34. glide/protobuf/command_request_pb2.py +0 -54
  35. glide/protobuf/command_request_pb2.pyi +0 -1187
  36. glide/protobuf/connection_request_pb2.py +0 -54
  37. glide/protobuf/connection_request_pb2.pyi +0 -320
  38. glide/protobuf/response_pb2.pyi +0 -100
  39. valkey_glide-2.0.0rc3.dist-info/METADATA +0 -127
  40. valkey_glide-2.0.0rc3.dist-info/RECORD +0 -37
  41. {glide/async_commands → glide_shared/commands}/bitmap.py +0 -0
  42. {glide/async_commands → glide_shared/commands}/command_args.py +0 -0
  43. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
  44. {glide → glide_shared}/protobuf_codec.py +0 -0
  45. {valkey_glide-2.0.0rc3.dist-info → valkey_glide-2.2.3.dist-info}/WHEEL +0 -0
@@ -5,24 +5,24 @@ module for `vector search` commands.
5
5
 
6
6
  from typing import List, Mapping, Optional, cast
7
7
 
8
- from glide.async_commands.server_modules.ft_options.ft_aggregate_options import (
8
+ from glide_shared.commands.server_modules.ft_options.ft_aggregate_options import (
9
9
  FtAggregateOptions,
10
10
  )
11
- from glide.async_commands.server_modules.ft_options.ft_constants import (
11
+ from glide_shared.commands.server_modules.ft_options.ft_constants import (
12
12
  CommandNames,
13
13
  FtCreateKeywords,
14
14
  )
15
- from glide.async_commands.server_modules.ft_options.ft_create_options import (
15
+ from glide_shared.commands.server_modules.ft_options.ft_create_options import (
16
16
  Field,
17
17
  FtCreateOptions,
18
18
  )
19
- from glide.async_commands.server_modules.ft_options.ft_profile_options import (
19
+ from glide_shared.commands.server_modules.ft_options.ft_profile_options import (
20
20
  FtProfileOptions,
21
21
  )
22
- from glide.async_commands.server_modules.ft_options.ft_search_options import (
22
+ from glide_shared.commands.server_modules.ft_options.ft_search_options import (
23
23
  FtSearchOptions,
24
24
  )
25
- from glide.constants import (
25
+ from glide_shared.constants import (
26
26
  TOK,
27
27
  FtAggregateResponse,
28
28
  FtInfoResponse,
@@ -30,7 +30,8 @@ from glide.constants import (
30
30
  FtSearchResponse,
31
31
  TEncodable,
32
32
  )
33
- from glide.glide_client import TGlideClient
33
+
34
+ from ..glide_client import TGlideClient
34
35
 
35
36
 
36
37
  async def create(
@@ -7,7 +7,7 @@ Examples:
7
7
  >>> import json
8
8
  >>> value = {'a': 1.0, 'b': 2}
9
9
  >>> json_str = json.dumps(value) # Convert Python dictionary to JSON string using json.dumps()
10
- >>> await json.set(client, "doc", "$", json_str)
10
+ >>> await glide_json.set(client, "doc", "$", json_str)
11
11
  'OK' # Indicates successful setting of the value at path '$' in the key stored at `doc`.
12
12
  >>> json_get = await glide_json.get(client, "doc", "$") # Returns the value at path '$' in the JSON document stored at
13
13
  # `doc` as JSON string.
@@ -19,97 +19,20 @@ Examples:
19
19
  """
20
20
  from typing import List, Optional, Union, cast
21
21
 
22
- from glide.async_commands.core import ConditionalChange
23
- from glide.constants import TOK, TEncodable, TJsonResponse, TJsonUniversalResponse
24
- from glide.glide_client import TGlideClient
25
-
26
-
27
- class JsonGetOptions:
28
- """
29
- Represents options for formatting JSON data, to be used in the [JSON.GET](https://valkey.io/commands/json.get/) command.
30
-
31
- Args:
32
- indent (Optional[str]): Sets an indentation string for nested levels. Defaults to None.
33
- newline (Optional[str]): Sets a string that's printed at the end of each line. Defaults to None.
34
- space (Optional[str]): Sets a string that's put between a key and a value. Defaults to None.
35
- """
36
-
37
- def __init__(
38
- self,
39
- indent: Optional[str] = None,
40
- newline: Optional[str] = None,
41
- space: Optional[str] = None,
42
- ):
43
- self.indent = indent
44
- self.new_line = newline
45
- self.space = space
46
-
47
- def get_options(self) -> List[str]:
48
- args = []
49
- if self.indent:
50
- args.extend(["INDENT", self.indent])
51
- if self.new_line:
52
- args.extend(["NEWLINE", self.new_line])
53
- if self.space:
54
- args.extend(["SPACE", self.space])
55
- return args
56
-
57
-
58
- class JsonArrIndexOptions:
59
- """
60
- Options for the `JSON.ARRINDEX` command.
61
-
62
- Args:
63
- start (int): The inclusive start index from which the search begins. Defaults to None.
64
- end (Optional[int]): The exclusive end index where the search stops. Defaults to None.
65
-
66
- Note:
67
- - If `start` is greater than `end`, the command returns `-1` to indicate that the value was not found.
68
- - Indices that exceed the array bounds are automatically adjusted to the nearest valid position.
69
- """
70
-
71
- def __init__(self, start: int, end: Optional[int] = None):
72
- self.start = start
73
- self.end = end
74
-
75
- def to_args(self) -> List[str]:
76
- """
77
- Get the options as a list of arguments for the JSON.ARRINDEX command.
78
-
79
- Returns:
80
- List[str]: A list containing the start and end indices if specified.
81
- """
82
- args = [str(self.start)]
83
- if self.end is not None:
84
- args.append(str(self.end))
85
- return args
86
-
87
-
88
- class JsonArrPopOptions:
89
- """
90
- Options for the JSON.ARRPOP command.
91
-
92
- Args:
93
- path (TEncodable): The path within the JSON document.
94
- index (Optional[int]): The index of the element to pop. If not specified, will pop the last element.
95
- Out of boundary indexes are rounded to their respective array boundaries. Defaults to None.
96
- """
97
-
98
- def __init__(self, path: TEncodable, index: Optional[int] = None):
99
- self.path = path
100
- self.index = index
101
-
102
- def to_args(self) -> List[TEncodable]:
103
- """
104
- Get the options as a list of arguments for the `JSON.ARRPOP` command.
105
-
106
- Returns:
107
- List[TEncodable]: A list containing the path and, if specified, the index.
108
- """
109
- args = [self.path]
110
- if self.index is not None:
111
- args.append(str(self.index))
112
- return args
22
+ from glide_shared.commands.core_options import ConditionalChange
23
+ from glide_shared.commands.server_modules.json_options import (
24
+ JsonArrIndexOptions,
25
+ JsonArrPopOptions,
26
+ JsonGetOptions,
27
+ )
28
+ from glide_shared.constants import (
29
+ TOK,
30
+ TEncodable,
31
+ TJsonResponse,
32
+ TJsonUniversalResponse,
33
+ )
34
+
35
+ from ..glide_client import TGlideClient
113
36
 
114
37
 
115
38
  async def set(
@@ -4,24 +4,25 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Dict, List, Mapping, Optional, Union, cast
6
6
 
7
- from glide.async_commands.batch import Batch
8
- from glide.async_commands.command_args import ObjectType
9
- from glide.async_commands.core import (
10
- CoreCommands,
7
+ from glide.glide import Script
8
+ from glide_shared.commands.batch import Batch
9
+ from glide_shared.commands.batch_options import BatchOptions
10
+ from glide_shared.commands.command_args import ObjectType
11
+ from glide_shared.commands.core_options import (
11
12
  FlushMode,
12
13
  FunctionRestorePolicy,
13
14
  InfoSection,
14
15
  )
15
- from glide.constants import (
16
+ from glide_shared.constants import (
16
17
  TOK,
17
18
  TEncodable,
18
19
  TFunctionListResponse,
19
20
  TFunctionStatsFullResponse,
20
21
  TResult,
21
22
  )
22
- from glide.protobuf.command_request_pb2 import RequestType
23
+ from glide_shared.protobuf.command_request_pb2 import RequestType
23
24
 
24
- from ..glide import Script
25
+ from .core import CoreCommands
25
26
 
26
27
 
27
28
  class StandaloneCommands(CoreCommands):
@@ -31,6 +32,10 @@ class StandaloneCommands(CoreCommands):
31
32
  See the [Valkey GLIDE Wiki](https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command)
32
33
  for details on the restrictions and limitations of the custom command API.
33
34
 
35
+ This function should only be used for single-response commands. Commands that don't return complete response and awaits
36
+ (such as SUBSCRIBE), or that return potentially more than a single response (such as XREAD), or that change the
37
+ client's behavior (such as entering pub/sub mode on RESP2 connections) shouldn't be called using this function.
38
+
34
39
  Args:
35
40
  command_args (List[TEncodable]): List of the command's arguments, where each argument is either a string or bytes.
36
41
  Every part of the command, including the command name and subcommands, should be added as a separate value in args.
@@ -39,7 +44,8 @@ class StandaloneCommands(CoreCommands):
39
44
  TResult: The returning value depends on the executed command.
40
45
 
41
46
  Example:
42
- >>> connection.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"])
47
+ >>> await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"])
48
+ # Expected Output: A list of all pub/sub clients
43
49
 
44
50
  """
45
51
  return await self._execute_command(RequestType.CustomCommand, command_args)
@@ -51,6 +57,8 @@ class StandaloneCommands(CoreCommands):
51
57
  """
52
58
  Get information and statistics about the server.
53
59
 
60
+ Starting from server version 7, command supports multiple section arguments.
61
+
54
62
  See [valkey.io](https://valkey.io/commands/info/) for details.
55
63
 
56
64
  Args:
@@ -69,7 +77,7 @@ class StandaloneCommands(CoreCommands):
69
77
  self,
70
78
  batch: Batch,
71
79
  raise_on_error: bool,
72
- timeout: Optional[int] = None,
80
+ options: Optional[BatchOptions] = None,
73
81
  ) -> Optional[List[TResult]]:
74
82
  """
75
83
  Executes a batch by processing the queued commands.
@@ -89,10 +97,7 @@ class StandaloneCommands(CoreCommands):
89
97
  When set to ``False``, errors will be included as part of the batch response array, allowing
90
98
  the caller to process both successful and failed commands together. In this case, error details
91
99
  will be provided as instances of ``RequestError``.
92
- timeout (Optional[int]): The duration in milliseconds that the client should wait for the batch request
93
- to complete. This duration encompasses sending the request, awaiting a response from the server, and any
94
- required reconnections or retries. If the specified timeout is exceeded for the request,
95
- a timeout error will be raised. If not explicitly set, the client's default request timeout will be used.
100
+ options (Optional[BatchOptions]): A ``BatchOptions`` object containing execution options.
96
101
 
97
102
  Returns:
98
103
  Optional[List[TResult]]: An array of results, where each entry corresponds to a command's execution result.
@@ -118,33 +123,38 @@ class StandaloneCommands(CoreCommands):
118
123
  # Expected Output: Pipeline Batch Result: [OK, OK, b'value1', b'value2']
119
124
 
120
125
  Example (Atomic Batch - Transaction with options):
126
+ >>> from glide import BatchOptions
121
127
  >>> transaction = Batch(is_atomic=True)
122
128
  >>> transaction.set("key", "1")
123
129
  >>> transaction.incr("key")
124
130
  >>> transaction.custom_command(["get", "key"])
131
+ >>> options = BatchOptions(timeout=1000) # Set a timeout of 1000 milliseconds
125
132
  >>> result = await client.exec(
126
133
  ... transaction,
127
134
  ... raise_on_error=False, # Do not raise an error on failure
128
- ... timeout=1000 # Set a timeout of 1000 milliseconds
135
+ ... options=options
129
136
  ... )
130
137
  >>> print(f"Transaction Result: {result}")
131
138
  # Expected Output: Transaction Result: [OK, 2, b'2']
132
139
 
133
140
  Example (Non-Atomic Batch - Pipeline with options):
141
+ >>> from glide import BatchOptions
134
142
  >>> pipeline = Batch(is_atomic=False)
135
143
  >>> pipeline.custom_command(["set", "key1", "value1"])
136
144
  >>> pipeline.custom_command(["set", "key2", "value2"])
137
145
  >>> pipeline.custom_command(["get", "key1"])
138
146
  >>> pipeline.custom_command(["get", "key2"])
147
+ >>> options = BatchOptions(timeout=1000) # Set a timeout of 1000 milliseconds
139
148
  >>> result = await client.exec(
140
149
  ... pipeline,
141
150
  ... raise_on_error=False, # Do not raise an error on failure
142
- ... timeout=1000 # Set a timeout of 1000 milliseconds
151
+ ... options=options
143
152
  ... )
144
153
  >>> print(f"Pipeline Result: {result}")
145
154
  # Expected Output: Pipeline Result: [OK, OK, b'value1', b'value2']
146
155
  """
147
156
  commands = batch.commands[:]
157
+ timeout = options.timeout if options else None
148
158
  return await self._execute_batch(
149
159
  commands,
150
160
  is_atomic=batch.is_atomic,
@@ -152,20 +162,6 @@ class StandaloneCommands(CoreCommands):
152
162
  timeout=timeout,
153
163
  )
154
164
 
155
- async def select(self, index: int) -> TOK:
156
- """
157
- Change the currently selected database.
158
-
159
- See [valkey.io](https://valkey.io/commands/select/) for details.
160
-
161
- Args:
162
- index (int): The index of the database to select.
163
-
164
- Returns:
165
- A simple OK response.
166
- """
167
- return cast(TOK, await self._execute_command(RequestType.Select, [str(index)]))
168
-
169
165
  async def config_resetstat(self) -> TOK:
170
166
  """
171
167
  Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM commands.
@@ -619,31 +615,6 @@ class StandaloneCommands(CoreCommands):
619
615
  await self._execute_command(RequestType.LastSave, []),
620
616
  )
621
617
 
622
- async def move(self, key: TEncodable, db_index: int) -> bool:
623
- """
624
- Move `key` from the currently selected database to the database specified by `db_index`.
625
-
626
- See [valkey.io](https://valkey.io/commands/move/) for more details.
627
-
628
- Args:
629
- key (TEncodable): The key to move.
630
- db_index (int): The index of the database to move `key` to.
631
-
632
- Returns:
633
- bool: `True` if `key` was moved.
634
-
635
- `False` if the `key` already exists in the destination database
636
- or does not exist in the source database.
637
-
638
- Example:
639
- >>> await client.move("some_key", 1)
640
- True
641
- """
642
- return cast(
643
- bool,
644
- await self._execute_command(RequestType.Move, [key, str(db_index)]),
645
- )
646
-
647
618
  async def publish(self, message: TEncodable, channel: TEncodable) -> int:
648
619
  """
649
620
  Publish a message on pubsub channel.
@@ -796,7 +767,7 @@ class StandaloneCommands(CoreCommands):
796
767
  args.extend(["VERSION", str(version)])
797
768
  if parameters:
798
769
  for var in parameters:
799
- args.extend(str(var))
770
+ args.append(str(var))
800
771
  return cast(
801
772
  bytes,
802
773
  await self._execute_command(RequestType.Lolwut, args),
@@ -861,8 +832,6 @@ class StandaloneCommands(CoreCommands):
861
832
  TOK: A simple "OK" response.
862
833
 
863
834
  Examples:
864
- >>> await client.watch("sampleKey")
865
- 'OK'
866
835
  >>> await client.unwatch()
867
836
  'OK'
868
837
  """
@@ -1026,7 +995,7 @@ class StandaloneCommands(CoreCommands):
1026
995
 
1027
996
  Examples:
1028
997
  >>> lua_script = Script("return { KEYS[1], ARGV[1] }")
1029
- >>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"] );
998
+ >>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"])
1030
999
  [b"foo", b"bar"]
1031
1000
  """
1032
1001
  return await self._execute_script(script.get_hash(), keys, args)
Binary file
glide/glide.pyi CHANGED
@@ -2,7 +2,7 @@ from collections.abc import Callable
2
2
  from enum import Enum
3
3
  from typing import List, Optional, Union
4
4
 
5
- from glide.constants import TResult
5
+ from glide_shared.constants import TResult
6
6
 
7
7
  DEFAULT_TIMEOUT_IN_MILLISECONDS: int = ...
8
8
  MAX_REQUEST_ARGS_LEN: int = ...
@@ -27,6 +27,28 @@ class ClusterScanCursor:
27
27
  def get_cursor(self) -> str: ...
28
28
  def is_finished(self) -> bool: ...
29
29
 
30
+ class OpenTelemetryConfig:
31
+ def __init__(
32
+ self,
33
+ traces: Optional[OpenTelemetryTracesConfig] = None,
34
+ metrics: Optional[OpenTelemetryMetricsConfig] = None,
35
+ flush_interval_ms: Optional[int] = None,
36
+ ) -> None: ...
37
+ def get_traces(self) -> Optional[OpenTelemetryTracesConfig]: ...
38
+ def set_traces(self, traces: OpenTelemetryTracesConfig) -> None: ...
39
+ def get_metrics(self) -> Optional[OpenTelemetryMetricsConfig]: ...
40
+
41
+ class OpenTelemetryTracesConfig:
42
+ def __init__(
43
+ self, endpoint: str, sample_percentage: Optional[int] = None
44
+ ) -> None: ...
45
+ def get_endpoint(self) -> str: ...
46
+ def get_sample_percentage(self) -> Optional[int]: ...
47
+
48
+ class OpenTelemetryMetricsConfig:
49
+ def __init__(self, endpoint: str) -> None: ...
50
+ def get_endpoint(self) -> str: ...
51
+
30
52
  def start_socket_listener_external(init_callback: Callable) -> None: ...
31
53
  def value_from_pointer(pointer: int) -> TResult: ...
32
54
  def create_leaked_value(message: str) -> int: ...
@@ -34,3 +56,6 @@ def create_leaked_bytes_vec(args_vec: List[bytes]) -> int: ...
34
56
  def get_statistics() -> dict: ...
35
57
  def py_init(level: Optional[Level], file_name: Optional[str]) -> Level: ...
36
58
  def py_log(log_level: Level, log_identifier: str, message: str) -> None: ...
59
+ def create_otel_span(name: str) -> int: ...
60
+ def drop_otel_span(span_ptr: int) -> None: ...
61
+ def init_opentelemetry(config: OpenTelemetryConfig) -> None: ...