Sha256: 0b8aca101b7fd67a07249599d8c1b9a35569a71d18821c075e3b6fd9c22e5cff

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

require 'bundler/setup'
require 'redis-namespace'
require 'flipper/adapters/redis'

options = {url: 'redis://127.0.0.1:6379'}
if ENV['REDIS_URL']
  options[:url] = ENV['REDIS_URL']
end
client = Redis.new(options)
namespaced_client = Redis::Namespace.new(:flipper_namespace, redis: client)
adapter = Flipper::Adapters::Redis.new(namespaced_client)
flipper = Flipper.new(adapter)

# Register a few groups.
Flipper.register(:admins) { |thing| thing.admin? }
Flipper.register(:early_access) { |thing| thing.early_access? }

# Create a user class that has flipper_id instance method.
User = Struct.new(:flipper_id)

flipper[:stats].enable
flipper[:stats].enable_group :admins
flipper[:stats].enable_group :early_access
flipper[:stats].enable_actor User.new('25')
flipper[:stats].enable_actor User.new('90')
flipper[:stats].enable_actor User.new('180')
flipper[:stats].enable_percentage_of_time 15
flipper[:stats].enable_percentage_of_actors 45

flipper[:search].enable

print 'all keys: '
pp client.keys
# all keys: ["stats", "flipper_features", "search"]
puts

puts 'notice how all the keys are namespaced'

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
flipper-redis-0.27.1 examples/redis/namespaced.rb
flipper-redis-0.27.0 examples/redis/namespaced.rb
flipper-redis-0.26.2 examples/redis/namespaced.rb
flipper-redis-0.26.0 examples/redis/namespaced.rb
flipper-redis-0.26.0.rc2 examples/redis/namespaced.rb
flipper-redis-0.26.0.rc1 examples/redis/namespaced.rb
flipper-redis-0.25.4 examples/redis/namespaced.rb
flipper-redis-0.25.3 examples/redis/namespaced.rb
flipper-redis-0.25.2 examples/redis/namespaced.rb
flipper-redis-0.25.1 examples/redis/namespaced.rb
flipper-redis-0.25.0 examples/redis/namespaced.rb
flipper-redis-0.24.1 examples/redis/namespaced.rb
flipper-redis-0.24.0 examples/redis/namespaced.rb
flipper-redis-0.23.1 examples/redis/namespaced.rb
flipper-redis-0.23.0 examples/redis/namespaced.rb
flipper-redis-0.22.2 examples/redis/namespaced.rb
flipper-redis-0.22.1 examples/redis/namespaced.rb
flipper-redis-0.22.0 examples/redis/namespaced.rb
flipper-redis-0.21.0 examples/redis/namespaced.rb
flipper-redis-0.21.0.rc2 examples/redis/namespaced.rb