Launch small (evented) TCP JSON services on a given host:port
Add this line to your application's Gemfile:
gem 'tecepe'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tecepe
Worker.listen("localhost", 5555) do
on 'perms' do |payload|
redis.smember("permissions:#{payload['user_id']}", payload['product_id']) do |r|
reply allowed: r
end
end
end
In reality you would do some more computation than just proxying Redis!
You can use UDP as your daemon's transport (instead of TCP). This is useful for non-blocking, fire-and-forget requests such as stats collectors or logging.
Worker.udp("localhost", 5555) do
on 'track' do |payload|
redis.incrby payload['tracking_name'], 1
end
end
This is simple enough that it should be easy to write clients in different langs/stacks. See lib/tecepe/blocking_client.rb for a reference implementation of a TCP client with retry-on-disconnection.
PEMISSIONS_SERVICE = Tecepe::BlockingClient.new('localhost', 5555)
PEMISSIONS_SERVICE.call 'perms', user_id: current_user.id, @product.id # true/false
UDP clients in Ruby are as easy as
require 'socket'
client = UDPSocket.new
client.send JSON.generate(payload), 0, host, port
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request