2019-08-14 09:48:44 +00:00
|
|
|
module Redis::Alfred
|
2020-07-07 18:44:07 +00:00
|
|
|
include Redis::RedisKeys
|
2020-07-04 06:12:47 +00:00
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
class << self
|
2020-07-07 18:44:07 +00:00
|
|
|
# key operations
|
|
|
|
|
|
|
|
def set(key, value)
|
|
|
|
$alfred.set(key, value)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
def setex(key, value, expiry = 1.day)
|
|
|
|
$alfred.setex(key, expiry, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key)
|
|
|
|
$alfred.get(key)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete(key)
|
|
|
|
$alfred.del(key)
|
|
|
|
end
|
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
# list operations
|
|
|
|
|
|
|
|
def llen(key)
|
|
|
|
$alfred.llen(key)
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
def lrange(key, start_index = 0, end_index = -1)
|
|
|
|
$alfred.lrange(key, start_index, end_index)
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
def rpop(key)
|
|
|
|
$alfred.rpop(key)
|
2020-07-04 06:12:47 +00:00
|
|
|
end
|
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
def lpush(key, values)
|
|
|
|
$alfred.lpush(key, values)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rpoplpush(source, destination)
|
|
|
|
$alfred.rpoplpush(source, destination)
|
|
|
|
end
|
|
|
|
|
|
|
|
def lrem(key, value, count = 0)
|
|
|
|
$alfred.lrem(key, count, value)
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|
2020-07-04 06:12:47 +00:00
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
# hash operations
|
2020-07-04 06:12:47 +00:00
|
|
|
|
|
|
|
# add a key value to redis hash
|
|
|
|
def hset(key, field, value)
|
|
|
|
$alfred.hset(key, field, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
# get value from redis hash
|
|
|
|
def hget(key, field)
|
|
|
|
$alfred.hget(key, field)
|
|
|
|
end
|
|
|
|
|
|
|
|
# get values of multiple keys from redis hash
|
|
|
|
def hmget(key, fields)
|
|
|
|
$alfred.hmget(key, *fields)
|
|
|
|
end
|
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
# sorted set operations
|
2020-07-04 06:12:47 +00:00
|
|
|
|
|
|
|
# add score and value for a key
|
|
|
|
def zadd(key, score, value)
|
|
|
|
$alfred.zadd(key, score, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
# get score of a value for key
|
|
|
|
def zscore(key, value)
|
|
|
|
$alfred.zscore(key, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
# get values by score
|
|
|
|
def zrangebyscore(key, range_start, range_end)
|
|
|
|
$alfred.zrangebyscore(key, range_start, range_end)
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|