ffi-hiredis_vip 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab0b43e5fa778ab53945a79ccb56a3680a845aca
4
+ data.tar.gz: 13ed771c3c8b05b3d0686318c0bd58178db315a3
5
+ SHA512:
6
+ metadata.gz: 852d415b1fbee1e6300c10aecd57ef7f04ea45e7e5a03fa70250e96f2372072d9c1cd2dda8e0d19393b7f61316f13974ede5838d9a727c116bf2ef3376e8ea16
7
+ data.tar.gz: d9868b4248f0f8f1c8e7b6b18d54ae875855a2f3640dfd3d00cecf423f11ee54b759c4d03927b7a02ee85a18795c5785d2e36758f12aff47336c14d2dd424f55
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .ruby-*
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ffi-hiredis_vip.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Ffi::HiredisVip
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ffi/hiredis_vip`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ffi-hiredis_vip'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ffi-hiredis_vip
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ffi-hiredis_vip.
36
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:spec) do |t|
5
+ t.libs << "spec"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ffi/hiredis_vip"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ffi/hiredis_vip/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ffi-hiredis_vip"
8
+ spec.version = FFI::HiredisVip::VERSION
9
+ spec.authors = ["Brandon Dewitt"]
10
+ spec.email = ["brandonsdewitt@gmail.com"]
11
+
12
+ spec.summary = %q{ FFI Wrapper around hiredis-vip for Hiredis and cluster support }
13
+ spec.description = %q{ FFI Wrapper for hiredis-vip }
14
+ #spec.homepage = "url"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency "ffi"
33
+ spec.add_runtime_dependency "ffi-hiredis_vip-core", ">= 0.1.0.pre4"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.13"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ spec.add_development_dependency "mocha"
39
+ spec.add_development_dependency "pry"
40
+ end
@@ -0,0 +1,6 @@
1
+ require "ffi/hiredis_vip/version"
2
+ require 'rubygems'
3
+ require 'ffi'
4
+
5
+ require "ffi/hiredis_vip/core"
6
+ require 'ffi/hiredis_vip/client'
@@ -0,0 +1,635 @@
1
+ require 'ffi/hiredis_vip'
2
+ require 'ffi/hiredis_vip/info'
3
+ require 'ffi/hiredis_vip/exists'
4
+ require 'ffi/hiredis_vip/exists_before_3'
5
+ require 'ffi/hiredis_vip/keys'
6
+ require 'ffi/hiredis_vip/mget'
7
+ require 'ffi/hiredis_vip/persist'
8
+ require 'ffi/hiredis_vip/persist_before_2_2'
9
+ require 'ffi/hiredis_vip/sadd'
10
+ require 'ffi/hiredis_vip/sadd_before_2_4'
11
+ require 'ffi/hiredis_vip/scan'
12
+ require 'ffi/hiredis_vip/scan_before_2_8'
13
+ require 'ffi/hiredis_vip/set'
14
+ require 'ffi/hiredis_vip/set_before_2_6_12'
15
+ require 'ffi/hiredis_vip/sscan'
16
+ require 'ffi/hiredis_vip/sscan_before_2_8'
17
+ require 'ffi/hiredis_vip/touch'
18
+ require 'ffi/hiredis_vip/touch_before_3_2_1'
19
+ require 'monitor'
20
+
21
+ module FFI
22
+ module HiredisVip
23
+ class Client
24
+ include MonitorMixin
25
+
26
+ OK = "OK"
27
+ PONG = "PONG"
28
+
29
+ def initialize(options = {})
30
+ database = options[:db]
31
+ host = options[:host]
32
+ port = options[:port].to_i
33
+
34
+ @connection = ::FFI::HiredisVip::Core.connect(host, port)
35
+
36
+ super() # MonitorMixin#initialize
37
+
38
+ raise "Cannot select database specified" if database && !select?(database)
39
+
40
+ set_exists_provider # Changed in Redis3
41
+ set_persist_provider # Added in Redis2.2
42
+ set_sadd_provider # Changed in Redis2.4
43
+ set_scan_provider # Introduced in Redis2.8
44
+ set_set_provider # Changed in 2.6.12
45
+ set_sscan_provider # Introduced in Redis2.8
46
+ set_touch_provider # Introduced in Redis3.2.1
47
+ end
48
+
49
+ def synchronize
50
+ mon_synchronize { yield(@connection) }
51
+ end
52
+
53
+ def dbsize
54
+ reply = nil
55
+ synchronize do |connection|
56
+ reply = ::FFI::HiredisVip::Core.command(connection, "DBSIZE")
57
+ end
58
+
59
+ case reply[:type]
60
+ when :REDIS_REPLY_INTEGER
61
+ reply[:integer]
62
+ else
63
+ 0
64
+ end
65
+ end
66
+
67
+ def decr(key)
68
+ reply = nil
69
+ command = "DECR %b"
70
+ command_args = [ :string, key, :size_t, key.size ]
71
+ synchronize do |connection|
72
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
73
+ end
74
+
75
+ return nil if reply.nil? || reply.null?
76
+
77
+ case reply[:type]
78
+ when :REDIS_REPLY_INTEGER
79
+ reply[:integer]
80
+ else
81
+ 0
82
+ end
83
+ end
84
+
85
+ def decrby(key, amount)
86
+ reply = nil
87
+ _amount = "#{amount}"
88
+ command = "DECRBY %b %b"
89
+ command_args = [ :string, key, :size_t, key.size, :string, _amount, :size_t, _amount.size ]
90
+ synchronize do |connection|
91
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
92
+ end
93
+
94
+ return nil if reply.nil? || reply.null?
95
+
96
+ case reply[:type]
97
+ when :REDIS_REPLY_INTEGER
98
+ reply[:integer]
99
+ else
100
+ 0
101
+ end
102
+ end
103
+
104
+ def del(*keys)
105
+ reply = nil
106
+ keys = keys.flatten
107
+ number_of_deletes = keys.size
108
+ command = "DEL#{' %b' * number_of_deletes}"
109
+ command_args = []
110
+ keys.each do |key|
111
+ command_args << :string << key << :size_t << key.size
112
+ end
113
+
114
+ synchronize do |connection|
115
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
116
+ end
117
+
118
+ return nil if reply.nil? || reply.null?
119
+
120
+ case reply[:type]
121
+ when :REDIS_REPLY_INTEGER
122
+ reply[:integer]
123
+ else
124
+ 0
125
+ end
126
+ end
127
+
128
+ def dump(key)
129
+ reply = nil
130
+ command = "DUMP %b"
131
+ command_args = [ :string, key, :size_t, key.size ]
132
+ synchronize do |connection|
133
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
134
+ end
135
+
136
+ return nil if reply.nil? || reply.null?
137
+
138
+ case reply[:type]
139
+ when :REDIS_REPLY_STRING
140
+ reply[:str]
141
+ else
142
+ nil
143
+ end
144
+ end
145
+
146
+ def echo(value)
147
+ reply = nil
148
+ command = "ECHO %b"
149
+ command_args = [ :string, value, :size_t, value.size ]
150
+ synchronize do |connection|
151
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
152
+ end
153
+
154
+ return nil if reply.nil? || reply.null?
155
+
156
+ case reply[:type]
157
+ when :REDIS_REPLY_STRING
158
+ reply[:str]
159
+ when :REDIS_REPLY_NIL
160
+ nil
161
+ else
162
+ nil
163
+ end
164
+ end
165
+
166
+ def echo?(value)
167
+ echo(value) == value
168
+ end
169
+
170
+ def exists(*keys)
171
+ @exists_provider.exists(*keys)
172
+ end
173
+
174
+ def exists?(key)
175
+ exists(key) == 1
176
+ end
177
+
178
+ def expire(key, seconds)
179
+ reply = nil
180
+ time_in_seconds = "#{seconds}"
181
+ command = "EXPIRE %b %b"
182
+ command_args = [ :string, key, :size_t, key.size, :string, time_in_seconds, :size_t, time_in_seconds.size ]
183
+ synchronize do |connection|
184
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
185
+ end
186
+
187
+ # TODO: should we return a 0 here?
188
+ return 0 if reply.nil? || reply.null?
189
+
190
+ case reply[:type]
191
+ when :REDIS_REPLY_INTEGER
192
+ reply[:integer]
193
+ else
194
+ 0
195
+ end
196
+ end
197
+
198
+ def expire?(key, seconds)
199
+ expire(key, seconds) == 1
200
+ end
201
+
202
+ def expireat(key, unix_time)
203
+ reply = nil
204
+ epoch = "#{unix_time}"
205
+ command = "EXPIREAT %b %b"
206
+ command_args = [ :string, key, :size_t, key.size, :string, epoch, :size_t, epoch.size ]
207
+ synchronize do |connection|
208
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
209
+ end
210
+
211
+ return 0 if reply.nil? || reply.null?
212
+
213
+ case reply[:type]
214
+ when :REDIS_REPLY_INTEGER
215
+ reply[:integer]
216
+ else
217
+ 0
218
+ end
219
+ end
220
+
221
+ def expireat?(key, unix_time)
222
+ expireat(key, unix_time) == 1
223
+ end
224
+
225
+ def flushall
226
+ reply = nil
227
+ synchronize do |connection|
228
+ reply = ::FFI::HiredisVip::Core.command(connection, "FLUSHALL")
229
+ end
230
+
231
+ return "" if reply.nil? || reply.null?
232
+
233
+ case reply[:type]
234
+ when :REDIS_REPLY_STRING
235
+ reply[:str]
236
+ else
237
+ ""
238
+ end
239
+ end
240
+
241
+ def flushall?
242
+ flushall == OK
243
+ end
244
+
245
+ def flushdb
246
+ reply = nil
247
+ synchronize do |connection|
248
+ reply = ::FFI::HiredisVip::Core.command(connection, "FLUSHDB")
249
+ end
250
+
251
+ return "" if reply.nil? || reply.null?
252
+
253
+ case reply[:type]
254
+ when :REDIS_REPLY_STRING
255
+ reply[:str]
256
+ else
257
+ ""
258
+ end
259
+ end
260
+
261
+ def flushdb?
262
+ flushdb == OK
263
+ end
264
+
265
+ def get(key)
266
+ reply = nil
267
+ command = "GET %b"
268
+ command_args = [ :string, key, :size_t, key.size ]
269
+
270
+ synchronize do |connection|
271
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
272
+ end
273
+
274
+ return nil if reply.nil? || reply.null?
275
+
276
+ case reply[:type]
277
+ when :REDIS_REPLY_STRING
278
+ reply[:str]
279
+ when :REDIS_REPLY_NIL
280
+ nil
281
+ else
282
+ nil # TODO: should this be empty string?
283
+ end
284
+ end
285
+ alias_method :[], :get
286
+
287
+ def incr(key)
288
+ reply = nil
289
+ command = "INCR %b"
290
+ command_args = [ :string, key, :size_t, key.size ]
291
+ synchronize do |connection|
292
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
293
+ end
294
+
295
+ return nil if reply.nil? || reply.null?
296
+
297
+ case reply[:type]
298
+ when :REDIS_REPLY_INTEGER
299
+ reply[:integer]
300
+ else
301
+ 0
302
+ end
303
+ end
304
+
305
+ def incrby(key, amount)
306
+ reply = nil
307
+ _amount = "#{amount}"
308
+ command = "INCRBY %b %b"
309
+ command_args = [ :string, key, :size_t, key.size, :string, _amount, :size_t, _amount.size ]
310
+ synchronize do |connection|
311
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
312
+ end
313
+
314
+ return nil if reply.nil? || reply.null?
315
+
316
+ case reply[:type]
317
+ when :REDIS_REPLY_INTEGER
318
+ reply[:integer]
319
+ else
320
+ 0
321
+ end
322
+ end
323
+
324
+ def info
325
+ reply = nil
326
+ synchronize do |connection|
327
+ reply = ::FFI::HiredisVip::Core.command(connection, "INFO")
328
+ end
329
+
330
+ return "" if reply.nil? || reply.null?
331
+
332
+ case reply[:type]
333
+ when :REDIS_REPLY_STRING
334
+ reply[:str]
335
+ else
336
+ ""
337
+ end
338
+ end
339
+
340
+ def keys(pattern)
341
+ @keys_provider ||= ::FFI::HiredisVip::Keys.new(self)
342
+ @keys_provider.keys(pattern)
343
+ end
344
+
345
+ def mget(*keys)
346
+ @mget_provider ||= ::FFI::HiredisVip::Mget.new(self)
347
+ @mget_provider.mget(*keys)
348
+ end
349
+
350
+ def persist(key)
351
+ @persist_provider.persist(key)
352
+ end
353
+
354
+ def persist?(key)
355
+ persist(key) == 1 || ttl(key) == -1
356
+ end
357
+
358
+ def ping
359
+ reply = nil
360
+ synchronize do |connection|
361
+ reply = ::FFI::HiredisVip::Core.command(connection, "PING")
362
+ end
363
+
364
+ return nil if reply.nil? || reply.null?
365
+
366
+ case reply[:type]
367
+ when :REDIS_REPLY_STATUS
368
+ reply[:str]
369
+ when :REDIS_REPLY_STRING
370
+ reply[:str]
371
+ else
372
+ ""
373
+ end
374
+ end
375
+
376
+ def ping?
377
+ ping == PONG
378
+ end
379
+
380
+ def psetex(key, value, expiry)
381
+ @set_provider.psetex(key, value, expiry)
382
+ end
383
+
384
+ def reconnect
385
+ reply = nil
386
+ synchronize do |connection|
387
+ reply = ::FFI::HiredisVip::Core.redisReconnect(connection)
388
+ end
389
+
390
+ case reply
391
+ when :REDIS_OK
392
+ true
393
+ else
394
+ false
395
+ end
396
+ end
397
+
398
+ def sadd(key, *values)
399
+ @sadd_provider.sadd(key, *values)
400
+ end
401
+
402
+ def scan(cursor, options = {})
403
+ @scan_provider.scan(cursor, options)
404
+ end
405
+
406
+ def scan_each(options = {}, &block)
407
+ return to_enum(:scan_each, options) unless block_given?
408
+
409
+ cursor = "0"
410
+ loop do
411
+ cursor, keys = scan(cursor, options)
412
+ keys.each(&block)
413
+ break if cursor == "0"
414
+ end
415
+ end
416
+
417
+ def sscan(key, cursor, options = {})
418
+ @sscan_provider.sscan(key, cursor, options)
419
+ end
420
+
421
+ def sscan_each(key, options = {}, &block)
422
+ return to_enum(:sscan_each, key, options) unless block_given?
423
+
424
+ cursor = "0"
425
+ loop do
426
+ cursor, values = sscan(key, cursor, options)
427
+ values.each(&block)
428
+ break if cursor == "0"
429
+ end
430
+ end
431
+
432
+ def select(db)
433
+ reply = nil
434
+ db = "#{db}"
435
+ command = "SELECT %b"
436
+ command_args = [ :string, db, :size_t, db.size ]
437
+ synchronize do |connection|
438
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
439
+ end
440
+
441
+ return nil if reply.nil? || reply.null?
442
+
443
+ case reply[:type]
444
+ when :REDIS_REPLY_STATUS
445
+ reply[:str]
446
+ else
447
+ nil
448
+ end
449
+ end
450
+
451
+ def select?(db)
452
+ select(db) == OK
453
+ end
454
+
455
+ def set(key, value, options = {})
456
+ @set_provider.set(key, value, options)
457
+ end
458
+ alias_method :[]=, :set
459
+
460
+ def set?(key, value, options = {})
461
+ set(key, value, options) == OK
462
+ end
463
+
464
+ def setex(key, value, expiry)
465
+ @set_provider.setex(key, value, expiry)
466
+ end
467
+
468
+ def setnx(key, value)
469
+ @set_provider.setnx(key, value)
470
+ end
471
+
472
+ def supports_persist?
473
+ @persist_provider.supports_persist?
474
+ end
475
+
476
+ def supports_scan?
477
+ @scan_provider.supports_scan?
478
+ end
479
+
480
+ def supports_scan_each?
481
+ @scan_provider.supports_scan?
482
+ end
483
+
484
+ def supports_sscan?
485
+ @sscan_provider.supports_sscan?
486
+ end
487
+
488
+ def supports_sscan_each?
489
+ @sscan_provider.supports_sscan?
490
+ end
491
+
492
+ def supports_touch?
493
+ @touch_provider.supports_touch?
494
+ end
495
+
496
+ def ttl(key)
497
+ reply = nil
498
+ command = "TTL %b"
499
+ command_args = [ :string, key, :size_t, key.size ]
500
+ synchronize do |connection|
501
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
502
+ end
503
+
504
+ return nil if reply.nil? || reply.null?
505
+
506
+ case reply[:type]
507
+ when :REDIS_REPLY_INTEGER
508
+ reply[:integer]
509
+ end
510
+ end
511
+
512
+ def touch(*keys)
513
+ @touch_provider.touch(*keys)
514
+ end
515
+
516
+ private
517
+
518
+ def redis_info_parsed
519
+ @redis_info_parsed ||= ::FFI::HiredisVip::Info.new(info)
520
+ end
521
+
522
+ def redis_version_2?
523
+ return @redis_version_2 unless @redis_version_2.nil?
524
+
525
+ @redis_version_2 = redis_info_parsed["redis_version"] &&
526
+ redis_info_parsed["redis_version"].start_with?("2")
527
+ end
528
+
529
+ def redis_version_3?
530
+ return @redis_version_3 unless @redis_version_3.nil?
531
+
532
+ @redis_version_3 = redis_info_parsed["redis_version"] &&
533
+ redis_info_parsed["redis_version"].start_with?("3")
534
+ end
535
+
536
+ def redis_version_greater_than_2_2?
537
+ return @redis_version_greater_than_2_2 unless @redis_version_greater_than_2_2.nil?
538
+
539
+ @redis_version_greater_than_2_2 = redis_info_parsed["redis_version"] &&
540
+ ::Gem::Version.new(redis_info_parsed["redis_version"]) >= ::Gem::Version.new("2.2.0")
541
+ end
542
+
543
+ def redis_version_greater_than_2_4?
544
+ return @redis_version_greater_than_2_4 unless @redis_version_greater_than_2_4.nil?
545
+
546
+ @redis_version_greater_than_2_4 = redis_info_parsed["redis_version"] &&
547
+ ::Gem::Version.new(redis_info_parsed["redis_version"]) >= ::Gem::Version.new("2.4.0")
548
+ end
549
+
550
+ def redis_version_greater_than_2_6_12?
551
+ return @redis_version_greater_than_2_6_12 unless @redis_version_greater_than_2_6_12.nil?
552
+
553
+ @redis_version_greater_than_2_6_12 = redis_info_parsed["redis_version"] &&
554
+ ::Gem::Version.new(redis_info_parsed["redis_version"]) >= ::Gem::Version.new("2.6.12")
555
+ end
556
+
557
+ def redis_version_greater_than_2_8?
558
+ return @redis_version_greater_than_2_8 unless @redis_version_greater_than_2_8.nil?
559
+
560
+ @redis_version_greater_than_2_8 = redis_info_parsed["redis_version"] &&
561
+ ::Gem::Version.new(redis_info_parsed["redis_version"]) >= ::Gem::Version.new("2.8.0")
562
+ end
563
+
564
+ def redis_version_greater_than_3_2_1?
565
+ return @redis_version_greater_than_3_2_1 unless @redis_version_greater_than_3_2_1.nil?
566
+
567
+ @redis_version_greater_than_3_2_1 = redis_info_parsed["redis_version"] &&
568
+ ::Gem::Version.new(redis_info_parsed["redis_version"]) >= ::Gem::Version.new("3.2.1")
569
+ end
570
+
571
+ def set_exists_provider
572
+ @exists_provider = case
573
+ when redis_version_3?
574
+ ::FFI::HiredisVip::Exists.new(self)
575
+ else
576
+ ::FFI::HiredisVip::ExistsBefore3.new(self)
577
+ end
578
+ end
579
+
580
+ def set_persist_provider
581
+ @persist_provider = case
582
+ when redis_version_greater_than_2_2?
583
+ ::FFI::HiredisVip::Persist.new(self)
584
+ else
585
+ ::FFI::HiredisVip::PersistBefore22.new(self)
586
+ end
587
+ end
588
+
589
+ def set_sadd_provider
590
+ @sadd_provider = case
591
+ when redis_version_greater_than_2_4?
592
+ ::FFI::HiredisVip::Sadd.new(self)
593
+ else
594
+ ::FFI::HiredisVip::SaddBefore24.new(self)
595
+ end
596
+ end
597
+
598
+ def set_scan_provider
599
+ @scan_provider = case
600
+ when redis_version_greater_than_2_8?
601
+ ::FFI::HiredisVip::Scan.new(self)
602
+ else
603
+ ::FFI::HiredisVip::ScanBefore28.new(self)
604
+ end
605
+ end
606
+
607
+ def set_set_provider
608
+ @set_provider = case
609
+ when redis_version_greater_than_2_6_12?
610
+ ::FFI::HiredisVip::Set.new(self)
611
+ else
612
+ ::FFI::HiredisVip::SetBefore2612.new(self)
613
+ end
614
+ end
615
+
616
+ def set_sscan_provider
617
+ @sscan_provider = case
618
+ when redis_version_greater_than_2_8?
619
+ ::FFI::HiredisVip::Sscan.new(self)
620
+ else
621
+ ::FFI::HiredisVip::SscanBefore28.new(self)
622
+ end
623
+ end
624
+
625
+ def set_touch_provider
626
+ @touch_provider = case
627
+ when redis_version_greater_than_3_2_1?
628
+ ::FFI::HiredisVip::Touch.new(self)
629
+ else
630
+ ::FFI::HiredisVip::TouchBefore321.new(self)
631
+ end
632
+ end
633
+ end # class Client
634
+ end # module HiredisVip
635
+ end # module FFI