Skip to content

Valkey client wrapper inspired by the redis-objects project.

License

Notifications You must be signed in to change notification settings

xorgnak/valkey-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

ValKey Objects

  • Standard gem install valkey-objects and bundle add valkey-objects installation.
  • Use require 'valkey/objects'.
  • Example:
class Example
  include VK

  timestamp :myTimestamp
  toggle :myToggle
  value :myValue
  counter :myCounter
  hashkey :myHashKey
  sortedset :mySortedSet
  set :mySet
  queue :myQueue
  place :myPlace
  ticker :myTicker
  entry :myEntry
  vector :myVector

  # Clear value on read
  value :myval, flush: true

  # Reset ttl in seconds on every read
  value :myVal, ttl: 60

  def initialize k
    # Must be available for VK module.
    @id = k
  end
  # include your work here...
end

@obj = Example.new("Object UUID")

## Deleting keys
@obj.myKey.expire seconds
@obj.myKey.delete!

@obj.myTimestamp.value! => set to utc epoch
@obj.myTimestamp.value => ...
@obj.myTimestamp.ago => seconds since
@obj.myTimestamp.to_time => Time object

@obj.myToggle.value = true or false
@obj.myToggle.value => ...
@obj.myToggle.value! => value = !value

@obj.myvalue.value = "A String"
@obj.myValue.value => "A string"
@obj.myValue.match(/Regexp/) { |match| ... }

@obj.myCounter.value = number
@obj.myCounter.value => number
@obj.incr number
@obj.decr number

@obj.myHashKey[:stringKey] = "Another String"
@obj.myHashKey[:numberKey] = 1.23
@obj.myHashKey[:key] => value
@obj.myHashKey.to_h

@obj.mySortedSet.poke key, number
@obj.mySotredSet[key] => score
@obj.mySortedSet.value { |key, index| ... }

@obj.mySet << "obj"
@obj.mySet['ob*'] => ["obj", ...]
@obj.mySet.rm "obj"
@obj.mySet.include? "obj"
@obj.mySet & @obj.otherSet
@obj.mySet | @obj.otherSet
@obj.mySet.value { |key, index| ... }

@obj.myQueue << "obj"
@obj.myQueue.length => 1
@obj.myQueue.front => "obj" && pop
@obj.myQueue.value { |key, index| ... }

@obj.myPlace "My Place", longitude, latitude
@obj.myPlace["My Place"] => { longitude: X, latitude: Y }
@obj.myPlace.distance "My Place", "Other Place"
@obj.myPlace.radius longitude, latitude, distance
@obj.myPlace.value { |key, index| ... }

@obj.myTicker["my key"] => "value"
@obj.myTicker["my key"] = "value"
@obj.myTicker.value
@obj.myTicker.value { |index, h={ score: key changes, key: key, value: value }| ... }

@obj.myEntry["my key"] => "value"
@obj.myEntry.push({ key: "value"})
@obj.myEntry.value
@obj.myEntry.value { |index, h={}| ... }

@obj.myTicker["my key"] => "value"
@obj.myTicker["my key"] = "value"
@obj.myVector.nearest("...String to match against...") => [{ distance between element }]
@obj.myVector.value { |index, e| ... }

About

Valkey client wrapper inspired by the redis-objects project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published