class Redstruct::String
Manipulation of redis strings
Public Instance Methods
@param [String] value The value to compare with @return [Boolean] True if deleted, false otherwise
# File lib/redstruct/string.rb, line 30 def delete_if_equals(value) coerce_bool(delete_if_equals_script(keys: @key, argv: value)) end
@return [String, nil] the string value stored in the database
# File lib/redstruct/string.rb, line 12 def get return self.connection.get(@key) end
@param [#to_s] value The object to store @return [String] The old value before setting it
# File lib/redstruct/string.rb, line 36 def getset(value) self.connection.getset(@key, value) end
@return [Integer] The length of the string
# File lib/redstruct/string.rb, line 41 def length self.connection.strlen(@key) end
@param [#to_s] value the object to store @param [Integer] expiry the expiry time in seconds; if nil, will never expire @param [Boolean] nx Not Exists: if true, will not set the key if it already existed @param [Boolean] xx Already Exists: if true, will set the key only if it already existed @return [Boolean] true if set, false otherwise
# File lib/redstruct/string.rb, line 21 def set(value, expiry: nil, nx: false, xx: false) options = { nx: nx, xx: xx } options[:ex] = expiry.to_i unless expiry.nil? coerce_bool(self.connection.set(@key, value, options)) end
@param [Integer] start Starting index of the slice @param [Integer] length Length of the slice; negative numbers start counting from the right (-1 = end) @return [Array<String>] The requested slice from <start> with length <length>
# File lib/redstruct/string.rb, line 48 def slice(start = 0, length = -1) length = start + length if length >= 0 return self.connection.getrange(@key, start, length) end