Class: Async::Redis::Client

Inherits:
Object
  • Object
show all
Includes:
Methods::Keys, Methods::Lists, Methods::Server, Methods::Strings
Defined in:
lib/async/redis/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Methods::Server

#info

Methods included from Methods::Lists

#blpop, #brpop, #brpoplpush, #lindex, #linsert, #llen, #lpop, #lpush, #lpushx, #lrange, #lrem, #lset, #ltrim, #rpop, #rpoplpush, #rpush, #rpushx

Methods included from Methods::Keys

#del, #dump, #exists, #expire, #expireat, #keys, #migrate, #move, #object, #persist, #pexpire, #pexpireat, #pttl, #randomkey, #rename, #renamenx, #restore, #scan, #sort, #touch, #ttl, #type, #unlink, #wait

Methods included from Methods::Strings

#append, #bitcount, #decr, #decrby, #get, #getbit, #getrange, #getset, #incr, #incrby, #incrbyfloat, #mget, #mset, #msetnx, #psetex, #set, #setbit, #setex, #setnx, #setrange, #strlen

Constructor Details

#initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options) ⇒ Client

Returns a new instance of Client.



45
46
47
48
49
50
# File 'lib/async/redis/client.rb', line 45

def initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options)
	@endpoint = endpoint
	@protocol = protocol
	
	@pool = connect(**options)
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



52
53
54
# File 'lib/async/redis/client.rb', line 52

def endpoint
  @endpoint
end

#protocolObject (readonly)

Returns the value of attribute protocol.



53
54
55
# File 'lib/async/redis/client.rb', line 53

def protocol
  @protocol
end

Class Method Details

.open(*args, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/async/redis/client.rb', line 55

def self.open(*args, &block)
	client = self.new(*args)
	
	return client unless block_given?
	
	begin
		yield client
	ensure
		client.close
	end
end

Instance Method Details

#call(*arguments) ⇒ Object



99
100
101
102
103
104
# File 'lib/async/redis/client.rb', line 99

def call(*arguments)
	@pool.acquire do |connection|
		connection.write_request(arguments)
		return connection.read_response
	end
end

#closeObject



67
68
69
# File 'lib/async/redis/client.rb', line 67

def close
	@pool.close
end

#multi(&block) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/async/redis/client.rb', line 87

def multi(&block)
	context = Context::Multi.new(@pool)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end

#publish(channel, message) ⇒ Object



71
72
73
# File 'lib/async/redis/client.rb', line 71

def publish(channel, message)
	call('PUBLISH', channel, message)
end

#subscribe(*channels) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/async/redis/client.rb', line 75

def subscribe(*channels)
	context = Context::Subscribe.new(@pool, channels)
	
	return context unless block_given?
	
	begin
		yield context
	ensure
		context.close
	end
end