ffi-hiredis_vip-core 0.1.0.pre

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: 9479892e645a66e1090e96e17224f3d921f99600
4
+ data.tar.gz: e4a8ce85cc846fa215dfd254533a42da86f6b8f8
5
+ SHA512:
6
+ metadata.gz: 4e509d9613c16fc6bfc299cb9c43334f5d3e3355d81da0a4d4e5161ab0d29995713e98f16457cd0d17b420f996aef8c2f1f94bc993f2b7d2bb5207a2f5d445f4
7
+ data.tar.gz: d44f95387b926bbd66be3f7b8b09b88a764c6bcb218bd7705ce2f37457b644ff7eb6b50dc922cfde55913720f9024cb7e1239ad5ddfb3959224ba8187dfc8cf9
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.2.2
5
+ before_install: gem install bundler -v 1.13.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ffi-hiredis_vip-core.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Brandon Dewitt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Ffi::HiredisVip::Core
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/core`. 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-core'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ffi-hiredis_vip-core
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-core.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
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/core"
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,39 @@
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/core/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ffi-hiredis_vip-core"
8
+ spec.version = FFI::HiredisVip::Core::VERSION
9
+ spec.authors = ["Brandon Dewitt"]
10
+ spec.email = ["brandonsdewitt@gmail.com"]
11
+
12
+ spec.summary = %q{ core library for FFI bindings for hiredis_vip (clustering support) }
13
+ spec.description = %q{ core library for FFI bingings for hiredis_vip (clustering support) }
14
+ spec.homepage = "https://github.com/abrandoned/ffi-hiredis_vip-core"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency "ffi"
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
+ end
@@ -0,0 +1,7 @@
1
+ module FFI
2
+ module HiredisVip
3
+ module Core
4
+ VERSION = "0.1.0.pre"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,121 @@
1
+ require "ffi/hiredis_vip/core/version"
2
+
3
+ require 'rubygems'
4
+ require 'ffi'
5
+
6
+ module FFI
7
+ module HiredisVip
8
+ module Core
9
+ extend ::FFI::Library
10
+ ffi_lib_flags :now, :global
11
+ # TODO: can we support libhiredis + libhiredis_vip and enable clustering on the latter?
12
+ # TODO: need to provide ways to set the loading of the lip and check standard lib paths
13
+ LIB_HOME = ENV["HIREDIS_VIP_HOME"]
14
+ ffi_lib File.expand_path("#{LIB_HOME}/libhiredis_vip.#{::FFI::Platform::LIBSUFFIX}", File.dirname(__FILE__))
15
+
16
+ RedisClusterFlags = enum :HIRCLUSTER_FLAG_NULL, 0x0,
17
+ :HIRCLUSTER_FLAG_ADD_SLAVE, 0x1000, #/* The flag to decide whether add slave node in redisClusterContext->nodes. This is set in the
18
+ #* least significant bit of the flags field in redisClusterContext. (1000000000000) */
19
+ :HIRCLUSTER_FLAG_ADD_OPENSLOT, 0x2000, #/* The flag to decide whether add open slot for master node. (10000000000000) */
20
+ :HIRCLUSTER_FLAG_ROUTE_USE_SLOTS, 0x4000 # /* The flag to decide whether add open slot for master node. (100000000000000) */
21
+
22
+ RedisReplyType = enum :REDIS_REPLY_STRING, 1,
23
+ :REDIS_REPLY_ARRAY, 2,
24
+ :REDIS_REPLY_INTEGER, 3,
25
+ :REDIS_REPLY_NIL, 4,
26
+ :REDIS_REPLY_STATUS, 5,
27
+ :REDIS_REPLY_ERROR, 6
28
+
29
+ RedisOkType = enum :REDIS_OK, 0,
30
+ :REDIS_ERR, -1,
31
+ :REDIS_ERR_IO, 1, # /* Error in read or write */
32
+ :REDIS_ERR_OTHER, 2, # /* Everything else... */
33
+ :REDIS_ERR_EOF, 3, # /* End of file */
34
+ :REDIS_ERR_PROTOCOL, 4, # /* Protocol error */
35
+ :REDIS_ERR_OOM, 5, # /* Out of memory */
36
+ :REDIS_ERR_CLUSTER_TOO_MANY_REDIRECT, 6
37
+
38
+ class Timeval < FFI::Struct
39
+ layout :tv_sec, :long,
40
+ :tv_usec, :long
41
+ end
42
+
43
+ class RedisReply < ::FFI::Struct
44
+ layout :type, ::FFI::HiredisVip::Core::RedisReplyType,
45
+ :integer, :long_long,
46
+ :len, :int,
47
+ :str, :string,
48
+ :elements, :size_t,
49
+ :element, :pointer
50
+ end
51
+
52
+ attach_function :freeReplyObject, [:pointer], :void, :blocking => true
53
+
54
+ attach_function :redisConnect, [:string, :int], :pointer, :blocking => true
55
+ attach_function :redisReconnect, [:pointer], RedisOkType, :blocking => true # :pointer => redisContext
56
+ attach_function :redisEnableKeepAlive, [:pointer], RedisOkType, :blocking => true # :pointer => redisContext
57
+ attach_function :redisCommand, [:pointer, :string, :varargs], :pointer, :blocking => true
58
+ attach_function :redisFree, [:pointer], :void, :blocking => true # :pointer => redisContext from redisConnect
59
+
60
+ attach_function :redisClusterFree, [:pointer], :void, :blocking => true # :pointer => redisClusterContext
61
+ attach_function :redisClusterConnect, [:string, :int], :pointer, :blocking => true # string => addresses, :int => flags
62
+ attach_function :redisClusterConnectWithTimeout, [:string, Timeval.by_value, :int], :pointer, :blocking => true # string => addresses, :timeval => timeout, :int => flags
63
+ attach_function :redisClusterConnectNonBlock, [:string, :int], :pointer, :blocking => true
64
+ attach_function :redisClusterCommand, [:pointer, :string, :varargs], :pointer, :blocking => true
65
+ attach_function :redisClusterSetMaxRedirect, [:pointer, :int], :void, :blocking => true # :pointer => redisContext, :int => max redirect
66
+ attach_function :redisClusterReset, [:pointer], :void, :blocking => true # :pointer => redisClusterContext
67
+
68
+ def self.command(connection, command, *args)
69
+ ::FFI::HiredisVip::Core::RedisReply.new(::FFI::AutoPointer.new(::FFI::HiredisVip::Core.redisCommand(connection, command, *args), ::FFI::HiredisVip::Core.method(:freeReplyObject)))
70
+ end
71
+
72
+ def self.connect(host, port)
73
+ ::FFI::AutoPointer.new(::FFI::HiredisVip::Core.redisConnect(host, port), ::FFI::HiredisVip::Core.method(:redisFree))
74
+ end
75
+
76
+ def self.cluster_command(cluster_context, command, *args)
77
+ ::FFI::AutoPointer.new(::FFI::HiredisVip::Core.redisClusterCommand(cluster_context, command, *args), ::FFI::HiredisVip::Core.method(:freeReplyObject))
78
+ end
79
+
80
+ def self.cluster_connect(addresses, flags = nil)
81
+ flags ||= RedisClusterFlags[:HIRCLUSTER_FLAG_ADD_SLAVE] # Not sure what default should be
82
+ ::FFI::AutoPointer.new(::FFI::HiredisVip::Core.redisClusterConnect(addresses, flags), ::FFI::HiredisVip::Core.method(:redisClusterFree))
83
+ end
84
+
85
+ # TODO: extract into ffi-hiredis_vip-benchmark
86
+ def self.bench(address = "127.0.0.1", port = 6379)
87
+ require "benchmark"
88
+
89
+ conn = connect(address, port)
90
+ n = (ARGV.shift || 20000).to_i
91
+
92
+ elapsed = Benchmark.realtime do
93
+ # n sets, n gets
94
+ n.times do |i|
95
+ key = "foo#{i}"
96
+ value = key * 10
97
+
98
+ command(conn, "SET %b %b", :string, key, :size_t, key.size, :string, value, :size_t, value.size)
99
+ command(conn, "GET %b", :string, key, :size_t, key.size)
100
+ end
101
+ end
102
+
103
+ puts '%.2f Kops' % (2 * n / 1000 / elapsed)
104
+ end
105
+
106
+ #def self.test_set_get
107
+ # connection = FFIHIREDISVIP.redisConnect("127.0.0.1", 6379)
108
+
109
+ # reply_raw = FFIHIREDISVIP.redisCommand(connection, "SET %b %b", :string, "bar", :size_t, 3, :string, "hello", :size_t, 5)
110
+ # FFIHIREDISVIP.freeReplyObject(reply_raw)
111
+
112
+ # get_reply_raw = FFIHIREDISVIP.redisCommand(connection, "GET bar")
113
+ # reply = RedisReply.new(get_reply_raw)
114
+ # puts reply[:str]
115
+ # FFIHIREDISVIP.freeReplyObject(get_reply_raw)
116
+
117
+ # FFIHIREDISVIP.redisFree(connection)
118
+ #end
119
+ end
120
+ end
121
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffi-hiredis_vip-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-07 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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: " core library for FFI bingings for hiredis_vip (clustering support) "
84
+ email:
85
+ - brandonsdewitt@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - ffi-hiredis_vip-core.gemspec
99
+ - lib/ffi/hiredis_vip/core.rb
100
+ - lib/ffi/hiredis_vip/core/version.rb
101
+ homepage: https://github.com/abrandoned/ffi-hiredis_vip-core
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">"
118
+ - !ruby/object:Gem::Version
119
+ version: 1.3.1
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: core library for FFI bindings for hiredis_vip (clustering support)
126
+ test_files: []