redstruct 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24f641b7af2b6207244ce2e1f6cc48b4ace00501
4
- data.tar.gz: d313d71fb27eb36fd6fb6cb34c21709fa0e1f08e
3
+ metadata.gz: 7010bd0a452c39445eb106efd64f418019f49086
4
+ data.tar.gz: fcac9ed0f4261cdf9b83e39d8baf87f7d6f13823
5
5
  SHA512:
6
- metadata.gz: b4a29bff10074805abbb590a238d5e302ab3d426148c60fced3a54af99970978a24fb39815f95f6e9a382af8ae4452bd47d989ca5674ebaa761b58649114296b
7
- data.tar.gz: 82677b93e0bfd290d9c3733b30c00daeae115de057092931635b1178c18b974c04916fb334497a509703b92e1a5db0ea2eb9ba505500af3f405bace568cfca02
6
+ metadata.gz: 72a43e0e1df1868f8531db9a1d44b2b5e7735d062a063eeac2d970113ce462045869a12a812a3dc2ee7a950b51e0bc05fc9c69d1f6072153500beec9d6b0916f
7
+ data.tar.gz: 50853403b5514b16151701376584fc4f2906631a12ac7d30c8daa82c5e9e51580c655ba3b36c862c2768ec15f13264e6c93e8cccf055028085999fcdb9f51fac
data/README.md CHANGED
@@ -32,6 +32,21 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
32
 
33
33
  Avoid using transactions; the Redis documentation suggests using Lua scripts where possible, as in most cases they will be faster than transactions. Use the `Redstruct::Utils::Scriptable` module and the `defscript` macro instead.
34
34
 
35
+ ## TODO
36
+
37
+ [x] Implement counters
38
+ [x] Implement locks (blocking/non-blocking)
39
+ [x] Implement queues
40
+ [x] Implement basic types (set, string, list, hash)
41
+ [ ] Implement SortedSet
42
+ [ ] Implement stacks
43
+ [ ] Discuss supporting pipelining vs. just using lua scripts (better interface for scripted extensions?)
44
+ [ ] Design/discuss stored factory meta-data (i.e. keep track of created objects, clear said objects, etc.)
45
+ [ ] Implement/redesign factory such that types, hls, etc., packages add methods as necessary (or not? discuss)
46
+ [ ] Implement collections to leverage redis commands such as mget, mset, etc.
47
+ [ ] Implement value transformers (read and write) to make reusing types with specially encoded objects easy
48
+
49
+
35
50
  ## Contributing
36
51
 
37
52
  Bug reports and pull requests are welcome on GitHub at https://github.com/npepinpe/redstruct.
data/Rakefile CHANGED
@@ -9,10 +9,10 @@ Rake::TestTask.new(:test) do |t|
9
9
  t.test_files = FileList['test/**/*_test.rb']
10
10
  end
11
11
 
12
- task :default => :test
12
+ task default: :test
13
13
 
14
- require 'redstruct/yard/defscript_handler'
14
+ require 'yard/defscript_handler'
15
15
  YARD::Rake::YardocTask.new do |t|
16
- t.files = ['lib/**/*.rb']
17
- t.options = ['--output-dir=./docs']
16
+ t.files = ['lib/**/*.rb']
17
+ t.options = ['--output-dir=./docs']
18
18
  end
@@ -10,17 +10,35 @@ module Redstruct
10
10
  @pool = pool
11
11
  end
12
12
 
13
+ # Executes the given block by first fixing a thread local connection from the pool,
14
+ # such that all redis commands executed within the block are on the same connection.
15
+ # This is necessary when doing pipelining, or multi/exec stuff
16
+ # @return [Object] whatever the passed block evaluates to, nil otherwise
17
+ def with
18
+ result = nil
19
+ @pool.with do |c|
20
+ begin
21
+ Thread.current[:__redstruct_connection] = c
22
+ result = yield(c) if block_given?
23
+ ensure
24
+ Thread.current[:__redstruct_connection] = nil
25
+ end
26
+ end
27
+
28
+ return result
29
+ end
30
+
13
31
  # While slower on load, defining all methods that we want to pipe to one of the connections results in
14
32
  # faster calls at runtime, and gives us the convenience of not going through the pool.with everytime.
15
33
  Redis.public_instance_methods(false).each do |method|
16
34
  next if NON_COMMAND_METHODS.include?(method)
17
35
  class_eval <<~METHOD, __FILE__, __LINE__ + 1
18
- def #{method}(*args)
36
+ def #{method}(*args, &block)
19
37
  connection = Thread.current[:__redstruct_connection]
20
38
  if connection.nil?
21
- return @pool.with { |c| c.#{method}(*args) }
39
+ with { |c| c.#{method}(*args, &block) }
22
40
  else
23
- return connection.#{method}(*args)
41
+ return connection.#{method}(*args, &block)
24
42
  end
25
43
  end
26
44
  METHOD
@@ -15,17 +15,6 @@ module Redstruct
15
15
  @key = key
16
16
  end
17
17
 
18
- def with
19
- self.connection.pool.with do |c|
20
- begin
21
- Thread.current[:__redstruct_connection] = c
22
- yield(c)
23
- ensure
24
- Thread.current[:__redstruct_connection] = nil
25
- end
26
- end
27
- end
28
-
29
18
  def to_h
30
19
  return { key: @key }
31
20
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Redstruct
2
3
  module Types
3
4
  # Note: keep in mind Redis converts everything to a string on the DB side
@@ -7,7 +8,8 @@ module Redstruct
7
8
  end
8
9
 
9
10
  def random(count: 1)
10
- return self.connection.srandmember(@key, count.to_i)
11
+ list = self.connection.srandmember(@key, count)
12
+ return count == 1 ? list[0] : Set.new(list)
11
13
  end
12
14
 
13
15
  def empty?
@@ -69,7 +71,8 @@ module Redstruct
69
71
  end
70
72
 
71
73
  def pop(count: 1)
72
- return self.connection.spop(@key, count.to_i)
74
+ list = self.connection.spop(@key, count)
75
+ return count == 1 ? list[0] : Set.new(list)
73
76
  end
74
77
 
75
78
  def remove(*members)
@@ -86,8 +89,6 @@ module Redstruct
86
89
  @factory.set(dest)
87
90
  when self.class
88
91
  dest
89
- else
90
- nil
91
92
  end
92
93
  end
93
94
  private :coerce_destination
@@ -15,18 +15,35 @@ module Redstruct
15
15
  self.connection.del(@key)
16
16
  end
17
17
 
18
- def expire(ttl)
19
- self.connection.expire(@key, ttl)
18
+ # Sets the key to expire after ttl seconds
19
+ # @param [Integer, #to_i] ttl the time to live in seconds (or milliseconds if ms is true)
20
+ # @param [Boolean] ms if true, assumes ttl is in milliseconds
21
+ def expire(ttl, ms: false)
22
+ if ms
23
+ self.connection.pexpire(@key, ttl.to_i)
24
+ else
25
+ self.connection.expire(@key, ttl.to_i)
26
+ end
20
27
  end
21
28
 
22
- def expire_at(time)
23
- self.connection.expire_at(@key, time.to_i)
29
+ # Sets the key to expire at the given timestamp.
30
+ # @param [Time, Integer, #to_i] time time or unix timestamp at which the key should expire
31
+ # @param [Boolean] ms if true, assumes the timestamp is in milliseconds
32
+ def expire_at(time, ms: false)
33
+ if ms
34
+ time = (time.to_f * 1000) if time.is_a?(Time)
35
+ self.connection.pexpire_at(@key, time.to_i)
36
+ else
37
+ self.connection.expire_at(@key, time.to_i)
38
+ end
24
39
  end
25
40
 
41
+ # Removes the expiry time from a key
26
42
  def persist
27
43
  self.connection.persist(@key)
28
44
  end
29
45
 
46
+ # @return [String] the underlying redis type
30
47
  def type
31
48
  self.connection.type(@key)
32
49
  end
@@ -1,3 +1,3 @@
1
1
  module Redstruct
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'logger'
2
+
3
+ module Releaser
4
+ class Logger < ::Logger
5
+ TAG = '[RELEASER]'.freeze
6
+
7
+ def info(message)
8
+ super(TAG) { message }
9
+ end
10
+
11
+ def error(message)
12
+ super(TAG) { message }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ require 'english'
2
+
3
+ module Releaser
4
+ class Repository
5
+ attr_reader :path
6
+
7
+ def initialize(path = '.')
8
+ @path = File.expand_path(path)
9
+ raise(Error, 'Unreadable path given') unless File.readable?(@path)
10
+ raise(Error, 'Repository is not a directory') unless File.directory?(@path)
11
+ raise(Error, 'Repository is not a github repository') unless git?
12
+ end
13
+
14
+ def git?
15
+ File.directory?("#{@path}/.git")
16
+ end
17
+
18
+ def clean?
19
+ committed = `git status -s`.chomp.strip.empty?
20
+ pushed = `git log origin/master..HEAD`.chomp.strip.empty?
21
+
22
+ return committed && pushed
23
+ end
24
+
25
+ def fetch_remote_tags
26
+ `git fetch --tags`
27
+ return $CHILD_STATUS.success?
28
+ end
29
+
30
+ class Error < StandardError; end
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require 'releaser/repository'
2
+
3
+ repo = Releaser::Repository.new
4
+ logger = Releaser::Logger.new($stdout)
5
+
6
+ namespace :releaser do
7
+ namespace :repo do
8
+ desc 'Updates README, CHANGELOG, tags the release'
9
+ task :release do
10
+ unless repo.clean?
11
+ logger.error('Uncommitted/unpushed changes detected; aborting')
12
+ exit(-1)
13
+ end
14
+
15
+ repo.fetch_remote_tags
16
+
17
+ tasks = [:update_version, :update_readme, :update_changelog, :update_tags]
18
+ tasks.each do |task|
19
+ Rake::Task[task].invoke
20
+ end
21
+
22
+ repo.synchronize
23
+ end
24
+
25
+ desc 'Updates the current version'
26
+ task :update_version do
27
+
28
+ end
29
+
30
+ desc 'Updates the README'
31
+ task :update_readme do
32
+ end
33
+
34
+ desc 'Updates the CHANGELOG'
35
+ task :update_changelog do
36
+ end
37
+
38
+ desc 'Tags release'
39
+ task :tag do
40
+ end
41
+ end
42
+
43
+ namespace :gem do
44
+ desc 'Ensures repo version exists, builds the gem, and pushes it'
45
+ task :release do
46
+
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redstruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Pepin-Perreault
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-09 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.3.2
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '3.3'
22
+ version: '4'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.3.2
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '3.3'
32
+ version: '4'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: connection_pool
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +119,10 @@ files:
113
119
  - lib/redstruct/utils/inspectable.rb
114
120
  - lib/redstruct/utils/scriptable.rb
115
121
  - lib/redstruct/version.rb
116
- - lib/redstruct/yard/defscript_handler.rb
122
+ - lib/releaser/logger.rb
123
+ - lib/releaser/repository.rb
124
+ - lib/tasks/release.rake
125
+ - lib/yard/defscript_handler.rb
117
126
  - test/redstruct/restruct_test.rb
118
127
  - test/test_helper.rb
119
128
  homepage: https://npepinpe.github.com/redstruct/
@@ -136,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
145
  version: '0'
137
146
  requirements: []
138
147
  rubyforge_project:
139
- rubygems_version: 2.6.6
148
+ rubygems_version: 2.5.1
140
149
  signing_key:
141
150
  specification_version: 4
142
151
  summary: Higher level data structures for Redis.
File without changes