rails / kredis

Higher-level data structures built on Redis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

release sets negative slots

sampatbadhe opened this issue · comments

When all slots are released, negative slots are created, allowing you to reserve slots that are more than available. Is this to be expected, or should we restrict releasing slot once all slots have been released?

3.1.0 :001 > slots = Kredis.slots "myslots", available: 3
  Kredis  (2.0ms)  Connected to shared
 =>
#<Kredis::Types::Slots:0x0000000114b5eb58
...
3.1.0 :002 > slots.get
  Kredis Proxy (1.8ms)  GET myslots
 => nil
3.1.0 :003 > slots.available
 => 3
3.1.0 :004 > slots.reserve
  Kredis Proxy (0.5ms)  INCR myslots
 => true
3.1.0 :005 > slots.get
  Kredis Proxy (0.4ms)  GET myslots
 => "1"
3.1.0 :006 > slots.available
 => 3
3.1.0 :007 > slots.release
  Kredis Proxy (0.3ms)  DECR myslots
 => 0
3.1.0 :008 > slots.get
  Kredis Proxy (0.4ms)  GET myslots
 => "0"
3.1.0 :009 > slots.release
  Kredis Proxy (0.4ms)  DECR myslots
 => -1
3.1.0 :010 > slots.get
  Kredis Proxy (0.5ms)  GET myslots
 => "-1"
3.1.0 :011 > slots.available
 => 3
3.1.0 :012 > slots.release
  Kredis Proxy (0.5ms)  DECR myslots
 => -2
3.1.0 :013 > slots.available
 => 3
3.1.0 :014 > slots.reserve
  Kredis Proxy (0.4ms)  INCR myslots
 => true
3.1.0 :015 > slots.get
  Kredis Proxy (0.3ms)  GET myslots
 => "-1"

Would be nice to guard against releasing slots that haven't been reserved. Shouldn't be possible to go negative. Please do explore a PR 👍

@dhh I raised PR #71 to guard against releasing slots that haven't been reserved. Could you please review.