Giter Site home page Giter Site logo

syft-application / redis-namespace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from resque/redis-namespace

0.0 0.0 0.0 301 KB

This gem adds a Redis::Namespace class which can be used to namespace Redis keys.

Home Page: http://redis.io

License: MIT License

Ruby 100.00%

redis-namespace's Introduction

redis-namespace

Redis::Namespace provides an interface to a namespaced subset of your redis keyspace (e.g., keys with a common beginning), and requires the redis-rb gem.

require 'redis-namespace'
# => true

redis_connection = Redis.new
# => #<Redis client v3.1.0 for redis://127.0.0.1:6379/0>
namespaced_redis = Redis::Namespace.new(:ns, redis: redis_connection)
# => #<Redis::Namespace v1.5.0 with client v3.1.0 for redis://127.0.0.1:6379/0/ns>

namespaced_redis.set('foo', 'bar') # redis_connection.set('ns:foo', 'bar')
# => "OK"

# Redis::Namespace automatically prepended our namespace to the key
# before sending it to our redis client.

namespaced_redis.get('foo')
# => "bar"
redis_connection.get('foo')
# => nil
redis_connection.get('ns:foo')
# => "bar"

namespaced_redis.del('foo')
# => 1
namespaced_redis.get('foo')
# => nil
redis_connection.get('ns:foo')
# => nil

Redis::Namespace also supports Proc as a namespace and will take the result string as namespace at runtime.

redis_connection = Redis.new
namespaced_redis = Redis::Namespace.new(Proc.new { Tenant.current_tenant }, redis: redis_connection)

Installation

Redis::Namespace is packaged as the redis-namespace gem, and hosted on rubygems.org.

From the command line:

$ gem install redis-namespace

Or in your Gemfile:

gem 'redis-namespace'

Caveats

Redis::Namespace provides a namespaced interface to Redis by keeping an internal registry of the method signatures in Redis provided by the redis-rb gem; we keep track of which arguments need the namespace added, and which return values need the namespace removed.

Blind Passthrough

If your version of this gem doesn't know about a particular command, it can't namespace it. Historically, this has meant that Redis::Namespace blindly passes unknown commands on to the underlying redis connection without modification which can lead to surprising effects.

As of v1.5.0, blind passthrough has been deprecated, and the functionality will be removed entirely in 2.0.

If you come across a command that is not yet supported, please open an issue on the issue tracker or submit a pull-request.

Administrative Commands

The effects of some redis commands cannot be limited to a particular namespace (e.g., FLUSHALL, which literally truncates all databases in your redis server, regardless of keyspace). Historically, this has meant that Redis::Namespace intentionally passes administrative commands on to the underlying redis connection without modification, which can lead to surprising effects.

As of v1.6.0, the direct use of administrative commands has been deprecated, and the functionality will be removed entirely in 2.0; while such commands are often useful for testing or administration, their meaning is inherently hidden when placed behind an interface that implies it will namespace everything.

The prefered way to send an administrative command is on the redis connection itself, which is publicly exposed as Redis::Namespace#redis:

namespaced.redis.flushall()
# => "OK"

2.x Planned Breaking Changes

As mentioned above, 2.0 will remove blind passthrough and the administrative command passthrough. By default in 1.5+, deprecation warnings are present and enabled; they can be silenced by initializing Redis::Namespace with warning: false or by setting the REDIS_NAMESPACE_QUIET environment variable.

Early opt-in

To enable testing against the 2.x interface before its release, in addition to deprecation warnings, early opt-in to these changes can be enabled by initializing Redis::Namespace with deprecations: true or by setting the REDIS_NAMESPACE_DEPRECATIONS environment variable. This should only be done once all warnings have been addressed.

Authors

While there are many authors who have contributed to this project, the following have done so on an ongoing basis with at least 5 commits:

  • Chris Wanstrath (@defunkt)
  • Ryan Biesemeyer (@yaauie)
  • Steve Klabnik (@steveklabnik)
  • Terence Lee (@hone)
  • Eoin Coffey (@ecoffey)

redis-namespace's People

Contributors

defunkt avatar yaauie avatar rafaelfranca avatar steveklabnik avatar hone avatar byroot avatar ota42y avatar neilchandler avatar fw42 avatar stefanmb avatar carlzulauf avatar larouxn avatar lukaszx0 avatar adammck avatar caius avatar fatkodima avatar sineed avatar filiptepper avatar gohanlon avatar mackuba avatar iloveitaly avatar anothermh avatar boz avatar avgerin0s avatar akshayrao14 avatar jbmeerkat avatar akahn avatar ixti avatar aliaksandrb avatar antti avatar

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.