Giter Club home page Giter Club logo

brpoplpush-redis_script's Introduction

brpoplpush-redis_script

Bring your own LUA scripts into redis

RSpec Status Maintainability Test Coverage Gem Version

Installation

Add this line to your application's Gemfile:

gem 'brpoplpush-redis_script'

And then execute:

bundle

Or install it yourself as:

gem install brpoplpush-redis_script

Usage

If you want to avoid global state in your project/gem the recommended way to use RedisScript is the following way.

Include the DSL module from the gem and configure with a path. We don't believe it is a good idea to put all your lua files in a single directory. We rather believe that these scripts should be placed and organized by feature.

Let's take sidekiq-unique-jobs for example. It uses brpoplpush-redis_script like follows:

# lib/my_redis_scripts.rb
require "brpoplpush/redis_script"

module SidekiqUniqueJobs::Scripts
  include Brpoplpush::RedisScript::DSL

  configure do |config|
    config.scripts_path = Rails.root.join("app", "lua")
  end
end

SidekiqUniqueJobs::Scripts.execute(:lock, Redis.new, keys: ["key1", "key2"] argv: ["bogus"])
# => 1

SidekiqUniqueJobs::Scripts.execute(:lock, Redis.new, keys: ["key1", "key1"] argv: ["bogus"])
# => -1
-- app/lua/lock.lua

local key_one = KEYS[1]
local key_two = KEYS[2]

local locked_val = ARGV[1]

if not key_one == key_two then
  redis.call("SET", key_two, )
  return 1
end

return -1

This is a very simplified version of course.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bropoplpush/brpoplpush-redis_script. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Brpoplpush::RedisScript project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

brpoplpush-redis_script's People

Contributors

dougedey avatar jpcamara avatar mberlanda avatar mhenrixon avatar norydev avatar wolfer avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

brpoplpush-redis_script's Issues

Improve gem configuration

Like you suggested in #1 we should allow various paths and scripts to be added to the gem. Right now it just takes a dumb directory because that is what I need to be able to use it in sidekiq-unique-jobs.

redis-namespace asks to use admistrative commands directly

When Sidekiq configured use redis namespaces like this

opts = {
  host:      APP_CONFIG[:redis_host].to_s,
  namespace: REDIS_NAMESPACE
}

Sidekiq.configure_server do |config|
  config.redis = opts
end

Sidekiq.configure_client do |config|
  config.redis = opts
end

Deprecated text appears at startup

Passing 'script' command to redis as is; administrative commands cannot be effectively namespaced and should be called on the redis connection directly; passthrough has been deprecated and will be removed in redis-namespace 2.0 (at /usr/local/rvm/gems/ruby-2.6.3/gems/brpoplpush-redis_script-0.1.1/lib/brpoplpush/redis_script/script.rb:69:in `load')
Passing 'script' command to redis as is; administrative commands cannot be effectively namespaced and should be called on the redis connection directly; passthrough has been deprecated and will be removed in redis-namespace 2.0 (at /usr/local/rvm/gems/ruby-2.6.3/gems/brpoplpush-redis_script-0.1.1/lib/brpoplpush/redis_script/script.rb:69:in `load')

Add CodeClimate

I experimented a little with it but couldn't find a way to add the project. It seems impossible for some reason.

Cannot upgrade Redis to 5.0.1

Recently I updated my bundle which resulted in updating redis to "5.0.0". As you may know this version does not work with Sidekiq < 7. There is a fix for it in redis 5.0.1 but this is against dependencies constraints for this gem. Is there a purpose for it or it can be easily updated? :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.