session_tracker 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -1
- data/lib/session_tracker/version.rb +1 -1
- data/lib/session_tracker.rb +8 -4
- data/session_tracker.gemspec +1 -0
- data/spec/session_tracker_spec.rb +14 -2
- metadata +39 -30
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c480cf71c5562f63dfe48952dfa162642a932814b64d6662e6e280a6f3307aa
|
4
|
+
data.tar.gz: 40f1e2363a5ca2fd85b02f97e74d538cd91a56226990e2fe96c03b7c4c5ce12d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: adefd6065a1a1be8e2abc963fce83f1a0ec9b917c964d9e1cb0bab8707ec85157dc03ec38593e90c536d63dbd78c07041950f0ebcc7c4b8169e289d246ecc067
|
7
|
+
data.tar.gz: a0a2757a7ffd6979efa65d882dca5c99221891738ab7588881a90abc8974213b4b4d7dd11ea03e41cca186aa64804e30cd0f18dcf31caaae21afd58d38689f71
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SessionTracker
|
2
2
|
|
3
|
-
Track active sessions in redis.
|
3
|
+
Track active users sessions in redis.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -32,6 +32,8 @@ Then to view the current state:
|
|
32
32
|
|
33
33
|
If redis is accessible through $redis, you don't have to give it as an argument to SessionTracker.new.
|
34
34
|
|
35
|
+
Read the spec and/or code to see how it works.
|
36
|
+
|
35
37
|
## Contributing
|
36
38
|
|
37
39
|
1. Fork it
|
data/lib/session_tracker.rb
CHANGED
@@ -18,14 +18,18 @@ class SessionTracker
|
|
18
18
|
# so we don't want to raise errors just because redis is down for a few seconds.
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
@redis.sunion(*
|
21
|
+
def active_users_data(timespan_in_minutes, time)
|
22
|
+
@redis.sunion(*keys_within(timespan_in_minutes, time))
|
23
|
+
end
|
24
|
+
|
25
|
+
def active_users(timespan_in_minutes = 5, time = Time.now)
|
26
|
+
active_users_data(timespan_in_minutes, time).size
|
23
27
|
end
|
24
28
|
|
25
29
|
private
|
26
30
|
|
27
|
-
def
|
28
|
-
times = 0.upto(
|
31
|
+
def keys_within(minutes, time)
|
32
|
+
times = 0.upto(minutes - 1).map { |n| time - (n * 60) }
|
29
33
|
times.map { |t| key_for(t) }
|
30
34
|
end
|
31
35
|
|
data/session_tracker.gemspec
CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.description = %q{Track active user sessions in redis}
|
9
9
|
gem.summary = %q{Track active user sessions in redis}
|
10
10
|
gem.homepage = ""
|
11
|
+
gem.metadata = { "rubygems_mfa_required" => "true" }
|
11
12
|
|
12
13
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
13
14
|
gem.files = `git ls-files`.split("\n")
|
@@ -44,14 +44,26 @@ describe SessionTracker, "active_users" do
|
|
44
44
|
|
45
45
|
let(:redis) { mock.as_null_object }
|
46
46
|
|
47
|
-
it "should do a union on the
|
47
|
+
it "should do a union on the specified timespan to get a active user count" do
|
48
48
|
time = Time.parse("13:09")
|
49
49
|
redis.should_receive(:sunion).with("active_customer_sessions_minute_09",
|
50
50
|
"active_customer_sessions_minute_08",
|
51
51
|
"active_customer_sessions_minute_07").
|
52
52
|
and_return([ mock, mock ])
|
53
53
|
|
54
|
-
SessionTracker.new("customer", redis).active_users(time).should == 2
|
54
|
+
SessionTracker.new("customer", redis).active_users(3, time).should == 2
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should use a default time span of 5 minutes" do
|
58
|
+
redis.should_receive(:sunion).with(anything, anything, anything,
|
59
|
+
anything, anything).and_return([ mock, mock ])
|
60
|
+
|
61
|
+
SessionTracker.new("customer", redis).active_users.should == 2
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be possible to access the data" do
|
65
|
+
redis.should_receive(:sunion).and_return([ :d1, :d2 ])
|
66
|
+
SessionTracker.new("customer", redis).active_users_data(3, Time.now).should == [ :d1, :d2 ]
|
55
67
|
end
|
56
68
|
|
57
69
|
end
|
metadata
CHANGED
@@ -1,60 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: session_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joakim Kolsjö
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: guard
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: guard-rspec
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
description: Track active user sessions in redis
|
59
70
|
email:
|
60
71
|
- joakim.kolsjo@gmail.com
|
@@ -62,8 +73,8 @@ executables: []
|
|
62
73
|
extensions: []
|
63
74
|
extra_rdoc_files: []
|
64
75
|
files:
|
65
|
-
- .gitignore
|
66
|
-
- .rvmrc
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rvmrc"
|
67
78
|
- Gemfile
|
68
79
|
- Guardfile
|
69
80
|
- README.md
|
@@ -74,27 +85,25 @@ files:
|
|
74
85
|
- spec/session_tracker_spec.rb
|
75
86
|
homepage: ''
|
76
87
|
licenses: []
|
88
|
+
metadata:
|
89
|
+
rubygems_mfa_required: 'true'
|
77
90
|
post_install_message:
|
78
91
|
rdoc_options: []
|
79
92
|
require_paths:
|
80
93
|
- lib
|
81
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
95
|
requirements:
|
84
|
-
- -
|
96
|
+
- - ">="
|
85
97
|
- !ruby/object:Gem::Version
|
86
98
|
version: '0'
|
87
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
100
|
requirements:
|
90
|
-
- -
|
101
|
+
- - ">="
|
91
102
|
- !ruby/object:Gem::Version
|
92
103
|
version: '0'
|
93
104
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 1.8.5
|
105
|
+
rubygems_version: 3.2.31
|
96
106
|
signing_key:
|
97
|
-
specification_version:
|
107
|
+
specification_version: 4
|
98
108
|
summary: Track active user sessions in redis
|
99
|
-
test_files:
|
100
|
-
- spec/session_tracker_spec.rb
|
109
|
+
test_files: []
|