Class: Redis
- Inherits:
-
Object
- Object
- Redis
- Includes:
- Commands
- Defined in:
- lib/redis.rb,
lib/redis/client.rb,
lib/redis/errors.rb,
lib/redis/version.rb,
lib/redis/commands.rb,
lib/redis/pipeline.rb,
lib/redis/hash_ring.rb,
lib/redis/subscribe.rb,
lib/redis/distributed.rb,
lib/redis/commands/geo.rb,
lib/redis/commands/keys.rb,
lib/redis/commands/sets.rb,
lib/redis/commands/lists.rb,
lib/redis/commands/hashes.rb,
lib/redis/commands/pubsub.rb,
lib/redis/commands/server.rb,
lib/redis/commands/bitmaps.rb,
lib/redis/commands/cluster.rb,
lib/redis/commands/streams.rb,
lib/redis/commands/strings.rb,
lib/redis/commands/scripting.rb,
lib/redis/commands/connection.rb,
lib/redis/commands/sorted_sets.rb,
lib/redis/commands/transactions.rb,
lib/redis/commands/hyper_log_log.rb
Defined Under Namespace
Modules: Commands, Connection Classes: BaseConnectionError, BaseError, CannotConnectError, Client, CommandError, ConnectionError, Distributed, Future, FutureNotReady, HashRing, InheritedError, InvalidClientOptionError, MultiConnection, MultiFuture, OutOfMemoryError, PermissionError, PipelinedConnection, ProtocolError, ReadOnlyError, SubscribedClient, Subscription, SubscriptionError, TimeoutError, WrongTypeError
Constant Summary collapse
- BASE_PATH =
__dir__
- Deprecated =
Class.new(StandardError)
- SERVER_URL_OPTIONS =
%i(url host port path).freeze
- VERSION =
'5.2.0'
Constants included from Commands
Commands::Boolify, Commands::BoolifySet, Commands::Floatify, Commands::FloatifyPairs, Commands::Hashify, Commands::HashifyClusterNodeInfo, Commands::HashifyClusterNodes, Commands::HashifyClusterSlaves, Commands::HashifyClusterSlots, Commands::HashifyInfo, Commands::HashifyStreamAutoclaim, Commands::HashifyStreamAutoclaimJustId, Commands::HashifyStreamEntries, Commands::HashifyStreamPendingDetails, Commands::HashifyStreamPendings, Commands::HashifyStreams, Commands::Noop, Commands::Pairify
Class Attribute Summary collapse
-
.raise_deprecations ⇒ Object
Returns the value of attribute raise_deprecations.
-
.silence_deprecations ⇒ Object
Returns the value of attribute silence_deprecations.
Class Method Summary collapse
Instance Method Summary collapse
- #_client ⇒ Object
-
#close ⇒ Object
(also: #disconnect!)
Disconnect the client as quickly and silently as possible.
-
#connected? ⇒ Boolean
Test whether or not the client is connected.
- #connection ⇒ Object
- #dup ⇒ Object
- #id ⇒ Object
-
#initialize(options = {}) ⇒ Redis
constructor
Create a new client instance.
- #inspect ⇒ Object
- #pipelined(exception: true) ⇒ Object
- #with {|_self| ... } ⇒ Object
-
#without_reconnect(&block) ⇒ Object
Run code without the client reconnecting.
Methods included from Commands
Methods included from Commands::Transactions
#discard, #exec, #multi, #unwatch, #watch
Methods included from Commands::Strings
#append, #decr, #decrby, #get, #getdel, #getex, #getrange, #getset, #incr, #incrby, #incrbyfloat, #mapped_mget, #mapped_mset, #mapped_msetnx, #mget, #mset, #msetnx, #psetex, #set, #setex, #setnx, #setrange, #strlen
Methods included from Commands::Streams
#xack, #xadd, #xautoclaim, #xclaim, #xdel, #xgroup, #xinfo, #xlen, #xpending, #xrange, #xread, #xreadgroup, #xrevrange, #xtrim
Methods included from Commands::SortedSets
#bzmpop, #bzpopmax, #bzpopmin, #zadd, #zcard, #zcount, #zdiff, #zdiffstore, #zincrby, #zinter, #zinterstore, #zlexcount, #zmpop, #zmscore, #zpopmax, #zpopmin, #zrandmember, #zrange, #zrangebylex, #zrangebyscore, #zrangestore, #zrank, #zrem, #zremrangebyrank, #zremrangebyscore, #zrevrange, #zrevrangebylex, #zrevrangebyscore, #zrevrank, #zscan, #zscan_each, #zscore, #zunion, #zunionstore
Methods included from Commands::Sets
#sadd, #sadd?, #scard, #sdiff, #sdiffstore, #sinter, #sinterstore, #sismember, #smembers, #smismember, #smove, #spop, #srandmember, #srem, #srem?, #sscan, #sscan_each, #sunion, #sunionstore
Methods included from Commands::Server
#bgrewriteaof, #bgsave, #client, #config, #dbsize, #debug, #flushall, #flushdb, #info, #lastsave, #monitor, #save, #shutdown, #slaveof, #slowlog, #sync, #time
Methods included from Commands::Scripting
Methods included from Commands::Pubsub
#psubscribe, #psubscribe_with_timeout, #publish, #pubsub, #punsubscribe, #spublish, #ssubscribe, #ssubscribe_with_timeout, #subscribe, #subscribe_with_timeout, #subscribed?, #sunsubscribe, #unsubscribe
Methods included from Commands::Lists
#blmove, #blmpop, #blpop, #brpop, #brpoplpush, #lindex, #linsert, #llen, #lmove, #lmpop, #lpop, #lpush, #lpushx, #lrange, #lrem, #lset, #ltrim, #rpop, #rpoplpush, #rpush, #rpushx
Methods included from Commands::Keys
#copy, #del, #dump, #exists, #exists?, #expire, #expireat, #expiretime, #keys, #migrate, #move, #object, #persist, #pexpire, #pexpireat, #pexpiretime, #pttl, #randomkey, #rename, #renamenx, #restore, #scan, #scan_each, #sort, #ttl, #type, #unlink
Methods included from Commands::HyperLogLog
Methods included from Commands::Hashes
#hdel, #hexists, #hget, #hgetall, #hincrby, #hincrbyfloat, #hkeys, #hlen, #hmget, #hmset, #hrandfield, #hscan, #hscan_each, #hset, #hsetnx, #hvals, #mapped_hmget, #mapped_hmset
Methods included from Commands::Geo
#geoadd, #geodist, #geohash, #geopos, #georadius, #georadiusbymember
Methods included from Connection
Methods included from Commands::Cluster
Methods included from Commands::Bitmaps
#bitcount, #bitop, #bitpos, #getbit, #setbit
Constructor Details
#initialize(options = {}) ⇒ Redis
Create a new client instance
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/redis.rb', line 63 def initialize( = {}) @monitor = Monitor.new @options = .dup @options[:reconnect_attempts] = 1 unless @options.key?(:reconnect_attempts) if ENV["REDIS_URL"] && SERVER_URL_OPTIONS.none? { |o| @options.key?(o) } @options[:url] = ENV["REDIS_URL"] end inherit_socket = @options.delete(:inherit_socket) @subscription_client = nil @client = initialize_client(@options) @client.inherit_socket! if inherit_socket end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Redis::Commands
Class Attribute Details
.raise_deprecations ⇒ Object
Returns the value of attribute raise_deprecations.
12 13 14 |
# File 'lib/redis.rb', line 12 def raise_deprecations @raise_deprecations end |
.silence_deprecations ⇒ Object
Returns the value of attribute silence_deprecations.
12 13 14 |
# File 'lib/redis.rb', line 12 def silence_deprecations @silence_deprecations end |
Class Method Details
.deprecate!(message) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/redis.rb', line 14 def deprecate!() unless silence_deprecations if raise_deprecations raise Deprecated, else ::Kernel.warn() end end end |
Instance Method Details
#_client ⇒ Object
98 99 100 |
# File 'lib/redis.rb', line 98 def _client @client end |
#close ⇒ Object Also known as: disconnect!
Disconnect the client as quickly and silently as possible.
88 89 90 91 |
# File 'lib/redis.rb', line 88 def close @client.close @subscription_client&.close end |
#connected? ⇒ Boolean
Test whether or not the client is connected
83 84 85 |
# File 'lib/redis.rb', line 83 def connected? @client.connected? || @subscription_client&.connected? end |
#connection ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/redis.rb', line 122 def connection { host: @client.host, port: @client.port, db: @client.db, id: id, location: "#{@client.host}:#{@client.port}" } end |
#dup ⇒ Object
118 119 120 |
# File 'lib/redis.rb', line 118 def dup self.class.new(@options) end |
#id ⇒ Object
110 111 112 |
# File 'lib/redis.rb', line 110 def id @client.id || @client.server_url end |
#inspect ⇒ Object
114 115 116 |
# File 'lib/redis.rb', line 114 def inspect "#<Redis client v#{Redis::VERSION} for #{id}>" end |
#pipelined(exception: true) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/redis.rb', line 102 def pipelined(exception: true) synchronize do |client| client.pipelined(exception: exception) do |raw_pipeline| yield PipelinedConnection.new(raw_pipeline, exception: exception) end end end |
#with {|_self| ... } ⇒ Object
94 95 96 |
# File 'lib/redis.rb', line 94 def with yield self end |
#without_reconnect(&block) ⇒ Object
Run code without the client reconnecting
78 79 80 |
# File 'lib/redis.rb', line 78 def without_reconnect(&block) @client.disable_reconnection(&block) end |