Class: PuavoRest::IdPool
- Inherits:
-
Object
- Object
- PuavoRest::IdPool
- Defined in:
- resources/id_pool.rb
Overview
Get unique and sequential IDs from Redis
Class Method Summary (collapse)
-
+ (Array<Fixnum>) id_range(namespace, count)
Get range of Ids.
-
+ (Object) last_id(namespace)
See what was the last given ID for the namespace.
-
+ (Object) next_id(namespace)
Get single id for ID the namespace.
-
+ (Object) set_id!(namespace, value)
Set ID sequence to value.
Class Method Details
+ (Array<Fixnum>) id_range(namespace, count)
Get range of Ids
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'resources/id_pool.rb', line 11 def self.id_range(namespace, count) pool = get_redis_id_pool() if pool.get(namespace).nil? pool.set(namespace, 5000) end _id_range = (1..count).map do pool.incr(namespace) end return _id_range end |
+ (Object) last_id(namespace)
See what was the last given ID for the namespace
29 30 31 |
# File 'resources/id_pool.rb', line 29 def self.last_id(namespace) get_redis_id_pool.get(namespace) end |
+ (Object) next_id(namespace)
Get single id for ID the namespace
37 38 39 |
# File 'resources/id_pool.rb', line 37 def self.next_id(namespace) id_range(namespace, 1).first end |
+ (Object) set_id!(namespace, value)
Set ID sequence to value. Using this can break things badly. Use with care!
45 46 47 48 |
# File 'resources/id_pool.rb', line 45 def self.set_id!(namespace, value) pool = get_redis_id_pool() pool.set(namespace, value) end |