@@ -23,10 +23,18 @@ module Redis
2323 # Legacy.
2424 ServerError = ::Protocol ::Redis ::ServerError
2525
26+ # A Redis client that provides connection pooling and context management.
2627 class Client
2728 include ::Protocol ::Redis ::Methods
2829
30+ # Methods module providing Redis-specific functionality.
2931 module Methods
32+ # Subscribe to one or more channels for pub/sub messaging.
33+ # @parameter channels [Array(String)] The channels to subscribe to.
34+ # @yields {|context| ...} If a block is given, it will be executed within the subscription context.
35+ # @parameter context [Context::Subscribe] The subscription context.
36+ # @returns [Object] The result of the block if block given.
37+ # @returns [Context::Subscribe] The subscription context if no block given.
3038 def subscribe ( *channels )
3139 context = Context ::Subscribe . new ( @pool , channels )
3240
@@ -39,6 +47,11 @@ def subscribe(*channels)
3947 end
4048 end
4149
50+ # Execute commands within a Redis transaction.
51+ # @yields {|context| ...} If a block is given, it will be executed within the transaction context.
52+ # @parameter context [Context::Transaction] The transaction context.
53+ # @returns [Object] The result of the block if block given.
54+ # @returns [Context::Transaction] Else if no block is given, returns the transaction context.
4255 def transaction ( &block )
4356 context = Context ::Transaction . new ( @pool )
4457
@@ -53,6 +66,11 @@ def transaction(&block)
5366
5467 alias multi transaction
5568
69+ # Execute commands in a pipeline for improved performance.
70+ # @yields {|context| ...} If a block is given, it will be executed within the pipeline context.
71+ # @parameter context [Context::Pipeline] The pipeline context.
72+ # @returns [Object] The result of the block if block given.
73+ # @returns [Context::Pipeline] The pipeline context if no block given.
5674 def pipeline ( &block )
5775 context = Context ::Pipeline . new ( @pool )
5876
@@ -68,6 +86,9 @@ def pipeline(&block)
6886 # Deprecated.
6987 alias nested pipeline
7088
89+ # Execute a Redis command directly.
90+ # @parameter arguments [Array] The command and its arguments.
91+ # @returns [Object] The response from the Redis server.
7192 def call ( *arguments )
7293 @pool . acquire do |connection |
7394 connection . write_request ( arguments )
@@ -78,25 +99,37 @@ def call(*arguments)
7899 end
79100 end
80101
102+ # Close the client and all its connections.
81103 def close
82104 @pool . close
83105 end
84106 end
85107
86108 include Methods
87109
110+ # Create a new Redis client.
111+ # @parameter endpoint [Endpoint] The Redis endpoint to connect to.
112+ # @parameter protocol [Protocol] The protocol to use for communication.
113+ # @parameter options [Hash] Additional options for the connection pool.
88114 def initialize ( endpoint = Endpoint . local , protocol : endpoint . protocol , **options )
89115 @endpoint = endpoint
90116 @protocol = protocol
91117
92118 @pool = make_pool ( **options )
93119 end
94120
121+ # @attribute [Endpoint] The Redis endpoint.
95122 attr :endpoint
123+
124+ # @attribute [Protocol] The communication protocol.
96125 attr :protocol
97126
98- # @return [client] if no block provided.
99- # @yield [client, task] yield the client in an async task.
127+ # Open a Redis client and optionally yield it in an async task.
128+ # @yields {|client, task| ...} If a block is given, yield the client in an async task.
129+ # @parameter client [Client] The Redis client instance.
130+ # @parameter task [Async::Task] The async task.
131+ # @returns [Client] The client if no block provided.
132+ # @returns [Object] The result of the block if block given.
100133 def self . open ( *arguments , **options , &block )
101134 client = self . new ( *arguments , **options )
102135
0 commit comments