No commit activity in last 3 years
No release in over 3 years
Dalli::KeysMatch extends Dalli with a function that allow you to list or remove keys using optional filters
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
>= 12.1.0, ~> 12.1
~> 3.6

Runtime

>= 1.0.0
~> 0.1.1
 Project Readme

Dalli KeysMatch

This gem add to the Dalli::Client methods to list/filter/delete keys using regexp or string patterns.

Memcached binary protocol does not implement stats cachedump command. This package is using telnet as workaround. It may not be performatic in an environment with high data volume. So It's not recommend using it in production. Useful for debugging or in background jobs.

Installation

Add this line to your application's Gemfile:

gem 'dalli-keys-match'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dalli-keys-match

Usage

require 'dalli/keys_match'

> client = Dalli::Client.new('localhost:11211')
> client.set('dalli-keys-match-1' , 1)
> client.set('dalli-keys-match-2' , 2)
> client.keys(/dalli-keys-match-\d/)
 => ["dalli-keys-match-2", "dalli-keys-match-1"]
> client.keys('dalli-keys-match-')
 => ["dalli-keys-match-2", "dalli-keys-match-1"]
> client.delete_matched(/dalli-keys-match-1/)
 => 1
> client.keys(/dalli-keys-match-\d/)
 => ["dalli-keys-match-2"]

Gem also handles namespaces. Keys are normalized and filters are always optimized to only look into the namespace

> dc1 = Dalli::Client.new('localhost:11211')
> dc2 = Dalli::Client.new('localhost:11211', namespace: 'marcosgz')
> dc1.set('zimmermann', 'last-name')
> dc2.set('zimmermann', 'last-name')
> dc1.keys(/zimmermann/)
 => ["zimmermann", "marcosgz:zimmermann"]
> dc2.keys(/zimmermann/)
 => ["zimmermann"]
> dc2.keys_with_namespace(/zimmermann/)
 => ["marcosgz:zimmermann"]
> dc2.delete_matched(/^zimmermann/)
 => 1
> dc1.keys(/zimmermann/)
 => ["zimmermann"]

Optional Configuration

Dalli::KeysMatch.config.telnet(
  'Timeout' => 30,
  'Prompt' => /(^END$)/,
)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marcosgz/dalli-keys-match.