Class: ModelContextProtocol::Server::StreamableHttpTransport::EventCounter
- Inherits:
-
Object
- Object
- ModelContextProtocol::Server::StreamableHttpTransport::EventCounter
- Defined in:
- lib/model_context_protocol/server/streamable_http_transport/event_counter.rb
Constant Summary collapse
- COUNTER_KEY_PREFIX =
"event_counter:"
Instance Method Summary collapse
- #current_count ⇒ Object
-
#initialize(redis_client, server_instance) ⇒ EventCounter
constructor
A new instance of EventCounter.
- #next_event_id ⇒ Object
- #reset ⇒ Object
- #set_count(value) ⇒ Object
Constructor Details
#initialize(redis_client, server_instance) ⇒ EventCounter
Returns a new instance of EventCounter.
6 7 8 9 10 11 12 13 14 |
# File 'lib/model_context_protocol/server/streamable_http_transport/event_counter.rb', line 6 def initialize(redis_client, server_instance) @redis = redis_client @server_instance = server_instance @counter_key = "#{COUNTER_KEY_PREFIX}#{server_instance}" if @redis.exists(@counter_key) == 0 @redis.set(@counter_key, 0) end end |
Instance Method Details
#current_count ⇒ Object
21 22 23 24 |
# File 'lib/model_context_protocol/server/streamable_http_transport/event_counter.rb', line 21 def current_count count = @redis.get(@counter_key) count ? count.to_i : 0 end |
#next_event_id ⇒ Object
16 17 18 19 |
# File 'lib/model_context_protocol/server/streamable_http_transport/event_counter.rb', line 16 def next_event_id count = @redis.incr(@counter_key) "#{@server_instance}-#{count}" end |
#reset ⇒ Object
26 27 28 |
# File 'lib/model_context_protocol/server/streamable_http_transport/event_counter.rb', line 26 def reset @redis.set(@counter_key, 0) end |
#set_count(value) ⇒ Object
30 31 32 |
# File 'lib/model_context_protocol/server/streamable_http_transport/event_counter.rb', line 30 def set_count(value) @redis.set(@counter_key, value.to_i) end |