ffi-hiredis_vip 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class ScanBefore28
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def scan(cursor, options = {})
9
+ raise <<-SCAN_ERROR
10
+ SCAN Command in Redis is only available on Servers >= 2.8.0
11
+ The Redis Server you are connecting to is using a version that is not supported.
12
+
13
+ == > INFO
14
+ #{@client.info}
15
+ SCAN_ERROR
16
+ end
17
+
18
+ def supports_scan?
19
+ false
20
+ end
21
+
22
+ end # class ScanBefore28
23
+ end # module HiredisVip
24
+ end # module FFI
@@ -0,0 +1,68 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class Set
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def psetex(key, value, expiry)
9
+ set(key, value, :px => expiry)
10
+ end
11
+
12
+ def set(key, value, options = {})
13
+ reply = nil
14
+ command = "SET %b %b"
15
+ command_args = [ :string, key, :size_t, key.size, :string, value, :size_t, value.size ]
16
+
17
+ if options[:ex]
18
+ expiry = "#{options[:ex]}"
19
+ command << " EX %b"
20
+ command_args << :string << expiry << :size_t << expiry.size
21
+ end
22
+
23
+ if options[:px]
24
+ px_expiry = "#{options[:px]}"
25
+ command << " PX %b"
26
+ command_args << :string << px_expiry << :size_t << px_expiry.size
27
+ end
28
+
29
+ command << " NX" if options[:nx]
30
+ command << " XX" if options[:xx]
31
+
32
+ synchronize do |connection|
33
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
34
+ end
35
+
36
+ return nil if reply.nil? || reply.null?
37
+
38
+ case reply[:type]
39
+ when :REDIS_REPLY_STRING
40
+ reply[:str]
41
+ when :REDIS_REPLY_STATUS
42
+ reply[:str]
43
+ when :REDIS_REPLY_NIL
44
+ nil
45
+ else
46
+ ""
47
+ end
48
+ end
49
+
50
+ def setex(key, value, expiry)
51
+ set(key, value, :ex => expiry)
52
+ end
53
+
54
+ def setnx(key, value)
55
+ set(key, value, :nx => true)
56
+ end
57
+
58
+ private
59
+
60
+ def synchronize
61
+ @client.synchronize do |connection|
62
+ yield(connection)
63
+ end
64
+ end
65
+
66
+ end # class Set
67
+ end # module HiredisVip
68
+ end # module FFI
@@ -0,0 +1,121 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class SetBefore2612
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def psetex(key, value, expiry)
9
+ expiry = "#{expiry}"
10
+ reply = nil
11
+ command = "PSETEX %b %b %b"
12
+ command_args = [ :string, key, :size_t, key.size, :string, expiry, :size_t, expiry.size, :string, value, :size_t, value.size ]
13
+
14
+ synchronize do |connection|
15
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
16
+ end
17
+
18
+ return nil if reply.nil? || reply.null?
19
+
20
+ case reply[:type]
21
+ when :REDIS_REPLY_STRING
22
+ reply[:str]
23
+ when :REDIS_REPLY_STATUS
24
+ reply[:str]
25
+ when :REDIS_REPLY_NIL
26
+ nil
27
+ else
28
+ ""
29
+ end
30
+ end
31
+
32
+ def set(key, value, options = {})
33
+ reply = nil
34
+ command = "SET %b %b"
35
+ command_args = [ :string, key, :size_t, key.size, :string, value, :size_t, value.size ]
36
+
37
+ case
38
+ when options[:ex]
39
+ return setex(key, value, options[:ex])
40
+ when options[:px]
41
+ return psetex(key, value, options[:ex])
42
+ when options[:nx]
43
+ return setnx(key, value)
44
+ end
45
+
46
+ synchronize do |connection|
47
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
48
+ end
49
+
50
+ return nil if reply.nil? || reply.null?
51
+
52
+ case reply[:type]
53
+ when :REDIS_REPLY_STRING
54
+ reply[:str]
55
+ when :REDIS_REPLY_STATUS
56
+ reply[:str]
57
+ when :REDIS_REPLY_NIL
58
+ nil
59
+ else
60
+ ""
61
+ end
62
+ end
63
+
64
+ def setex(key, value, expiry)
65
+ expiry = "#{expiry}"
66
+ reply = nil
67
+ command = "SETEX %b %b %b"
68
+ command_args = [ :string, key, :size_t, key.size, :string, expiry, :size_t, expiry.size, :string, value, :size_t, value.size ]
69
+
70
+ synchronize do |connection|
71
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
72
+ end
73
+
74
+ return nil if reply.nil? || reply.null?
75
+
76
+ case reply[:type]
77
+ when :REDIS_REPLY_STRING
78
+ reply[:str]
79
+ when :REDIS_REPLY_STATUS
80
+ reply[:str]
81
+ when :REDIS_REPLY_NIL
82
+ nil
83
+ else
84
+ ""
85
+ end
86
+ end
87
+
88
+ def setnx(key, value)
89
+ reply = nil
90
+ command = "SETNX %b %b"
91
+ command_args = [ :string, key, :size_t, key.size, :string, value, :size_t, value.size ]
92
+
93
+ synchronize do |connection|
94
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
95
+ end
96
+
97
+ return nil if reply.nil? || reply.null?
98
+
99
+ case reply[:type]
100
+ when :REDIS_REPLY_STRING
101
+ reply[:str]
102
+ when :REDIS_REPLY_STATUS
103
+ reply[:str]
104
+ when :REDIS_REPLY_NIL
105
+ nil
106
+ else
107
+ ""
108
+ end
109
+ end
110
+
111
+ private
112
+
113
+ def synchronize
114
+ @client.synchronize do |connection|
115
+ yield(connection)
116
+ end
117
+ end
118
+
119
+ end # class SetBefore2612
120
+ end # module HiredisVip
121
+ end # module FFI
@@ -0,0 +1,78 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class Sscan
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def sscan(key, cursor, options = {})
9
+ reply = nil
10
+ command = "SSCAN %b %b"
11
+ command_args = [ :string, key, :size_t, key.size, :string, cursor, :size_t, cursor.size ]
12
+
13
+ if options[:match]
14
+ matcher = "#{options[:match]}"
15
+ command << " MATCH %b"
16
+ command_args << :string << matcher << :size_t << matcher.size
17
+ end
18
+
19
+ if options[:count]
20
+ count = "#{options[:count]}"
21
+ command << " COUNT %b"
22
+ command_args << :string << count << :size_t << count.size
23
+ end
24
+
25
+ synchronize do |connection|
26
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
27
+ end
28
+
29
+ return nil if reply.nil? || reply.null?
30
+
31
+ # TODO: more error checking here?
32
+ case reply[:type]
33
+ when :REDIS_REPLY_ARRAY
34
+ [ scan_results_cursor(reply), scan_results_to_array(reply) ]
35
+ end
36
+ end
37
+
38
+ def supports_sscan?
39
+ true
40
+ end
41
+
42
+ private
43
+
44
+ def scan_results_cursor(reply)
45
+ zeroth_result = ::FFI::HiredisVip::Core.redisReplyElement(reply, 0)
46
+
47
+ if !zeroth_result.null? && zeroth_result[:type] == :REDIS_REPLY_STRING
48
+ zeroth_result[:str]
49
+ else
50
+ raise "probs" # TODO: what do we do here
51
+ end
52
+ end
53
+
54
+ def scan_results_to_array(reply)
55
+ scan_results = []
56
+ array_reply = ::FFI::HiredisVip::Core.redisReplyElement(reply, 1)
57
+
58
+ if !array_reply.null? && array_reply[:type] == :REDIS_REPLY_ARRAY
59
+ 0.upto(array_reply[:elements] - 1) do |element_number|
60
+ result = ::FFI::HiredisVip::Core.redisReplyElement(array_reply, element_number)
61
+ scan_results << result[:str] if result[:type] == :REDIS_REPLY_STRING
62
+ end
63
+
64
+ scan_results
65
+ else
66
+ raise "probs" # TODO: what do we do here
67
+ end
68
+ end
69
+
70
+ def synchronize
71
+ @client.synchronize do |connection|
72
+ yield(connection)
73
+ end
74
+ end
75
+
76
+ end # class Sscan
77
+ end # module HiredisVip
78
+ end # module FFI
@@ -0,0 +1,24 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class SscanBefore28
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def sscan(key, cursor, options = {})
9
+ raise <<-SSCAN_ERROR
10
+ SSCAN Command in Redis is only available on Servers >= 2.8.0
11
+ The Redis Server you are connecting to is using a version that is not supported.
12
+
13
+ == > INFO
14
+ #{@client.info}
15
+ SSCAN_ERROR
16
+ end
17
+
18
+ def supports_sscan?
19
+ false
20
+ end
21
+
22
+ end # class SscanBefore28
23
+ end # module HiredisVip
24
+ end # module FFI
@@ -0,0 +1,38 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class Touch
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def touch(*keys)
9
+ reply = nil
10
+ keys = keys.flatten
11
+ number_of_touches = keys.size
12
+ command = "TOUCH#{' %b' * number_of_touches}"
13
+ command_args = []
14
+ keys.each do |key|
15
+ command_args << :string << key << :size_t << key.size
16
+ end
17
+
18
+ synchronize do |connection|
19
+ reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)
20
+ end
21
+
22
+ return nil if reply.nil? || reply.null?
23
+
24
+ case reply[:type]
25
+ when :REDIS_REPLY_INTEGER
26
+ reply[:integer]
27
+ else
28
+ 0
29
+ end
30
+ end
31
+
32
+ def supports_touch?
33
+ true
34
+ end
35
+
36
+ end # class Touch
37
+ end # module HiredisVip
38
+ end # module FFI
@@ -0,0 +1,24 @@
1
+ module FFI
2
+ module HiredisVip
3
+ class TouchBefore321
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def touch(*keys)
9
+ raise <<-TOUCH_ERROR
10
+ TOUCH Command in Redis is only available on Servers >= 3.2.1
11
+ The Redis Server you are connecting to is using a version that is not supported.
12
+
13
+ == > INFO
14
+ #{@client.info}
15
+ TOUCH_ERROR
16
+ end
17
+
18
+ def supports_touch?
19
+ false
20
+ end
21
+
22
+ end # class TouchBefore321
23
+ end # module HiredisVip
24
+ end # module FFI
@@ -0,0 +1,5 @@
1
+ module FFI
2
+ module HiredisVip
3
+ VERSION = "0.1.0.pre1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffi-hiredis_vip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffi-hiredis_vip-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0.pre4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0.pre4
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: " FFI Wrapper for hiredis-vip "
112
+ email:
113
+ - brandonsdewitt@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - bin/console
124
+ - bin/setup
125
+ - ffi-hiredis_vip.gemspec
126
+ - lib/ffi/hiredis_vip.rb
127
+ - lib/ffi/hiredis_vip/client.rb
128
+ - lib/ffi/hiredis_vip/exists.rb
129
+ - lib/ffi/hiredis_vip/exists_before_3.rb
130
+ - lib/ffi/hiredis_vip/info.rb
131
+ - lib/ffi/hiredis_vip/keys.rb
132
+ - lib/ffi/hiredis_vip/mget.rb
133
+ - lib/ffi/hiredis_vip/persist.rb
134
+ - lib/ffi/hiredis_vip/persist_before_2_2.rb
135
+ - lib/ffi/hiredis_vip/sadd.rb
136
+ - lib/ffi/hiredis_vip/sadd_before_2_4.rb
137
+ - lib/ffi/hiredis_vip/scan.rb
138
+ - lib/ffi/hiredis_vip/scan_before_2_8.rb
139
+ - lib/ffi/hiredis_vip/set.rb
140
+ - lib/ffi/hiredis_vip/set_before_2_6_12.rb
141
+ - lib/ffi/hiredis_vip/sscan.rb
142
+ - lib/ffi/hiredis_vip/sscan_before_2_8.rb
143
+ - lib/ffi/hiredis_vip/touch.rb
144
+ - lib/ffi/hiredis_vip/touch_before_3_2_1.rb
145
+ - lib/ffi/hiredis_vip/version.rb
146
+ homepage:
147
+ licenses: []
148
+ metadata:
149
+ allowed_push_host: https://rubygems.org
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">"
162
+ - !ruby/object:Gem::Version
163
+ version: 1.3.1
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: FFI Wrapper around hiredis-vip for Hiredis and cluster support
170
+ test_files: []