Class: Async::Redis::Key

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/async/redis/key.rb

Overview

Represents a Redis key with utility methods for key manipulation.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Key

Initialize a new Key.



21
22
23
# File 'lib/async/redis/key.rb', line 21

def initialize(path)
	@path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



31
32
33
# File 'lib/async/redis/key.rb', line 31

def path
  @path
end

Class Method Details

.[](path) ⇒ Object

Create a new Key instance.



13
14
15
# File 'lib/async/redis/key.rb', line 13

def self.[] path
	self.new(path)
end

Instance Method Details

#<=>(other) ⇒ Object

Compare this key with another key.



55
56
57
# File 'lib/async/redis/key.rb', line 55

def <=> other
	@path <=> other.to_str
end

#[](key) ⇒ Object

Create a child key by appending a subkey.



48
49
50
# File 'lib/async/redis/key.rb', line 48

def [] key
	self.class.new("#{@path}:#{key}")
end

#sizeObject

Get the byte size of the key.



27
28
29
# File 'lib/async/redis/key.rb', line 27

def size
	@path.bytesize
end

#to_sObject

Convert the key to a string.



35
36
37
# File 'lib/async/redis/key.rb', line 35

def to_s
	@path
end

#to_strObject

Convert the key to a string (for String compatibility).



41
42
43
# File 'lib/async/redis/key.rb', line 41

def to_str
	@path
end