Class: Redis
- Inherits:
-
Object
- Object
- Redis
- Includes:
- MonitorMixin
- Defined in:
- lib/redis.rb,
lib/redis/client.rb,
lib/redis/version.rb,
lib/redis/pipeline.rb,
lib/redis/hash_ring.rb,
lib/redis/subscribe.rb,
lib/redis/distributed.rb,
lib/redis/connection/ruby.rb,
lib/redis/connection/hiredis.rb,
lib/redis/connection/registry.rb,
lib/redis/connection/synchrony.rb,
lib/redis/connection/command_helper.rb
Defined Under Namespace
Modules: Connection, DisableThreadSafety Classes: Client, CommandOptions, Distributed, HashRing, Pipeline, ProtocolError, SubscribedClient, Subscription
Constant Summary
- VERSION =
"2.2.0"
Instance Attribute Summary (collapse)
-
- (Object) client
readonly
Returns the value of attribute client.
Class Method Summary (collapse)
- + (Object) connect(options = {})
- + (Object) current
- + (Object) current=(redis)
- + (Object) deprecate(message, trace = caller[0])
Instance Method Summary (collapse)
- - (Object) [](key)
- - (Object) []=(key, value)
-
- (Object) append(key, value)
Append a value to a key.
-
- (Object) auth(password)
Authenticate to the server.
-
- (Object) bgrewriteaof
Asynchronously rewrite the append-only file.
-
- (Object) bgsave
Asynchronously save the dataset to disk.
-
- (Object) blpop(*args)
Remove and get the first element in a list, or block until one is available.
-
- (Object) brpop(*args)
Remove and get the last element in a list, or block until one is available.
-
- (Object) brpoplpush(source, destination, timeout)
Pop a value from a list, push it to another list and return it; or block until one is available.
- - (Object) config(action, *args)
-
- (Object) dbsize
Return the number of keys in the selected database.
- - (Object) debug(*args)
-
- (Object) decr(key)
Decrement the integer value of a key by one.
-
- (Object) decrby(key, decrement)
Decrement the integer value of a key by the given number.
-
- (Object) del(*keys)
Delete a key.
-
- (Object) discard
Discard all commands issued after MULTI.
-
- (Object) echo(value)
Echo the given string.
-
- (Object) exec
Execute all commands issued after MULTI.
-
- (Object) exists(key)
Determine if a key exists.
-
- (Object) expire(key, seconds)
Set a key's time to live in seconds.
-
- (Object) expireat(key, unix_time)
Set the expiration for a key as a UNIX timestamp.
-
- (Object) flushall
Remove all keys from all databases.
-
- (Object) flushdb
Remove all keys from the current database.
-
- (Object) get(key)
Get the value of a key.
-
- (Object) getbit(key, offset)
Returns the bit value at offset in the string value stored at key.
-
- (Object) getrange(key, start, stop)
Get a substring of the string stored at a key.
-
- (Object) getset(key, value)
Set the string value of a key and return its old value.
-
- (Object) hdel(key, field)
Delete a hash field.
-
- (Object) hexists(key, field)
Determine if a hash field exists.
-
- (Object) hget(key, field)
Get the value of a hash field.
-
- (Object) hgetall(key)
Get all the fields and values in a hash.
-
- (Object) hincrby(key, field, increment)
Increment the integer value of a hash field by the given number.
-
- (Object) hkeys(key)
Get all the fields in a hash.
-
- (Object) hlen(key)
Get the number of fields in a hash.
-
- (Object) hmget(key, *fields)
Get the values of all the given hash fields.
-
- (Object) hmset(key, *attrs)
Set multiple hash fields to multiple values.
-
- (Object) hset(key, field, value)
Set the string value of a hash field.
-
- (Object) hsetnx(key, field, value)
Set the value of a hash field, only if the field does not exist.
-
- (Object) hvals(key)
Get all the values in a hash.
- - (Object) id
-
- (Object) incr(key)
Increment the integer value of a key by one.
-
- (Object) incrby(key, increment)
Increment the integer value of a key by the given number.
-
- (Object) info
Get information and statistics about the server.
-
- (Redis) initialize(options = {})
constructor
A new instance of Redis.
- - (Object) inspect
-
- (Object) keys(pattern = "*")
Find all keys matching the given pattern.
-
- (Object) lastsave
Get the UNIX time stamp of the last successful save to disk.
-
- (Object) lindex(key, index)
Get an element from a list by its index.
-
- (Object) linsert(key, where, pivot, value)
Insert an element before or after another element in a list.
-
- (Object) llen(key)
Get the length of a list.
-
- (Object) lpop(key)
Remove and get the first element in a list.
-
- (Object) lpush(key, value)
Prepend a value to a list.
-
- (Object) lpushx(key, value)
Prepend a value to a list, only if the list exists.
-
- (Object) lrange(key, start, stop)
Get a range of elements from a list.
-
- (Object) lrem(key, count, value)
Remove elements from a list.
-
- (Object) lset(key, index, value)
Set the value of an element in a list by its index.
-
- (Object) ltrim(key, start, stop)
Trim a list to the specified range.
- - (Object) mapped_hmget(key, *fields)
- - (Object) mapped_hmset(key, hash)
- - (Object) mapped_mget(*keys)
- - (Object) mapped_mset(hash)
- - (Object) mapped_msetnx(hash)
- - (Object) method_missing(command, *args)
-
- (Object) mget(*keys)
Get the values of all the given keys.
-
- (Object) monitor(&block)
Listen for all requests received by the server in real time.
-
- (Object) move(key, db)
Move a key to another database.
-
- (Object) mset(*args)
Set multiple keys to multiple values.
-
- (Object) msetnx(*args)
Set multiple keys to multiple values, only if none of the keys exist.
-
- (Object) multi
Mark the start of a transaction block.
-
- (Object) persist(key)
Remove the expiration from a key.
-
- (Object) ping
Ping the server.
- - (Object) pipelined(options = {})
-
- (Object) psubscribe(*channels, &block)
Listen for messages published to channels matching the given patterns.
-
- (Object) publish(channel, message)
Post a message to a channel.
-
- (Object) punsubscribe(*channels)
Stop listening for messages posted to channels matching the given patterns.
-
- (Object) quit
Close the connection.
-
- (Object) randomkey
Return a random key from the keyspace.
-
- (Object) rename(old_name, new_name)
Rename a key.
-
- (Object) renamenx(old_name, new_name)
Rename a key, only if the new key does not exist.
-
- (Object) rpop(key)
Remove and get the last element in a list.
-
- (Object) rpoplpush(source, destination)
Remove the last element in a list, append it to another list and return it.
-
- (Object) rpush(key, value)
Append a value to a list.
-
- (Object) rpushx(key, value)
Append a value to a list, only if the list exists.
-
- (Object) sadd(key, value)
Add a member to a set.
-
- (Object) save
Synchronously save the dataset to disk.
-
- (Object) scard(key)
Get the number of members in a set.
-
- (Object) sdiff(*keys)
Subtract multiple sets.
-
- (Object) sdiffstore(destination, *keys)
Subtract multiple sets and store the resulting set in a key.
-
- (Object) select(db)
Change the selected database for the current connection.
-
- (Object) set(key, value)
Set the string value of a key.
-
- (Object) setbit(key, offset, value)
Sets or clears the bit at offset in the string value stored at key.
-
- (Object) setex(key, ttl, value)
Set the value and expiration of a key.
-
- (Object) setnx(key, value)
Set the value of a key, only if the key does not exist.
-
- (Object) setrange(key, offset, value)
Overwrite part of a string at key starting at the specified offset.
-
- (Object) shutdown
Synchronously save the dataset to disk and then shut down the server.
-
- (Object) sinter(*keys)
Intersect multiple sets.
-
- (Object) sinterstore(destination, *keys)
Intersect multiple sets and store the resulting set in a key.
-
- (Object) sismember(key, member)
Determine if a given value is a member of a set.
-
- (Object) slaveof(host, port)
Make the server a slave of another instance, or promote it as master.
-
- (Object) smembers(key)
Get all the members in a set.
-
- (Object) smove(source, destination, member)
Move a member from one set to another.
-
- (Object) sort(key, options = {})
Sort the elements in a list, set or sorted set.
-
- (Object) spop(key)
Remove and return a random member from a set.
-
- (Object) srandmember(key)
Get a random member from a set.
-
- (Object) srem(key, value)
Remove a member from a set.
-
- (Object) strlen(key)
Get the length of the value stored in a key.
-
- (Object) subscribe(*channels, &block)
Listen for messages published to the given channels.
- - (Boolean) subscribed?
- - (Object) substr(key, start, stop)
-
- (Object) sunion(*keys)
Add multiple sets.
-
- (Object) sunionstore(destination, *keys)
Add multiple sets and store the resulting set in a key.
-
- (Object) sync
Internal command used for replication.
-
- (Object) ttl(key)
Get the time to live for a key.
-
- (Object) type(key)
Determine the type stored at key.
-
- (Object) unsubscribe(*channels)
Stop listening for messages posted to the given channels.
-
- (Object) unwatch
Forget about all watched keys.
-
- (Object) watch(*keys)
Watch the given keys to determine execution of the MULTI/EXEC block.
-
- (Object) without_reconnect(&block)
Run code without the client reconnecting.
-
- (Object) zadd(key, score, member)
Add a member to a sorted set, or update its score if it already exists.
-
- (Object) zcard(key)
Get the number of members in a sorted set.
-
- (Object) zcount(key, start, stop)
Count the members in a sorted set with scores within the given values.
-
- (Object) zincrby(key, increment, member)
Increment the score of a member in a sorted set.
-
- (Object) zinterstore(destination, keys, options = {})
Intersect multiple sorted sets and store the resulting sorted set in a new key.
-
- (Object) zrange(key, start, stop, options = {})
Return a range of members in a sorted set, by index.
-
- (Object) zrangebyscore(key, min, max, options = {})
Return a range of members in a sorted set, by score.
-
- (Object) zrank(key, member)
Determine the index of a member in a sorted set.
-
- (Object) zrem(key, member)
Remove a member from a sorted set.
-
- (Object) zremrangebyrank(key, start, stop)
Remove all members in a sorted set within the given indexes.
-
- (Object) zremrangebyscore(key, min, max)
Remove all members in a sorted set within the given scores.
-
- (Object) zrevrange(key, start, stop, options = {})
Return a range of members in a sorted set, by index, with scores ordered from high to low.
-
- (Object) zrevrangebyscore(key, max, min, options = {})
Return a range of members in a sorted set, by score, with scores ordered from high to low.
-
- (Object) zrevrank(key, member)
Determine the index of a member in a sorted set, with scores ordered from high to low.
-
- (Object) zscore(key, member)
Get the score associated with the given member in a sorted set.
-
- (Object) zunionstore(destination, keys, options = {})
Add multiple sorted sets and store the resulting sorted set in a new key.
Constructor Details
- (Redis) initialize(options = {})
A new instance of Redis
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/redis.rb', line 53 def initialize( = {}) @client = Client.new() if [:thread_safe] == false # Override #synchronize extend DisableThreadSafety else # Monitor#initialize super() end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(command, *args)
1066 1067 1068 1069 1070 |
# File 'lib/redis.rb', line 1066 def method_missing(command, *args) synchronize do @client.call(command, *args) end end |
Instance Attribute Details
- (Object) client (readonly)
Returns the value of attribute client
26 27 28 |
# File 'lib/redis.rb', line 26 def client @client end |
Class Method Details
+ (Object) connect(options = {})
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redis.rb', line 28 def self.connect( = {}) = .dup require "uri" url = URI(.delete(:url) || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0") [:host] ||= url.host [:port] ||= url.port [:password] ||= url.password [:db] ||= url.path[1..-1].to_i new() end |
+ (Object) current
43 44 45 |
# File 'lib/redis.rb', line 43 def self.current Thread.current[:redis] ||= Redis.connect end |
+ (Object) current=(redis)
47 48 49 |
# File 'lib/redis.rb', line 47 def self.current=(redis) Thread.current[:redis] = redis end |
+ (Object) deprecate(message, trace = caller[0])
22 23 24 |
# File 'lib/redis.rb', line 22 def self.deprecate(, trace = caller[0]) $stderr.puts "\n#{} (in #{trace})" end |
Instance Method Details
- (Object) [](key)
817 818 819 |
# File 'lib/redis.rb', line 817 def [](key) get(key) end |
- (Object) []=(key, value)
821 822 823 |
# File 'lib/redis.rb', line 821 def []=(key,value) set(key, value) end |
- (Object) append(key, value)
Append a value to a key.
183 184 185 186 187 |
# File 'lib/redis.rb', line 183 def append(key, value) synchronize do @client.call(:append, key, value) end end |
- (Object) auth(password)
Authenticate to the server.
73 74 75 76 77 |
# File 'lib/redis.rb', line 73 def auth(password) synchronize do @client.call(:auth, password) end end |
- (Object) bgrewriteaof
Asynchronously rewrite the append-only file.
141 142 143 144 145 |
# File 'lib/redis.rb', line 141 def bgrewriteaof synchronize do @client.call(:bgrewriteaof) end end |
- (Object) bgsave
Asynchronously save the dataset to disk.
134 135 136 137 138 |
# File 'lib/redis.rb', line 134 def bgsave synchronize do @client.call(:bgsave) end end |
- (Object) blpop(*args)
Remove and get the first element in a list, or block until one is available.
376 377 378 379 380 |
# File 'lib/redis.rb', line 376 def blpop(*args) synchronize do @client.call_without_timeout(:blpop, *args) end end |
- (Object) brpop(*args)
Remove and get the last element in a list, or block until one is available.
383 384 385 386 387 |
# File 'lib/redis.rb', line 383 def brpop(*args) synchronize do @client.call_without_timeout(:brpop, *args) end end |
- (Object) brpoplpush(source, destination, timeout)
Pop a value from a list, push it to another list and return it; or block until one is available.
391 392 393 394 395 |
# File 'lib/redis.rb', line 391 def brpoplpush(source, destination, timeout) synchronize do @client.call_without_timeout(:brpoplpush, source, destination, timeout) end end |
- (Object) config(action, *args)
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/redis.rb', line 100 def config(action, *args) synchronize do reply = @client.call(:config, action, *args) if reply.kind_of?(Array) && action == :get Hash[*reply] else reply end end end |
- (Object) dbsize
Return the number of keys in the selected database.
278 279 280 281 282 |
# File 'lib/redis.rb', line 278 def dbsize synchronize do @client.call(:dbsize) end end |
- (Object) debug(*args)
804 805 806 807 808 |
# File 'lib/redis.rb', line 804 def debug(*args) synchronize do @client.call(:debug, *args) end end |
- (Object) decr(key)
Decrement the integer value of a key by one.
915 916 917 918 919 |
# File 'lib/redis.rb', line 915 def decr(key) synchronize do @client.call(:decr, key) end end |
- (Object) decrby(key, decrement)
Decrement the integer value of a key by the given number.
922 923 924 925 926 |
# File 'lib/redis.rb', line 922 def decrby(key, decrement) synchronize do @client.call(:decrby, key, decrement) end end |
- (Object) del(*keys)
Delete a key.
672 673 674 675 676 |
# File 'lib/redis.rb', line 672 def del(*keys) synchronize do @client.call(:del, *keys) end end |
- (Object) discard
Discard all commands issued after MULTI.
784 785 786 787 788 |
# File 'lib/redis.rb', line 784 def discard synchronize do @client.call(:discard) end end |
- (Object) echo(value)
Echo the given string.
257 258 259 260 261 |
# File 'lib/redis.rb', line 257 def echo(value) synchronize do @client.call(:echo, value) end end |
- (Object) exec
Execute all commands issued after MULTI.
988 989 990 991 992 |
# File 'lib/redis.rb', line 988 def exec synchronize do @client.call(:exec) end end |
- (Object) exists(key)
Determine if a key exists.
285 286 287 288 289 |
# File 'lib/redis.rb', line 285 def exists(key) synchronize do _bool @client.call(:exists, key) end end |
- (Object) expire(key, seconds)
Set a key's time to live in seconds.
693 694 695 696 697 |
# File 'lib/redis.rb', line 693 def expire(key, seconds) synchronize do _bool @client.call(:expire, key, seconds) end end |
- (Object) expireat(key, unix_time)
Set the expiration for a key as a UNIX timestamp.
714 715 716 717 718 |
# File 'lib/redis.rb', line 714 def expireat(key, unix_time) synchronize do _bool @client.call(:expireat, key, unix_time) end end |
- (Object) flushall
Remove all keys from all databases.
120 121 122 123 124 |
# File 'lib/redis.rb', line 120 def flushall synchronize do @client.call(:flushall) end end |
- (Object) flushdb
Remove all keys from the current database.
113 114 115 116 117 |
# File 'lib/redis.rb', line 113 def flushdb synchronize do @client.call(:flushdb) end end |
- (Object) get(key)
Get the value of a key.
148 149 150 151 152 |
# File 'lib/redis.rb', line 148 def get(key) synchronize do @client.call(:get, key) end end |
- (Object) getbit(key, offset)
Returns the bit value at offset in the string value stored at key.
155 156 157 158 159 |
# File 'lib/redis.rb', line 155 def getbit(key, offset) synchronize do @client.call(:getbit, key, offset) end end |
- (Object) getrange(key, start, stop)
Get a substring of the string stored at a key.
162 163 164 165 166 |
# File 'lib/redis.rb', line 162 def getrange(key, start, stop) synchronize do @client.call(:getrange, key, start, stop) end end |
- (Object) getset(key, value)
Set the string value of a key and return its old value.
169 170 171 172 173 |
# File 'lib/redis.rb', line 169 def getset(key, value) synchronize do @client.call(:getset, key, value) end end |
- (Object) hdel(key, field)
Delete a hash field.
223 224 225 226 227 |
# File 'lib/redis.rb', line 223 def hdel(key, field) synchronize do @client.call(:hdel, key, field) end end |
- (Object) hexists(key, field)
Determine if a hash field exists.
791 792 793 794 795 |
# File 'lib/redis.rb', line 791 def hexists(key, field) synchronize do _bool @client.call(:hexists, key, field) end end |
- (Object) hget(key, field)
Get the value of a hash field.
216 217 218 219 220 |
# File 'lib/redis.rb', line 216 def hget(key, field) synchronize do @client.call(:hget, key, field) end end |
- (Object) hgetall(key)
Get all the fields and values in a hash.
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/redis.rb', line 203 def hgetall(key) synchronize do reply = @client.call(:hgetall, key) if reply.kind_of?(Array) Hash[*reply] else reply end end end |
- (Object) hincrby(key, field, increment)
Increment the integer value of a hash field by the given number.
777 778 779 780 781 |
# File 'lib/redis.rb', line 777 def hincrby(key, field, increment) synchronize do @client.call(:hincrby, key, field, increment) end end |
- (Object) hkeys(key)
Get all the fields in a hash.
230 231 232 233 234 |
# File 'lib/redis.rb', line 230 def hkeys(key) synchronize do @client.call(:hkeys, key) end end |
- (Object) hlen(key)
Get the number of fields in a hash.
763 764 765 766 767 |
# File 'lib/redis.rb', line 763 def hlen(key) synchronize do @client.call(:hlen, key) end end |
- (Object) hmget(key, *fields)
Get the values of all the given hash fields.
746 747 748 749 750 |
# File 'lib/redis.rb', line 746 def hmget(key, *fields) synchronize do @client.call(:hmget, key, *fields) end end |
- (Object) hmset(key, *attrs)
Set multiple hash fields to multiple values.
735 736 737 738 739 |
# File 'lib/redis.rb', line 735 def hmset(key, *attrs) synchronize do @client.call(:hmset, key, *attrs) end end |
- (Object) hset(key, field, value)
Set the string value of a hash field.
721 722 723 724 725 |
# File 'lib/redis.rb', line 721 def hset(key, field, value) synchronize do _bool @client.call(:hset, key, field, value) end end |
- (Object) hsetnx(key, field, value)
Set the value of a hash field, only if the field does not exist.
728 729 730 731 732 |
# File 'lib/redis.rb', line 728 def hsetnx(key, field, value) synchronize do _bool @client.call(:hsetnx, key, field, value) end end |
- (Object) hvals(key)
Get all the values in a hash.
770 771 772 773 774 |
# File 'lib/redis.rb', line 770 def hvals(key) synchronize do @client.call(:hvals, key) end end |
- (Object) id
1054 1055 1056 1057 1058 |
# File 'lib/redis.rb', line 1054 def id synchronize do @client.id end end |
- (Object) incr(key)
Increment the integer value of a key by one.
901 902 903 904 905 |
# File 'lib/redis.rb', line 901 def incr(key) synchronize do @client.call(:incr, key) end end |
- (Object) incrby(key, increment)
Increment the integer value of a key by the given number.
908 909 910 911 912 |
# File 'lib/redis.rb', line 908 def incrby(key, increment) synchronize do @client.call(:incrby, key, increment) end end |
- (Object) info
Get information and statistics about the server.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/redis.rb', line 88 def info synchronize do reply = @client.call(:info) if reply.kind_of?(String) Hash[*reply.split(/:|\r\n/).grep(/^[^#]/)] else reply end end end |
- (Object) inspect
1060 1061 1062 1063 1064 |
# File 'lib/redis.rb', line 1060 def inspect synchronize do "#<Redis client v#{Redis::VERSION} connected to #{id} (Redis v#{info["redis_version"]})>" end end |
- (Object) keys(pattern = "*")
Find all keys matching the given pattern.
237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/redis.rb', line 237 def keys(pattern = "*") synchronize do reply = @client.call(:keys, pattern) if reply.kind_of?(String) reply.split(" ") else reply end end end |
- (Object) lastsave
Get the UNIX time stamp of the last successful save to disk.
271 272 273 274 275 |
# File 'lib/redis.rb', line 271 def lastsave synchronize do @client.call(:lastsave) end end |
- (Object) lindex(key, index)
Get an element from a list by its index.
313 314 315 316 317 |
# File 'lib/redis.rb', line 313 def lindex(key, index) synchronize do @client.call(:lindex, key, index) end end |
- (Object) linsert(key, where, pivot, value)
Insert an element before or after another element in a list.
320 321 322 323 324 |
# File 'lib/redis.rb', line 320 def linsert(key, where, pivot, value) synchronize do @client.call(:linsert, key, where, pivot, value) end end |
- (Object) llen(key)
Get the length of a list.
292 293 294 295 296 |
# File 'lib/redis.rb', line 292 def llen(key) synchronize do @client.call(:llen, key) end end |
- (Object) lpop(key)
Remove and get the first element in a list.
405 406 407 408 409 |
# File 'lib/redis.rb', line 405 def lpop(key) synchronize do @client.call(:lpop, key) end end |
- (Object) lpush(key, value)
Prepend a value to a list.
355 356 357 358 359 |
# File 'lib/redis.rb', line 355 def lpush(key, value) synchronize do @client.call(:lpush, key, value) end end |
- (Object) lpushx(key, value)
Prepend a value to a list, only if the list exists.
362 363 364 365 366 |
# File 'lib/redis.rb', line 362 def lpushx(key, value) synchronize do @client.call(:lpushx, key, value) end end |
- (Object) lrange(key, start, stop)
Get a range of elements from a list.
299 300 301 302 303 |
# File 'lib/redis.rb', line 299 def lrange(key, start, stop) synchronize do @client.call(:lrange, key, start, stop) end end |
- (Object) lrem(key, count, value)
Remove elements from a list.
334 335 336 337 338 |
# File 'lib/redis.rb', line 334 def lrem(key, count, value) synchronize do @client.call(:lrem, key, count, value) end end |
- (Object) lset(key, index, value)
Set the value of an element in a list by its index.
327 328 329 330 331 |
# File 'lib/redis.rb', line 327 def lset(key, index, value) synchronize do @client.call(:lset, key, index, value) end end |
- (Object) ltrim(key, start, stop)
Trim a list to the specified range.
306 307 308 309 310 |
# File 'lib/redis.rb', line 306 def ltrim(key, start, stop) synchronize do @client.call(:ltrim, key, start, stop) end end |
- (Object) mapped_hmget(key, *fields)
752 753 754 755 756 757 758 759 760 |
# File 'lib/redis.rb', line 752 def mapped_hmget(key, *fields) reply = hmget(key, *fields) if reply.kind_of?(Array) Hash[*fields.zip(reply).flatten] else reply end end |
- (Object) mapped_hmset(key, hash)
741 742 743 |
# File 'lib/redis.rb', line 741 def mapped_hmset(key, hash) hmset(key, *hash.to_a.flatten) end |
- (Object) mapped_mget(*keys)
875 876 877 878 879 880 881 882 883 |
# File 'lib/redis.rb', line 875 def mapped_mget(*keys) reply = mget(*keys) if reply.kind_of?(Array) Hash[*keys.zip(reply).flatten] else reply end end |
- (Object) mapped_mset(hash)
860 861 862 |
# File 'lib/redis.rb', line 860 def mapped_mset(hash) mset(*hash.to_a.flatten) end |
- (Object) mapped_msetnx(hash)
871 872 873 |
# File 'lib/redis.rb', line 871 def mapped_msetnx(hash) msetnx(*hash.to_a.flatten) end |
- (Object) mget(*keys)
Get the values of all the given keys.
176 177 178 179 180 |
# File 'lib/redis.rb', line 176 def mget(*keys) synchronize do @client.call(:mget, *keys) end end |
- (Object) monitor(&block)
Listen for all requests received by the server in real time.
798 799 800 801 802 |
# File 'lib/redis.rb', line 798 def monitor(&block) synchronize do @client.call_loop(:monitor, &block) end end |
- (Object) move(key, db)
Move a key to another database.
658 659 660 661 662 |
# File 'lib/redis.rb', line 658 def move(key, db) synchronize do _bool @client.call(:move, key, db) end end |
- (Object) mset(*args)
Set multiple keys to multiple values.
854 855 856 857 858 |
# File 'lib/redis.rb', line 854 def mset(*args) synchronize do @client.call(:mset, *args) end end |
- (Object) msetnx(*args)
Set multiple keys to multiple values, only if none of the keys exist.
865 866 867 868 869 |
# File 'lib/redis.rb', line 865 def msetnx(*args) synchronize do @client.call(:msetnx, *args) end end |
- (Object) multi
Mark the start of a transaction block.
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/redis.rb', line 995 def multi synchronize do if !block_given? @client.call :multi else result = pipelined(:raise => false) do multi yield(self) exec end result.last end end end |
- (Object) persist(key)
Remove the expiration from a key.
700 701 702 703 704 |
# File 'lib/redis.rb', line 700 def persist(key) synchronize do _bool @client.call(:persist, key) end end |
- (Object) ping
Ping the server.
264 265 266 267 268 |
# File 'lib/redis.rb', line 264 def ping synchronize do @client.call(:ping) end end |
- (Object) pipelined(options = {})
961 962 963 964 965 966 967 968 969 970 971 |
# File 'lib/redis.rb', line 961 def pipelined( = {}) synchronize do begin original, @client = @client, Pipeline.new yield original.call_pipelined(@client.commands, ) unless @client.commands.empty? ensure @client = original end end end |
- (Object) psubscribe(*channels, &block)
Listen for messages published to channels matching the given patterns.
1048 1049 1050 1051 1052 |
# File 'lib/redis.rb', line 1048 def psubscribe(*channels, &block) synchronize do subscription(:psubscribe, channels, block) end end |
- (Object) publish(channel, message)
Post a message to a channel.
1012 1013 1014 1015 1016 |
# File 'lib/redis.rb', line 1012 def publish(channel, ) synchronize do @client.call(:publish, channel, ) end end |
- (Object) punsubscribe(*channels)
Stop listening for messages posted to channels matching the given patterns.
1033 1034 1035 1036 1037 1038 |
# File 'lib/redis.rb', line 1033 def punsubscribe(*channels) synchronize do raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed? @client.punsubscribe(*channels) end end |
- (Object) quit
Close the connection.
936 937 938 939 940 941 942 943 944 945 |
# File 'lib/redis.rb', line 936 def quit synchronize do begin @client.call(:quit) rescue Errno::ECONNRESET ensure @client.disconnect end end end |
- (Object) randomkey
Return a random key from the keyspace.
250 251 252 253 254 |
# File 'lib/redis.rb', line 250 def randomkey synchronize do @client.call(:randomkey) end end |
- (Object) rename(old_name, new_name)
Rename a key.
679 680 681 682 683 |
# File 'lib/redis.rb', line 679 def rename(old_name, new_name) synchronize do @client.call(:rename, old_name, new_name) end end |
- (Object) renamenx(old_name, new_name)
Rename a key, only if the new key does not exist.
686 687 688 689 690 |
# File 'lib/redis.rb', line 686 def renamenx(old_name, new_name) synchronize do _bool @client.call(:renamenx, old_name, new_name) end end |
- (Object) rpop(key)
Remove and get the last element in a list.
369 370 371 372 373 |
# File 'lib/redis.rb', line 369 def rpop(key) synchronize do @client.call(:rpop, key) end end |
- (Object) rpoplpush(source, destination)
Remove the last element in a list, append it to another list and return it.
398 399 400 401 402 |
# File 'lib/redis.rb', line 398 def rpoplpush(source, destination) synchronize do @client.call(:rpoplpush, source, destination) end end |
- (Object) rpush(key, value)
Append a value to a list.
341 342 343 344 345 |
# File 'lib/redis.rb', line 341 def rpush(key, value) synchronize do @client.call(:rpush, key, value) end end |
- (Object) rpushx(key, value)
Append a value to a list, only if the list exists.
348 349 350 351 352 |
# File 'lib/redis.rb', line 348 def rpushx(key, value) synchronize do @client.call(:rpushx, key, value) end end |
- (Object) sadd(key, value)
Add a member to a set.
426 427 428 429 430 |
# File 'lib/redis.rb', line 426 def sadd(key, value) synchronize do _bool @client.call(:sadd, key, value) end end |
- (Object) save
Synchronously save the dataset to disk.
127 128 129 130 131 |
# File 'lib/redis.rb', line 127 def save synchronize do @client.call(:save) end end |
- (Object) scard(key)
Get the number of members in a set.
454 455 456 457 458 |
# File 'lib/redis.rb', line 454 def scard(key) synchronize do @client.call(:scard, key) end end |
- (Object) sdiff(*keys)
Subtract multiple sets.
489 490 491 492 493 |
# File 'lib/redis.rb', line 489 def sdiff(*keys) synchronize do @client.call(:sdiff, *keys) end end |
- (Object) sdiffstore(destination, *keys)
Subtract multiple sets and store the resulting set in a key.
496 497 498 499 500 |
# File 'lib/redis.rb', line 496 def sdiffstore(destination, *keys) synchronize do @client.call(:sdiffstore, destination, *keys) end end |
- (Object) select(db)
Change the selected database for the current connection.
80 81 82 83 84 85 |
# File 'lib/redis.rb', line 80 def select(db) synchronize do @client.db = db @client.call(:select, db) end end |
- (Object) set(key, value)
Set the string value of a key.
826 827 828 829 830 |
# File 'lib/redis.rb', line 826 def set(key, value) synchronize do @client.call(:set, key, value) end end |
- (Object) setbit(key, offset, value)
Sets or clears the bit at offset in the string value stored at key.
833 834 835 836 837 |
# File 'lib/redis.rb', line 833 def setbit(key, offset, value) synchronize do @client.call(:setbit, key, offset, value) end end |
- (Object) setex(key, ttl, value)
Set the value and expiration of a key.
840 841 842 843 844 |
# File 'lib/redis.rb', line 840 def setex(key, ttl, value) synchronize do @client.call(:setex, key, ttl, value) end end |
- (Object) setnx(key, value)
Set the value of a key, only if the key does not exist.
665 666 667 668 669 |
# File 'lib/redis.rb', line 665 def setnx(key, value) synchronize do _bool @client.call(:setnx, key, value) end end |
- (Object) setrange(key, offset, value)
Overwrite part of a string at key starting at the specified offset.
847 848 849 850 851 |
# File 'lib/redis.rb', line 847 def setrange(key, offset, value) synchronize do @client.call(:setrange, key, offset, value) end end |
- (Object) shutdown
Synchronously save the dataset to disk and then shut down the server.
948 949 950 951 952 |
# File 'lib/redis.rb', line 948 def shutdown synchronize do @client.call(:shutdown) end end |
- (Object) sinter(*keys)
Intersect multiple sets.
461 462 463 464 465 |
# File 'lib/redis.rb', line 461 def sinter(*keys) synchronize do @client.call(:sinter, *keys) end end |
- (Object) sinterstore(destination, *keys)
Intersect multiple sets and store the resulting set in a key.
468 469 470 471 472 |
# File 'lib/redis.rb', line 468 def sinterstore(destination, *keys) synchronize do @client.call(:sinterstore, destination, *keys) end end |
- (Object) sismember(key, member)
Determine if a given value is a member of a set.
419 420 421 422 423 |
# File 'lib/redis.rb', line 419 def sismember(key, member) synchronize do _bool @client.call(:sismember, key, member) end end |
- (Object) slaveof(host, port)
Make the server a slave of another instance, or promote it as master.
955 956 957 958 959 |
# File 'lib/redis.rb', line 955 def slaveof(host, port) synchronize do @client.call(:slaveof, host, port) end end |
- (Object) smembers(key)
Get all the members in a set.
412 413 414 415 416 |
# File 'lib/redis.rb', line 412 def smembers(key) synchronize do @client.call(:smembers, key) end end |
- (Object) smove(source, destination, member)
Move a member from one set to another.
440 441 442 443 444 |
# File 'lib/redis.rb', line 440 def smove(source, destination, member) synchronize do _bool @client.call(:smove, source, destination, member) end end |
- (Object) sort(key, options = {})
Sort the elements in a list, set or sorted set.
886 887 888 889 890 891 892 893 894 895 896 897 898 |
# File 'lib/redis.rb', line 886 def sort(key, = {}) command = CommandOptions.new() do |c| c.value :by c.splat :limit c.multi :get c.words :order c.value :store end synchronize do @client.call(:sort, key, *command.to_a) end end |
- (Object) spop(key)
Remove and return a random member from a set.
447 448 449 450 451 |
# File 'lib/redis.rb', line 447 def spop(key) synchronize do @client.call(:spop, key) end end |
- (Object) srandmember(key)
Get a random member from a set.
503 504 505 506 507 |
# File 'lib/redis.rb', line 503 def srandmember(key) synchronize do @client.call(:srandmember, key) end end |
- (Object) srem(key, value)
Remove a member from a set.
433 434 435 436 437 |
# File 'lib/redis.rb', line 433 def srem(key, value) synchronize do _bool @client.call(:srem, key, value) end end |
- (Object) strlen(key)
Get the length of the value stored in a key.
196 197 198 199 200 |
# File 'lib/redis.rb', line 196 def strlen(key) synchronize do @client.call(:strlen, key) end end |
- (Object) subscribe(*channels, &block)
Listen for messages published to the given channels.
1041 1042 1043 1044 1045 |
# File 'lib/redis.rb', line 1041 def subscribe(*channels, &block) synchronize do subscription(:subscribe, channels, block) end end |
- (Boolean) subscribed?
1018 1019 1020 1021 1022 |
# File 'lib/redis.rb', line 1018 def subscribed? synchronize do @client.kind_of? SubscribedClient end end |
- (Object) substr(key, start, stop)
189 190 191 192 193 |
# File 'lib/redis.rb', line 189 def substr(key, start, stop) synchronize do @client.call(:substr, key, start, stop) end end |
- (Object) sunion(*keys)
Add multiple sets.
475 476 477 478 479 |
# File 'lib/redis.rb', line 475 def sunion(*keys) synchronize do @client.call(:sunion, *keys) end end |
- (Object) sunionstore(destination, *keys)
Add multiple sets and store the resulting set in a key.
482 483 484 485 486 |
# File 'lib/redis.rb', line 482 def sunionstore(destination, *keys) synchronize do @client.call(:sunionstore, destination, *keys) end end |
- (Object) sync
Internal command used for replication.
811 812 813 814 815 |
# File 'lib/redis.rb', line 811 def sync synchronize do @client.call(:sync) end end |
- (Object) ttl(key)
Get the time to live for a key.
707 708 709 710 711 |
# File 'lib/redis.rb', line 707 def ttl(key) synchronize do @client.call(:ttl, key) end end |
- (Object) type(key)
Determine the type stored at key.
929 930 931 932 933 |
# File 'lib/redis.rb', line 929 def type(key) synchronize do @client.call(:type, key) end end |
- (Object) unsubscribe(*channels)
Stop listening for messages posted to the given channels.
1025 1026 1027 1028 1029 1030 |
# File 'lib/redis.rb', line 1025 def unsubscribe(*channels) synchronize do raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed? @client.unsubscribe(*channels) end end |
- (Object) unwatch
Forget about all watched keys.
981 982 983 984 985 |
# File 'lib/redis.rb', line 981 def unwatch synchronize do @client.call(:unwatch) end end |
- (Object) watch(*keys)
Watch the given keys to determine execution of the MULTI/EXEC block.
974 975 976 977 978 |
# File 'lib/redis.rb', line 974 def watch(*keys) synchronize do @client.call(:watch, *keys) end end |
- (Object) without_reconnect(&block)
Run code without the client reconnecting
66 67 68 69 70 |
# File 'lib/redis.rb', line 66 def without_reconnect(&block) synchronize do @client.without_reconnect(&block) end end |
- (Object) zadd(key, score, member)
Add a member to a sorted set, or update its score if it already exists.
510 511 512 513 514 |
# File 'lib/redis.rb', line 510 def zadd(key, score, member) synchronize do _bool @client.call(:zadd, key, score, member) end end |
- (Object) zcard(key)
Get the number of members in a sorted set.
539 540 541 542 543 |
# File 'lib/redis.rb', line 539 def zcard(key) synchronize do @client.call(:zcard, key) end end |
- (Object) zcount(key, start, stop)
Count the members in a sorted set with scores within the given values.
571 572 573 574 575 |
# File 'lib/redis.rb', line 571 def zcount(key, start, stop) synchronize do @client.call(:zcount, key, start, stop) end end |
- (Object) zincrby(key, increment, member)
Increment the score of a member in a sorted set.
532 533 534 535 536 |
# File 'lib/redis.rb', line 532 def zincrby(key, increment, member) synchronize do @client.call(:zincrby, key, increment, member) end end |
- (Object) zinterstore(destination, keys, options = {})
Intersect multiple sorted sets and store the resulting sorted set in a new key.
634 635 636 637 638 639 640 641 642 643 |
# File 'lib/redis.rb', line 634 def zinterstore(destination, keys, = {}) command = CommandOptions.new() do |c| c.splat :weights c.value :aggregate end synchronize do @client.call(:zinterstore, destination, keys.size, *(keys + command.to_a)) end end |
- (Object) zrange(key, start, stop, options = {})
Return a range of members in a sorted set, by index.
546 547 548 549 550 551 552 553 554 555 |
# File 'lib/redis.rb', line 546 def zrange(key, start, stop, = {}) command = CommandOptions.new() do |c| c.bool :withscores c.bool :with_scores end synchronize do @client.call(:zrange, key, start, stop, *command.to_a) end end |
- (Object) zrangebyscore(key, min, max, options = {})
Return a range of members in a sorted set, by score.
558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/redis.rb', line 558 def zrangebyscore(key, min, max, = {}) command = CommandOptions.new() do |c| c.splat :limit c.bool :withscores c.bool :with_scores end synchronize do @client.call(:zrangebyscore, key, min, max, *command.to_a) end end |
- (Object) zrank(key, member)
Determine the index of a member in a sorted set.
517 518 519 520 521 |
# File 'lib/redis.rb', line 517 def zrank(key, member) synchronize do @client.call(:zrank, key, member) end end |
- (Object) zrem(key, member)
Remove a member from a sorted set.
626 627 628 629 630 |
# File 'lib/redis.rb', line 626 def zrem(key, member) synchronize do _bool @client.call(:zrem, key, member) end end |
- (Object) zremrangebyrank(key, start, stop)
Remove all members in a sorted set within the given indexes.
612 613 614 615 616 |
# File 'lib/redis.rb', line 612 def zremrangebyrank(key, start, stop) synchronize do @client.call(:zremrangebyrank, key, start, stop) end end |
- (Object) zremrangebyscore(key, min, max)
Remove all members in a sorted set within the given scores.
605 606 607 608 609 |
# File 'lib/redis.rb', line 605 def zremrangebyscore(key, min, max) synchronize do @client.call(:zremrangebyscore, key, min, max) end end |
- (Object) zrevrange(key, start, stop, options = {})
Return a range of members in a sorted set, by index, with scores ordered from high to low.
579 580 581 582 583 584 585 586 587 588 |
# File 'lib/redis.rb', line 579 def zrevrange(key, start, stop, = {}) command = CommandOptions.new() do |c| c.bool :withscores c.bool :with_scores end synchronize do @client.call(:zrevrange, key, start, stop, *command.to_a) end end |
- (Object) zrevrangebyscore(key, max, min, options = {})
Return a range of members in a sorted set, by score, with scores ordered from high to low.
592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/redis.rb', line 592 def zrevrangebyscore(key, max, min, = {}) command = CommandOptions.new() do |c| c.splat :limit c.bool :withscores c.bool :with_scores end synchronize do @client.call(:zrevrangebyscore, key, max, min, *command.to_a) end end |
- (Object) zrevrank(key, member)
Determine the index of a member in a sorted set, with scores ordered from high to low.
525 526 527 528 529 |
# File 'lib/redis.rb', line 525 def zrevrank(key, member) synchronize do @client.call(:zrevrank, key, member) end end |
- (Object) zscore(key, member)
Get the score associated with the given member in a sorted set.
619 620 621 622 623 |
# File 'lib/redis.rb', line 619 def zscore(key, member) synchronize do @client.call(:zscore, key, member) end end |
- (Object) zunionstore(destination, keys, options = {})
Add multiple sorted sets and store the resulting sorted set in a new key.
646 647 648 649 650 651 652 653 654 655 |
# File 'lib/redis.rb', line 646 def zunionstore(destination, keys, = {}) command = CommandOptions.new() do |c| c.splat :weights c.value :aggregate end synchronize do @client.call(:zunionstore, destination, keys.size, *(keys + command.to_a)) end end |