Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
## Installation

Install the gem and add to the application's Gemfile by executing:

```ruby
# Gemfile
$ gem "redis_stream", git: "https://github.com/test-IO/redis_stream"
```

## Usage

Initialize the gem with the Redis client you want to use in you `config/initializers/
Initialize the gem with the Redis client you want to use in you `config/initializers/`

```ruby
RedisStream.configure do |config|
config.redis(Redis.new(url: "redis://localhost:6379/0"))
config.redis_url("redis://localhost:6379/0")
config.group("group_name")
config.consumer("consumer_name")
config.stream("stream_name")
config.logging_stream("logging_stream_name")
config.maxlen(200) # optional, defaults to 100
end
```

`maxlen` is optional and caps the stream length when publishing (passed to Redis `XADD` with the approximate flag). If omitted, the default of 100 is used.

### Subscribe

To subscribe you will always need to provide the name of the stream you want to listen to, you can also provide an array of stream.

```ruby
Expand Down
7 changes: 6 additions & 1 deletion lib/redis_stream/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module RedisStream
class Configuration
attr_accessor :client, :group_id, :consumer_id, :stream_key, :logging_stream_key
attr_accessor :client, :group_id, :consumer_id, :stream_key, :logging_stream_key, :max_length

def initialize
@group = "group"
@consumer = "consumer"
@stream_key = "stream"
@logging_stream_key = "logging_stream"
@max_length = 100
end

def redis(client)
Expand All @@ -32,5 +33,9 @@ def stream(stream)
def logging_stream(logging_stream)
@logging_stream_key = logging_stream
end

def maxlen(max_length)
@max_length = max_length
end
end
end
2 changes: 1 addition & 1 deletion lib/redis_stream/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(stream_key)

def publish(name, data = {})
data = {"name" => name, "json" => JSON.generate(data)}
RedisStream.client.xadd(@stream_key, data, maxlen: 1000, approximate: true)
RedisStream.client.xadd(@stream_key, data, maxlen: RedisStream.config.max_length, approximate: true)
end
end
end
Loading