Sha256: 30c03e81b3960af703306893fad86b172e1e7c43fca83011bb238a2a5c2221be

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require "redic"

class Nest < String
  METHODS = [:append, :bitcount, :bitpos, :blpop, :brpop, :brpoplpush,
    :decr, :decrby, :del, :dump, :exists, :expire, :expireat, :get,
    :getbit, :getrange, :getset, :hdel, :hexists, :hget, :hgetall,
    :hincrby, :hincrbyfloat, :hkeys, :hlen, :hmget, :hmset, :hset,
    :hsetnx, :hstrlen, :hvals, :incr, :incrby, :incrbyfloat, :lindex,
    :linsert, :llen, :lpop, :lpush, :lpushx, :lrange, :lrem, :lset,
    :ltrim, :move, :persist, :pexpire, :pexpireat, :pfadd, :pfcount,
    :pfmerge, :psetex, :pttl, :publish, :rename, :renamenx, :restore,
    :rpop, :rpoplpush, :rpush, :rpushx, :sadd, :scard, :sdiff, :sdiffstore,
    :set, :setbit, :setex, :setnx, :setrange, :sinter, :sinterstore,
    :sismember, :smembers, :smove, :sort, :spop, :srandmember, :srem,
    :strlen, :subscribe, :sunion, :sunionstore, :ttl, :type, :unsubscribe,
    :watch, :zadd, :zcard, :zcount, :zincrby, :zinterstore, :zlexcount,
    :zrange, :zrangebylex, :zrevrangebylex, :zrangebyscore, :zrank,
    :zrem, :zremrangebylex, :zremrangebyrank, :zremrangebyscore,
    :zrevrange, :zrevrangebyscore, :zrevrank, :zscore, :zunionstore,
    :sscan, :hscan, :zscan]

  attr :redis

  def initialize(key, redis = Redic.new)
    super(key.to_s)
    @redis = redis
  end

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

  METHODS.each do |meth|
    define_method(meth) do |*args|
      redis.call(meth, self, *args)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nest-2.0.0 lib/nest.rb