🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

redis-client-extensions

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-client-extensions

0.0.2
Rubygems
Version published
Maintainers
1
Created
Source

RedisClientExtensions

A set of useful core extensions to the redis-rb client library, extracted from KnowMyRankings.

Installation

Add this line to your application's Gemfile:

gem 'redis-client-extensions'

And then execute:

$ bundle

Or install it yourself as:

$ gem install redis-client-extensions

The extensions will add themselves to the Redis client automatically - in our Rails app, we have an initializer that looks something like

require 'redis-client-extensions'

$redis = Redis.new(...)

The extensions also work with MockRedis out of the box if it is installed.

Note that the library is coded against Ruby 2.1+.

Usage

Currently added functions are:

  • hmultiset(hkey, hash) - convenience method for storing a Ruby hash into a redis hash
$redis.hmultiset("my-hash", { name: "tom", color: "red" })
$redis.hget("my-hash", "name") # => "tom"
$redis.hget("my-hash", "color") # => "red"
  • find_keys_in_batches(options) - A wrapper for SCAN to iterate over keys matching a pattern. Options are passed through to SCAN.
$redis.find_keys_in_batches(match: "mypattern*", count: 100) do |keys|
  puts "Got batch of #{keys.count} keys"
  puts "Values for this batch: #{$redis.mget(keys)}"
end
  • get_i(key) - Parse an Integer stored at a key
$redis.get_i('price') # => 9
  • cache_fetch(key, expires_in:, &block) - Get or set a value (to be stored with Marshal) expiring in some number of seconds
# Initial cache miss, block evaluated to store value
ret = $redis.cache_fetch('my-key', expires_in: 60) do
  'cached-value'
end
# => 'cached-value'
#
# Calling again retrieves cached value, block will not be called
ret = $redis.cache_fetch('my-key', expires_in: 60) do
  'something-else' # Not called!
end
# => 'cached-value'
  • mdump(key, val) - Serialize and store a value at key using Marshal
$redis.mdump('my-key', [1,2,3]) # => 'OK'
  • mload(key) - Retrieve a Marshalled value from key
$redis.mdump('my-key', [1,2,3])
$redis.mload('my-key') # => [1,2,3]
$redis.mload('does-not-exist') # => nil

Contributing

  • Fork it ( http://github.com//redis-client-extensions/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

FAQs

Package last updated on 03 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts