simple-feed 2.1.0 → 3.2.0
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.
- checksums.yaml +4 -4
- data/.envrc +3 -0
- data/.github/workflows/rubocop.yml +22 -22
- data/.github/workflows/ruby.yml +21 -22
- data/.gitignore +2 -1
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +102 -33
- data/.travis.yml +3 -13
- data/CHANGELOG.md +128 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.adoc +209 -79
- data/README.pdf +25720 -12
- data/Rakefile +1 -1
- data/codecov.yml +28 -0
- data/examples/shared/provider_example.rb +43 -25
- data/lib/simplefeed/activity/single_user.rb +2 -2
- data/lib/simplefeed/dsl/formatter.rb +67 -28
- data/lib/simplefeed/event.rb +48 -10
- data/lib/simplefeed/feed.rb +20 -9
- data/lib/simplefeed/providers/base/provider.rb +1 -1
- data/lib/simplefeed/providers/key.rb +57 -42
- data/lib/simplefeed/providers/proxy.rb +20 -7
- data/lib/simplefeed/providers/redis/driver.rb +3 -7
- data/lib/simplefeed/providers/redis/provider.rb +6 -6
- data/lib/simplefeed/providers.rb +0 -1
- data/lib/simplefeed/response.rb +3 -5
- data/lib/simplefeed/version.rb +1 -1
- data/lib/simplefeed.rb +21 -17
- data/man/running-example-redis-debug.png +0 -0
- data/man/running-example.png +0 -0
- data/man/sf-color-dump.png +0 -0
- data/simple-feed.gemspec +7 -3
- metadata +56 -15
- data/examples/hash_provider_example.rb +0 -24
- data/lib/simplefeed/key/template.rb +0 -48
- data/lib/simplefeed/key/type.rb +0 -28
- data/lib/simplefeed/providers/hash/paginator.rb +0 -33
- data/lib/simplefeed/providers/hash/provider.rb +0 -188
data/README.adoc
CHANGED
@@ -3,82 +3,130 @@
|
|
3
3
|
:toc:
|
4
4
|
:toclevels: 5
|
5
5
|
:sectnums:
|
6
|
+
:icons: font
|
6
7
|
|
7
|
-
|
8
|
+
====
|
8
9
|
|
9
|
-
image:https://
|
10
|
-
|
10
|
+
https://liberapay.com/kigster/donate[image:https://liberapay.com/assets/widgets/donate.svg[Donate using Liberapay,height=30]]
|
11
|
+
|
12
|
+
https://liberapay.com/kigster/donate[image:https://img.shields.io/liberapay/goal/kigster.svg?logo=liberapay[https://img.shields.io/liberapay/goal/kigster,height=50]]
|
13
|
+
====
|
14
|
+
|
15
|
+
== Scalable, Easy to Use Activity (aka "News") Feed
|
11
16
|
|
12
|
-
|
13
|
-
image:https://github.com/kigster/simple-feed/workflows/Rubocop/badge.svg?branch=master[Ruby,link=https://github.com/kigster/simple-feed/actions?query=workflow%3ARubocop]
|
17
|
+
=== What is this gem? — A Quick Summary
|
14
18
|
|
15
|
-
|
16
|
-
image:https://api.codeclimate.com/v1/badges/a11061820895fcde635e/maintainability[Maintainability,link=https://codeclimate.com/github/kigster/simple-feed/maintainability]
|
17
|
-
image:https://api.codeclimate.com/v1/badges/a11061820895fcde635e/test_coverage[Test Coverage,link=https://codeclimate.com/github/kigster/simple-feed/test_coverage]
|
19
|
+
NOTE: This gem is the Redis-backed backend implementation for a reverse chronological order news feed for a typical social network similar in some ways to Twitter: where users have followers, but also topics or a categories can have followers. When an event is posted by a user, it is also pushed to various individual feeds, and the gem then offers `O(1)` speed pagination for reading any page of the feed. The limitation is that the number of feed items must be capped (the default is 4000 items). The implementation can be scaled horizontally by sharding Redis backend, which can be implemented using a Redis Proxy layer such as https://github.com/twitter/twemproxy[Twemproxy] or https://github.com/envoyproxy/envoy/issues/19436[Envoy]).
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
=== Build & Gem Status
|
22
|
+
|
23
|
+
image:https://img.shields.io/badge/license-MIT-blue.svg[MIT licensed,link=https://github.com/kigster/simple-feed/main/LICENSE.txt]
|
24
|
+
image:https://github.com/kigster/simple-feed/actions/workflows/ruby.yml/badge.svg[RSpec,link=https://github.com/kigster/simple-feed/actions/workflows/ruby.yml]
|
25
|
+
image:https://github.com/kigster/simple-feed/actions/workflows/rubocop.yml/badge.svg[Rubocop,link=https://github.com/kigster/simple-feed/actions/workflows/rubocop.yml]
|
26
|
+
|
27
|
+
image:https://img.shields.io/gem/v/simple-feed.svg[Gem Version,link=https://rubygems.org/gems/simple-feed]
|
28
|
+
image:https://codecov.io/gh/kigster/simple-feed/branch/master/graph/badge.svg?token=RvDkGqoahz[Coverage,link=https://codecov.io/gh/kigster/simple-feed]
|
29
|
+
|
30
|
+
=== Test Coverage Map
|
31
|
+
|
32
|
+
image:https://codecov.io/gh/kigster/simple-feed/graphs/sunburst.svg?token=RvDkGqoahz[Coverage Map,link=https://codecov.io/gh/kigster/simple-feed/branch/master]
|
21
33
|
|
22
34
|
IMPORTANT: Please read the (somewhat outdated) blog post http://kig.re/2017/02/19/feeding-frenzy-with-simple-feed-activity-feed-ruby-gem.html[Feeding Frenzy with SimpleFeed] launching this library. Please leave comments or questions in the discussion thread at the bottom of that post. Thanks!
|
23
35
|
|
24
36
|
If you like to see this project grow, your donation of any amount is much appreciated.
|
25
37
|
|
26
38
|
image::https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif[Donate,link=https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FSFYYNEQ8RKWU]
|
27
|
-
'''
|
28
39
|
|
29
|
-
This is a fast, pure-ruby implementation of an activity feed concept commonly used in social networking applications. The implementation is optimized for *read-time performance* and high concurrency (lots of users), and can be extended with custom backend providers.
|
40
|
+
This is a fast, pure-ruby implementation of an activity feed concept commonly used in social networking applications. The implementation is optimized for *read-time performance* and high concurrency (lots of users), and can be extended with custom backend providers. One data provider come bundled: the production-ready Redis provider.
|
30
41
|
|
31
42
|
*Important Notes and Acknowledgements:*
|
32
43
|
|
33
44
|
* SimpleFeed _does not depend on Ruby on Rails_ and is a *pure-ruby* implementation
|
34
|
-
* SimpleFeed requires
|
45
|
+
* SimpleFeed requires MRI Ruby 2.3 or later
|
35
46
|
* SimpleFeed is currently live in production
|
47
|
+
* SimpleFeed can use https://github.com/redis/hiredis[hiredis] if you install it separately and load it before loading the gem.
|
36
48
|
* SimpleFeed is open source thanks to the generosity of *http://simbi.com[Simbi, Inc]*.
|
37
49
|
|
38
50
|
== Features
|
39
51
|
|
40
|
-
SimpleFeed offers the following features:
|
52
|
+
SimpleFeed is a Ruby Library that can be plugged into any application to power a fast, Redis-based activity feed implementation so common on social networking sites. SimpleFeed offers the following features:
|
53
|
+
|
54
|
+
* Modelled after graph-relationships similar to those on Twitter (bi-directional independent follow relationships):
|
55
|
+
** Feed maintains a reverse-chronological order for heterogeneous events for each user.
|
56
|
+
** It offers a constant time lookup for user's feed, avoiding complex SQL joins to render it.
|
57
|
+
** An API to read/paginate the feed for a given user
|
58
|
+
** As well as to *query the total unread items in the feed* since it was last read by the user (typically shown on App icons).
|
59
|
+
* Scalable and well performing Redis-based activity feed —
|
60
|
+
** Scales to millions of users (will need to use Twemproxy to shard across several Redis instances)
|
61
|
+
** Stores a fixed number of events for each unique "user" — the default is 1000. When the feed reaches 1001 events, the oldest event is offloaded from the activity.
|
62
|
+
* Implementation properties:
|
63
|
+
** Fully thread-safe implementation, writing events can be done in eg. Sidekiq.
|
64
|
+
** Zero assumptions about what you are storing: the "data" is just a string. Serialize it with JSON, Marshall, YAML, or whatever.
|
65
|
+
** You can create as many different types of feeds per application as you like (no Ruby Singletons used).
|
66
|
+
** Customize mapping from `user_id` to the activity id based on your business logic (more on this later).
|
67
|
+
|
68
|
+
=== Publishing Events
|
69
|
+
|
70
|
+
Pushing events to the feed requires the following:
|
41
71
|
|
42
|
-
*
|
72
|
+
* An `Event` consisting of:
|
73
|
+
** String `data` that, most commonly, is a foreign key to a database table, but can really be anything you like.
|
74
|
+
** Float `at` (typically, the timestamp, but can be any `float` number)
|
75
|
+
* One or more user IDs, or event consumers: basically — who should see the event being published in their feed.
|
43
76
|
|
44
|
-
|
77
|
+
You publish an event by choosing a set of users whose feed should be updated. For example, were you re-implementing Twitter, your array of `user_ids` when publishing an event would be all followers of the Tweet's author. While the `data` would probably be the Tweet ID.
|
45
78
|
|
46
|
-
* Stores a fixed number of events per unique activity ID (eg, a user) — the default is 2000. When the full list is used, the oldest events are bumped off the feed (and are effectively trashed).
|
47
79
|
|
48
|
-
|
80
|
+
NOTE: Publishing an event to the feeds of N users is roughly a O(N * log(N)) operation
|
49
81
|
|
50
|
-
|
82
|
+
=== Consuming Events (Reading / Rendering the Feed)
|
51
83
|
|
52
|
-
|
84
|
+
You can fetch the chronologically ordered events for a particular user, using:
|
53
85
|
|
54
|
-
*
|
86
|
+
* Methods on the `activity` such as `paginate`, `fetch`.
|
55
87
|
|
56
|
-
|
88
|
+
** Reading feed for one user (or one type of user) is a `O(1)` operation
|
57
89
|
|
58
|
-
*
|
90
|
+
* For each activity (user) you can fetch the `total_count` and the `unread_count` — the number of total and new items in the feed, where `unread_count` is computed since the user last reset their `read status`.
|
59
91
|
|
60
|
-
|
92
|
+
** Note: `total_count` can never exceed the maximum size of the feed that you configured. The default is 1000 items.
|
61
93
|
|
62
|
-
|
94
|
+
** The `last_read` timestamp can be automatically reset when the user is shown the feed via `paginate` method (whether or not its reset is controlled via a method argument).
|
63
95
|
|
64
|
-
|
96
|
+
=== Modifying User's Feed
|
97
|
+
|
98
|
+
For any given user, you can:
|
99
|
+
|
100
|
+
* Wipe their feed with `wipe`
|
101
|
+
|
102
|
+
* Selectively remove items from the feed with `delete_if`.
|
103
|
+
** For instance, if a user un-follows someone they shouldn't see their events anymore, so you'd have to call `delete_if` and remove any events published by the unfollowed user.
|
104
|
+
|
105
|
+
=== Aggregating Events
|
106
|
+
|
107
|
+
This is a feature planned for future versions.
|
108
|
+
|
109
|
+
Help us much appreciated, even if you are not a developer, but have a clear idea about how it should work.
|
110
|
+
|
111
|
+
== Commercial & Enterprise Support
|
112
|
+
|
113
|
+
Commercial Support plans are available for SimpleFeed through author's https://reinvent.one[ReinventONE Inc] consulting company. Please reach out to kig AT reinvent.one for more information.
|
114
|
+
|
115
|
+
== Usage
|
65
116
|
|
66
|
-
|
117
|
+
=== Example
|
67
118
|
|
68
119
|
Please read the additional documentation, including the examples, on the https://github.com/kigster/simple-feed/wiki[project's Github Wiki].
|
69
120
|
|
70
121
|
Below is a screen shot of an actual activity feed powered by this library.
|
71
122
|
|
72
|
-
image::https://raw.githubusercontent.com/kigster/simple-feed/
|
123
|
+
image::https://raw.githubusercontent.com/kigster/simple-feed/main/man/activity-feed-action.png[usage]
|
73
124
|
|
74
|
-
|
125
|
+
=== Providers
|
75
126
|
|
76
127
|
A key concept to understanding SimpleFeed gem, is that of a _provider_, which is effectively a persistence implementation for the events belonging to each user.
|
77
128
|
|
78
|
-
|
79
|
-
|
80
|
-
* The production-ready `:redis` provider, which uses the https://redislabs.com/ebook/redis-in-action/part-2-core-concepts-2/chapter-3-commands-in-redis/3-5-sorted-sets[sorted set Redis data type] to store and fetch the events, scored by time (but not necessarily).
|
81
|
-
* The naïve `:hash` provider based on the ruby `Hash` class, that can be useful in unit tests, or in simple simulations.
|
129
|
+
One providers are supplied with this gem: the production-ready `:redis` provider, which uses the https://redislabs.com/ebook/redis-in-action/part-2-core-concepts-2/chapter-3-commands-in-redis/3-5-sorted-sets[sorted set Redis data type] to store and fetch the events, scored by time (but not necessarily).
|
82
130
|
|
83
131
|
You initialize a provider by using the `SimpleFeed.provider([Symbol])` method.
|
84
132
|
|
@@ -91,6 +139,7 @@ Below we configure a feed called `:newsfeed`, which in this example will be popu
|
|
91
139
|
require 'simplefeed'
|
92
140
|
|
93
141
|
# Let's define a Redis-based feed, and wrap Redis in a in a ConnectionPool.
|
142
|
+
|
94
143
|
SimpleFeed.define(:newsfeed) do |f|
|
95
144
|
f.provider = SimpleFeed.provider(:redis,
|
96
145
|
redis: -> { ::Redis.new },
|
@@ -108,55 +157,130 @@ After the feed is defined, the gem creates a similarly named method under the `S
|
|
108
157
|
|
109
158
|
You can also get a full list of currently defined feeds with `SimpleFeed.feed_names` method.
|
110
159
|
|
160
|
+
=== Reading from and writing to the feed
|
161
|
+
|
162
|
+
For the impatient, here is a quick way to get started with the `SimpleFeed`.
|
163
|
+
|
164
|
+
[source,ruby]
|
165
|
+
----
|
166
|
+
# Let's use the feed we defined earlier and create activity for all followers of the current user
|
167
|
+
publish_activity = SimpleFeed.newsfeed.activity(@current_user.followers.map(&:id))
|
168
|
+
|
169
|
+
# Store directly the value and the optional time stamp
|
170
|
+
publish_activity.store(value: 'hello', at: Time.now)
|
171
|
+
# => true # indicates that value 'hello' was not yet in the feed (all events must be unique)
|
172
|
+
|
173
|
+
# Or, using the event form:
|
174
|
+
publish_activity.store(event: SimpleFeed::Event.new('good bye', Time.now))
|
175
|
+
# => true
|
176
|
+
----
|
177
|
+
|
178
|
+
As we've added the two events for these users, we can now read them back, sorted by
|
179
|
+
the time and paginated:
|
180
|
+
|
181
|
+
[source,ruby]
|
182
|
+
----
|
183
|
+
# Let's grab the first follower
|
184
|
+
user_activity = SimpleFeed.newsfeed.activity(@current_user.followers.first.id)
|
185
|
+
|
186
|
+
# Now we can paginate the events, while resetting this user's last-read timestamp:
|
187
|
+
user_activity.paginate(page: 1, reset_last_read: true)
|
188
|
+
# [
|
189
|
+
# [0] #<SimpleFeed::Event: value=hello, at=1480475294.0579991>,
|
190
|
+
# [1] #<SimpleFeed::Event: value=good bye, at=1480472342.8979871>,
|
191
|
+
# ]
|
192
|
+
----
|
193
|
+
|
194
|
+
IMPORTANT: Note that we stored the activity by passing an array of users, but read the activity for just one user. This is how you'd use SimpleFeed most of the time, with the exception of the alternative mapping described below.
|
195
|
+
|
111
196
|
=== User IDs
|
112
197
|
|
113
|
-
In the
|
198
|
+
In the previous section you saw the examples of publishing events to many feeds, and then reading the activity for a given user.
|
199
|
+
|
200
|
+
SimpleFeed supports user IDs that are either numeric (integer) or string-based (eg, UUID). Numeric IDs are best for simplest cases, and are the most compact. String keys offer the most flexibility.
|
201
|
+
|
202
|
+
==== Activity Keys
|
114
203
|
|
115
|
-
|
204
|
+
In the next section we'll talk about generating `keys` from user_ids. We mean — Redis Hash keys that uniquely map a user (or a set of users) to the activity feed they should see.
|
116
205
|
|
117
|
-
|
206
|
+
There are up to two keys that are computed depending on the situation:
|
118
207
|
|
119
|
-
|
208
|
+
* `data_key` is used to store the actual feed events
|
209
|
+
* `meta_key` is used to store user's `last_read` status
|
120
210
|
|
121
211
|
==== Partitioning Schema
|
122
212
|
|
123
|
-
|
213
|
+
NOTE: This feature is only available in **SimpleFeed Version 3+**.
|
214
|
+
|
215
|
+
You can take advantage of string user IDs for situations where your feed requires keys to be composite for instance. Just remember that SimpleFeed does not care about what's in your user ID, and even what you call "a user". It's convenient to think of the activities in terms of users, because typically each user has a unique feed that only they see.
|
124
216
|
|
125
217
|
But you can just as easily use zip code as the unique activity ID, and create one feed of events per geographical location, that all folks living in that zip code share. But what about other countries?
|
126
218
|
|
127
|
-
Now you use
|
219
|
+
Now you use partitioning scheme: make the "user_id" argument a combination `iso_country_code.postal_code`, eg for San Francisco, you'd use `us.94107`, but for Australia you could use, eg `au.3148`.
|
128
220
|
|
129
|
-
|
221
|
+
==== Relationship between an Activity and a User
|
130
222
|
|
131
|
-
|
223
|
+
===== One to One
|
224
|
+
|
225
|
+
In the most common case, you will have one activity per user.
|
226
|
+
|
227
|
+
For instance, in the Twitter example, each Twitter user has a unique tweeter feed that only they see.
|
228
|
+
|
229
|
+
The events are published when someone posts a tweet, to the array of all users that follow the Tweet author.
|
230
|
+
|
231
|
+
===== One to Many
|
232
|
+
|
233
|
+
However, SimpleFeed supports one additional use-case, where you might have one activity shared among many users.
|
234
|
+
|
235
|
+
Imagine a service that notifies residents of important announcements based on user's zip code of residence.
|
236
|
+
|
237
|
+
We want this feed to work as follows:
|
238
|
+
|
239
|
+
* All users that share a zip-code should see the same exact feed.
|
240
|
+
* However, all users should never share the individual's `last_read` status: so if two people read the same activity from the same zip code, their `unread_count` should change independently.
|
241
|
+
|
242
|
+
In terms of the activity keys, this means:
|
243
|
+
|
244
|
+
* `data_key` should be based on the zip-code of each user, and be one to many with users.
|
245
|
+
* `meta_key` should be based on the user ID as we want it to be 1-1 with users.
|
246
|
+
|
247
|
+
To support this use-case, SimpleFeed supports two optional transformer lambdas that can be applied to each user object when computing their activity feed hash key:
|
132
248
|
|
133
249
|
[source,ruby]
|
134
250
|
----
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
#
|
140
|
-
|
141
|
-
# or equivalent:
|
142
|
-
@event = SimpleFeed::Event.new('hello', Time.now)
|
143
|
-
activity.store(event: @event)
|
144
|
-
# => false # false indicates that the same event is already in the feed.
|
251
|
+
SimpleFeed.define(:zipcode_alerts) do |f|
|
252
|
+
f.provider = SimpleFeed.provider(:redis, redis: -> { ::Redis.new }, pool_size: 10)
|
253
|
+
f.namespace = 'zc'
|
254
|
+
f.data_key_transformer = ->(user) { user.zip_code } # actual feed data is stored once per zip code
|
255
|
+
f.meta_key_transformer = ->(user) { user.id } # last_read status is stored once per user
|
256
|
+
end
|
145
257
|
----
|
146
258
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
259
|
+
When you publish events into this feed, you would need to provide `User` objects that all respond to `.zip_code` method (based on the above configuration). Since the data is only defined by Zip Code, you probably don't want to be publishing it via a giant array of users. Most likely, you'll want to publish event based on the zip code, and consume them based on the user ID.
|
260
|
+
|
261
|
+
To support this user-case, let's modify our transformer lambda (only the `data` one) as follows — so that it can support both the consuming read by a user case, and the publishing a feed by zip code case:
|
262
|
+
|
263
|
+
Alternatively, you could do something like this:
|
152
264
|
|
153
265
|
[source,ruby]
|
154
266
|
----
|
155
|
-
|
156
|
-
|
267
|
+
f.data_key_transformer = ->(entity) do
|
268
|
+
case entity
|
269
|
+
when User
|
270
|
+
entity.zip_code.to_i
|
271
|
+
when String # UUIDs
|
272
|
+
User.find(entity)&.zip_code.to_i
|
273
|
+
when ZipCode, Numeric
|
274
|
+
entity.to_i
|
275
|
+
else
|
276
|
+
raise ArgumentError, "Invalid type #{entity.class.name}"
|
277
|
+
end
|
278
|
+
end
|
157
279
|
----
|
158
280
|
|
159
|
-
|
281
|
+
Just make sure that your users always have `.zip_code` defined, and that `ZipCode.new(94107).to_i` returns exactly the same thing as `@user.zip_code.to_i` or your users won't see the feeds they are supposed to see.
|
282
|
+
|
283
|
+
=== The Two Forms of the Feed API
|
160
284
|
|
161
285
|
The feed API is offered in two forms:
|
162
286
|
|
@@ -170,9 +294,8 @@ The method names and signatures are the same. The only difference is in what the
|
|
170
294
|
|
171
295
|
Please see further below the details about the <<batch-api,Batch API>>.
|
172
296
|
|
173
|
-
+++<a name="single-user-api">++++++</a>+++
|
174
|
-
|
175
297
|
[discrete]
|
298
|
+
|
176
299
|
===== Single-User API
|
177
300
|
|
178
301
|
In the examples below we show responses based on a single-user usage. As previously mentioned, the multi-user usage is the same, except what the response values are, and is discussed further down below.
|
@@ -183,10 +306,10 @@ Let's take a look at a ruby session, which demonstrates return values of the fee
|
|
183
306
|
----
|
184
307
|
require 'simplefeed'
|
185
308
|
|
186
|
-
# Define the feed using
|
309
|
+
# Define the feed using Redis provider, which uses
|
187
310
|
# SortedSet to keep user's events sorted.
|
188
311
|
SimpleFeed.define(:followers) do |f|
|
189
|
-
f.provider = SimpleFeed.provider(:
|
312
|
+
f.provider = SimpleFeed.provider(:redis)
|
190
313
|
f.per_page = 50
|
191
314
|
f.per_page = 2
|
192
315
|
end
|
@@ -316,7 +439,7 @@ The DSL context has access to two additional methods:
|
|
316
439
|
|
317
440
|
Below is an example output of `color_dump` method, which is intended for the debugging purposes.
|
318
441
|
|
319
|
-
|
442
|
+
image::https://raw.githubusercontent.com/kigster/simple-feed/main/man/sf-color-dump.png[title=#color_dump method output, width=659, link=https://raw.githubusercontent.com/kigster/simple-feed/main/man/sf-color-dump.png]
|
320
443
|
|
321
444
|
+++<a name="api">++++++</a>+++
|
322
445
|
|
@@ -393,9 +516,7 @@ It is the intention of this gem that:
|
|
393
516
|
* it should be easy to write new providers
|
394
517
|
* it should be easy to swap out providers
|
395
518
|
|
396
|
-
|
397
|
-
|
398
|
-
Two providers are available with this gem:
|
519
|
+
One provider is included with this gem:
|
399
520
|
|
400
521
|
=== `SimpleFeed::Providers::Redis::Provider`
|
401
522
|
|
@@ -403,36 +524,43 @@ Redis Provider is a production-ready persistence adapter that uses the https://r
|
|
403
524
|
|
404
525
|
This provider is optimized for large writes and can use either a single Redis instance for all users of your application, or any number of Redis https://en.wikipedia.org/wiki/Shard_(database_architecture)[shards] by using a https://github.com/twitter/twemproxy[_Twemproxy_] in front of the Redis shards.
|
405
526
|
|
406
|
-
=== `SimpleFeed::Providers::HashProvider`
|
407
|
-
|
408
|
-
This is a pure Hash-like implementation of a provider that can be useful in unit tests of a host application. This provider could be used to write and read events within a single ruby process, can be serialized to and from a YAML file, and is therefore intended primarily for Feed emulations in automated tests.
|
409
|
-
|
410
|
-
== Redis Provider
|
411
|
-
|
412
527
|
If you set environment variable `REDIS_DEBUG` to `true` and run the example (see below) you will see every operation redis performs. This could be useful in debugging an issue or submitting a bug report.
|
413
528
|
|
414
|
-
== Running the Examples
|
529
|
+
== Running the Examples and Specs
|
415
530
|
|
416
531
|
Source code for the gem contains the `examples` folder with an example file that can be used to test out the providers, and see what they do under the hood.
|
417
532
|
|
533
|
+
Both the specs and the example requires a local redis instance to be available.
|
534
|
+
|
418
535
|
To run it, checkout the source of the library, and then:
|
419
536
|
|
420
|
-
[source,bash]
|
421
537
|
----
|
422
538
|
git clone https://github.com/kigster/simple-feed.git
|
423
539
|
cd simple-feed
|
424
|
-
|
425
|
-
|
540
|
+
|
541
|
+
# on OSX with HomeBrew:
|
542
|
+
brew install redis
|
543
|
+
brew services start redis
|
544
|
+
|
545
|
+
# check that your redis is up:
|
546
|
+
redis-cli info
|
547
|
+
|
548
|
+
# install bundler and other dependencies
|
549
|
+
gem install bundler --version 2.1.4
|
550
|
+
bundle install
|
551
|
+
bundle exec rspec # make sure tests are passing
|
552
|
+
|
553
|
+
# run the example:
|
426
554
|
ruby examples/redis_provider_example.rb
|
427
555
|
----
|
428
556
|
|
429
557
|
The above command will help you download, setup all dependencies, and run the examples for a single user:
|
430
558
|
|
431
|
-
image::https://raw.githubusercontent.com/kigster/simple-feed/
|
559
|
+
image::https://raw.githubusercontent.com/kigster/simple-feed/main/man/running-example.png[title=Running Redis Example in a Terminal, width=663, link=https://raw.githubusercontent.com/kigster/simple-feed/main/man/running-example.png]
|
432
560
|
|
433
561
|
If you set `REDIS_DEBUG` variable prior to running the example, you will be able to see every single Redis command executed as the example works its way through. Below is a sample output:
|
434
562
|
|
435
|
-
image::https://raw.githubusercontent.com/kigster/simple-feed/
|
563
|
+
image::https://raw.githubusercontent.com/kigster/simple-feed/main/man/running-example-redis-debug.png[title=Running Redis Example with REDIS_DEBUG set, width=918, link=https://raw.githubusercontent.com/kigster/simple-feed/main/man/running-example-redis-debug.png]
|
436
564
|
|
437
565
|
=== Generating Ruby API Documentation
|
438
566
|
|
@@ -474,6 +602,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/kigste
|
|
474
602
|
|
475
603
|
The gem is available as open source under the terms of the http://opensource.org/licenses/MIT[MIT License].
|
476
604
|
|
605
|
+
image:https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkigster%2Fsimple-feed.svg?type=large[FOSSA Scan Status, link=https://app.fossa.com/projects/git%2Bgithub.com%2Fkigster%2Fsimple-feed?ref=badge_large]
|
606
|
+
|
477
607
|
=== Acknowledgements
|
478
608
|
|
479
609
|
* This project is conceived and sponsored by https://simbi.com[Simbi, Inc.].
|