lite-redis 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/CHANGELOG.md +6 -20
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +29 -29
  6. data/README.md +12 -19
  7. data/Rakefile +2 -2
  8. data/bin/console +3 -3
  9. data/docs/CONNECTION.md +8 -4
  10. data/docs/GEO.md +8 -4
  11. data/docs/HASH.md +8 -4
  12. data/docs/HYPER_LOG_LOG.md +7 -3
  13. data/docs/KEY.md +7 -3
  14. data/docs/LIST.md +7 -3
  15. data/docs/PUB_SUB.md +6 -2
  16. data/docs/SCRIPT.md +7 -3
  17. data/docs/SET.md +7 -3
  18. data/docs/SORTED_SET.md +8 -4
  19. data/docs/STRING.md +7 -3
  20. data/docs/TRANSACTION.md +8 -4
  21. data/lib/generators/lite/redis/install_generator.rb +2 -2
  22. data/lib/lite/redis/base.rb +53 -2
  23. data/lib/lite/redis/configuration.rb +2 -0
  24. data/lib/lite/redis/connection.rb +96 -3
  25. data/lib/lite/redis/geo.rb +24 -3
  26. data/lib/lite/redis/hash.rb +60 -3
  27. data/lib/lite/redis/hyper_log_log.rb +12 -3
  28. data/lib/lite/redis/key.rb +86 -3
  29. data/lib/lite/redis/list.rb +124 -3
  30. data/lib/lite/redis/pub_sub.rb +36 -3
  31. data/lib/lite/redis/railtie.rb +1 -1
  32. data/lib/lite/redis/script.rb +12 -3
  33. data/lib/lite/redis/set.rb +60 -3
  34. data/lib/lite/redis/sorted_set.rb +127 -3
  35. data/lib/lite/redis/string.rb +87 -3
  36. data/lib/lite/redis/transaction.rb +20 -3
  37. data/lib/lite/redis/version.rb +1 -1
  38. data/lib/lite/redis.rb +17 -32
  39. data/lib/tasks/redis.rake +10 -10
  40. data/lite-redis.gemspec +27 -34
  41. metadata +7 -16
  42. data/lib/lite/redis/helpers/base_helper.rb +0 -41
  43. data/lib/lite/redis/helpers/connection_helper.rb +0 -105
  44. data/lib/lite/redis/helpers/geo_helper.rb +0 -33
  45. data/lib/lite/redis/helpers/hash_helper.rb +0 -69
  46. data/lib/lite/redis/helpers/hyper_log_log_helper.rb +0 -21
  47. data/lib/lite/redis/helpers/key_helper.rb +0 -95
  48. data/lib/lite/redis/helpers/list_helper.rb +0 -133
  49. data/lib/lite/redis/helpers/pub_sub_helper.rb +0 -45
  50. data/lib/lite/redis/helpers/script_helper.rb +0 -21
  51. data/lib/lite/redis/helpers/set_helper.rb +0 -69
  52. data/lib/lite/redis/helpers/sorted_set_helper.rb +0 -136
  53. data/lib/lite/redis/helpers/string_helper.rb +0 -96
  54. data/lib/lite/redis/helpers/transaction_helper.rb +0 -29
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module HashHelper
6
-
7
- def find(key, field)
8
- client.hget(key.to_s, field)
9
- end
10
-
11
- def find_each(key, *args)
12
- client.hmget(key.to_s, *args)
13
- end
14
-
15
- def all(key)
16
- client.hgetall(key.to_s)
17
- end
18
-
19
- def keys(key)
20
- client.hkeys(key.to_s)
21
- end
22
-
23
- def values(key)
24
- client.hvals(key.to_s)
25
- end
26
-
27
- def value_length(key, field)
28
- client.hstrlen(key.to_s, field)
29
- end
30
-
31
- def count(key)
32
- client.hlen(key.to_s)
33
- end
34
-
35
- def exists?(key, field)
36
- client.hexists(key.to_s, field)
37
- end
38
-
39
- def create(key, field, value)
40
- client.hset(key.to_s, field, value)
41
- end
42
-
43
- def create!(key, field, value)
44
- client.hsetnx(key.to_s, field, value)
45
- end
46
-
47
- def create_each(key, *args)
48
- client.hmset(key.to_s, *args)
49
- end
50
-
51
- def increment(key, field, value)
52
- if value.is_a?(Float)
53
- client.hincrbyfloat(key.to_s, field, value)
54
- else
55
- client.hincrby(key.to_s, field, value)
56
- end
57
- end
58
-
59
- def destroy(key, *args)
60
- client.hdel(key.to_s, *args)
61
- end
62
-
63
- def scan(key, cursor, opts = {})
64
- client.hdel(key.to_s, cursor, **opts)
65
- end
66
-
67
- end
68
- end
69
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module HyperLogLogHelper
6
-
7
- def create(key, member)
8
- client.pfadd(key.to_s, member)
9
- end
10
-
11
- def count(*args)
12
- client.pfcount(*args)
13
- end
14
-
15
- def merge(key, *keys)
16
- client.pfmerge(key.to_s, *keys)
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module KeyHelper
6
-
7
- def exists?(key)
8
- client.exists(key.to_s)
9
- end
10
-
11
- def type?(key)
12
- client.type(key.to_s)
13
- end
14
-
15
- def ttl?(key, format = :seconds)
16
- if seconds?(format)
17
- client.ttl(key.to_s)
18
- else
19
- client.pttl(key.to_s)
20
- end
21
- end
22
-
23
- def sort(key, opts = {})
24
- client.sort(key.to_s, **opts)
25
- end
26
-
27
- def sample
28
- client.randomkey
29
- end
30
-
31
- def rename(key, value)
32
- client.rename(key.to_s, value.to_s)
33
- end
34
-
35
- def rename!(key, value)
36
- client.renamenx(key.to_s, value.to_s)
37
- end
38
-
39
- def destroy(key)
40
- client.del(key.to_s)
41
- end
42
-
43
- def persist(key)
44
- client.persist(key.to_s)
45
- end
46
-
47
- def expire(key, seconds, format = :seconds)
48
- if seconds?(format)
49
- client.expire(key.to_s, seconds)
50
- else
51
- client.pexpire(key.to_s, seconds)
52
- end
53
- end
54
-
55
- alias expire_in expire
56
-
57
- def expire_at(key, seconds, format = :seconds)
58
- if seconds?(format)
59
- client.expireat(key.to_s, seconds)
60
- else
61
- client.pexpireat(key.to_s, seconds)
62
- end
63
- end
64
-
65
- def dump(key)
66
- client.dump(key.to_s)
67
- end
68
-
69
- def match(pattern = '*')
70
- client.keys(pattern.to_s)
71
- end
72
-
73
- def migrate(key, options)
74
- client.migrate(key.to_s, options)
75
- end
76
-
77
- def move(key, destination)
78
- client.move(key.to_s, destination)
79
- end
80
-
81
- def object(*args)
82
- client.object(*args)
83
- end
84
-
85
- def restore(key, milliseconds, value)
86
- client.restore(key.to_s, milliseconds, value)
87
- end
88
-
89
- def scan(cursor, opts = {})
90
- client.scan(cursor, **opts)
91
- end
92
-
93
- end
94
- end
95
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module ListHelper
6
-
7
- def find(key, position = 1)
8
- client.lindex(key.to_s, position - 1)
9
- end
10
-
11
- def first(key, limit = 1)
12
- value = client.lrange(key.to_s, 0, -1)
13
- return value.first if limit == 1
14
-
15
- value.first(limit)
16
- end
17
-
18
- def last(key, limit = 1)
19
- value = client.lrange(key.to_s, 0, -1)
20
- return value.last if limit == 1
21
-
22
- value.last(limit)
23
- end
24
-
25
- def between(key, start = 1, finish = 0)
26
- client.lrange(key.to_s, start - 1, finish - 1)
27
- end
28
-
29
- def all(key)
30
- client.lrange(key.to_s, 0, -1)
31
- end
32
-
33
- def count(key)
34
- client.llen(key.to_s)
35
- end
36
-
37
- def create(key, value, order = :prepend)
38
- if append?(order)
39
- client.rpush(key.to_s, value)
40
- else
41
- client.lpush(key.to_s, value)
42
- end
43
- end
44
-
45
- def create!(key, value, order = :prepend)
46
- if append?(order)
47
- client.rpushx(key.to_s, value)
48
- else
49
- client.lpushx(key.to_s, value)
50
- end
51
- end
52
-
53
- def create_limit(key, value, limit, order = :prepend)
54
- if append?(order)
55
- client.rpush(key.to_s, value)
56
- else
57
- client.lpush(key.to_s, value)
58
- end
59
-
60
- client.ltrim(key.to_s, 0, limit - 1)
61
- end
62
-
63
- def create_limit!(key, value, limit, order = :prepend)
64
- if append?(order)
65
- client.rpushx(key.to_s, value)
66
- else
67
- client.lpushx(key.to_s, value)
68
- end
69
-
70
- client.ltrim(key.to_s, 0, limit - 1)
71
- end
72
-
73
- def create_before(key, pivot, value)
74
- client.linsert(key.to_s, :before, pivot, value)
75
- end
76
-
77
- def create_after(key, pivot, value)
78
- client.linsert(key.to_s, :after, pivot, value)
79
- end
80
-
81
- def update(key, index, value)
82
- client.lset(key.to_s, index, value)
83
- end
84
-
85
- def move(key, desination)
86
- client.rpoplpush(key.to_s, desination.to_s)
87
- end
88
-
89
- def move_blocking(key, desination)
90
- brpoplpush(key.to_s, desination.to_s)
91
- end
92
-
93
- def destroy(key, count, value)
94
- client.lrem(key.to_s, count, value)
95
- end
96
-
97
- def destroy_first(key, limit = 1)
98
- client.ltrim(key.to_s, limit, -1)
99
- end
100
-
101
- def destroy_last(key, limit = 1)
102
- client.ltrim(key.to_s, 0, -(limit + 1))
103
- end
104
-
105
- def destroy_except(key, start, finish)
106
- client.ltrim(key.to_s, start - 1, finish - 1)
107
- end
108
-
109
- def destroy_all(key)
110
- client.ltrim(key.to_s, -1, 0)
111
- end
112
-
113
- def pop(key, order = :prepend)
114
- if append?(order)
115
- client.rpop(key)
116
- else
117
- client.lpop(key)
118
- end
119
- end
120
-
121
- def pop_blocking(keys, opts = {})
122
- timeout = opts[:timeout] || 0
123
-
124
- if append?(opts[:order] || :prepend)
125
- client.brpop(keys, timeout)
126
- else
127
- client.blpop(keys, timeout)
128
- end
129
- end
130
-
131
- end
132
- end
133
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module PubSubHelper
6
-
7
- def publish(channel, message)
8
- client.publish(channel, message)
9
- end
10
-
11
- def subscribed?
12
- client.subscribed?
13
- end
14
-
15
- def subscribe(*channels, timeout: nil, &block)
16
- if timeout.nil?
17
- client.subscribe(*channels, &block)
18
- else
19
- client.subscribe_with_timeout(timeout, *channels, &block)
20
- end
21
- end
22
-
23
- def unsubscribe(*channels)
24
- client.unsubscribe(*channels)
25
- end
26
-
27
- def match_subscribe(*channels, timeout: nil, &block)
28
- if timeout.nil?
29
- client.psubscribe(*channels, &block)
30
- else
31
- client.psubscribe_with_timeout(timeout, *channels, &block)
32
- end
33
- end
34
-
35
- def match_unsubscribe(*channels)
36
- client.punsubscribe(*channels)
37
- end
38
-
39
- def state(command, *args)
40
- client.pubsub(command, *args)
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module ScriptHelper
6
-
7
- def script(command, *args)
8
- client.script(command, *args)
9
- end
10
-
11
- def eval(*args)
12
- client.eval(:eval, *args)
13
- end
14
-
15
- def evalsha(*args)
16
- client.eval(:evalsha, *args)
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module SetHelper
6
-
7
- def find(key)
8
- client.smembers(key.to_s)
9
- end
10
-
11
- def combine(*args)
12
- client.sunion(*args)
13
- end
14
-
15
- def difference(*args)
16
- client.sdiff(*args)
17
- end
18
-
19
- def intersection(key, *args)
20
- client.sinter(key.to_s, *args)
21
- end
22
-
23
- def sample(key, value = 1)
24
- client.srandmember(key.to_s, value)
25
- end
26
-
27
- def value?(key, value)
28
- client.sismember(key.to_s, value)
29
- end
30
-
31
- def count(key)
32
- client.scard(key.to_s)
33
- end
34
-
35
- def create(key, args)
36
- client.sadd(key.to_s, args)
37
- end
38
-
39
- def create_combination(key, *args)
40
- client.sunionstore(key.to_s, *args)
41
- end
42
-
43
- def create_difference(key, *args)
44
- client.sdiffstore(key.to_s, *args)
45
- end
46
-
47
- def create_intersection(key, *args)
48
- client.sinterstore(key.to_s, *args)
49
- end
50
-
51
- def move(key, destination, value)
52
- client.smove(key.to_s, destination.to_s, value)
53
- end
54
-
55
- def destroy(key, args)
56
- client.srem(key.to_s, args)
57
- end
58
-
59
- def destroy_random(key)
60
- client.spop(key.to_s)
61
- end
62
-
63
- def scan(key, cursor, opts = {})
64
- client.sscan(key.to_s, cursor, **opts)
65
- end
66
-
67
- end
68
- end
69
- end
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module SortedSetHelper
6
-
7
- def find(key, position, opts = {})
8
- position -= 1
9
- value = client.zrange(key.to_s, position, position, **opts)
10
- value.first
11
- end
12
-
13
- def find_score(key, position, opts = {})
14
- value = client.zrangebyscore(key.to_s, position, position, **opts)
15
- value.first
16
- end
17
-
18
- def first(key, opts = {})
19
- value = client.zrange(key.to_s, 0, 0, **opts)
20
- value.first
21
- end
22
-
23
- def first_score(key, opts = {})
24
- value = client.zrangebyscore(key.to_s, 1, 1, **opts)
25
- value.first
26
- end
27
-
28
- def last(key, opts = {})
29
- value = client.zrevrange(key.to_s, 0, 0, **opts)
30
- value.first
31
- end
32
-
33
- def last_score(key, opts = {})
34
- value = client.zrevrangebyscore(key.to_s, 1, 1, **opts)
35
- value.first
36
- end
37
-
38
- def between(key, start, finish, opts = {})
39
- client.zrange(key.to_s, start - 1, finish - 1, **opts)
40
- end
41
-
42
- def between_reverse(key, start, finish, opts = {})
43
- client.zrevrange(key.to_s, start - 1, finish - 1, **opts)
44
- end
45
-
46
- def between_scores(key, min, max, opts = {})
47
- client.zrangebyscore(key.to_s, min, max, **opts)
48
- end
49
-
50
- def between_scores_reverse(key, min, max, opts = {})
51
- client.zrevrangebyscore(key.to_s, min, max, **opts)
52
- end
53
-
54
- def between_lex(key, min, max, opts = {})
55
- client.zrangebylex(key.to_s, min, max, **opts)
56
- end
57
-
58
- def between_lex_reverse(key, min, max, opts = {})
59
- client.zrevrangebylex(key.to_s, min, max, **opts)
60
- end
61
-
62
- def all(key, opts = {})
63
- client.zrange(key.to_s, 0, -1, **opts)
64
- end
65
-
66
- def all_reverse(key, opts = {})
67
- client.zrevrange(key.to_s, 0, -1, **opts)
68
- end
69
-
70
- def position(key, value)
71
- value = client.zrank(key.to_s, value)
72
- value += 1 unless value.nil?
73
- value
74
- end
75
-
76
- def position_reverse(key, value)
77
- value = client.zrevrank(key.to_s, value)
78
- value += 1 unless value.nil?
79
- value
80
- end
81
-
82
- def score(key, value)
83
- client.zscore(key.to_s, value)
84
- end
85
-
86
- def count(key)
87
- client.zcard(key.to_s)
88
- end
89
-
90
- def count_between(key, min, max)
91
- client.zcount(key.to_s, min, max)
92
- end
93
-
94
- def create(key, *args)
95
- client.zadd(key.to_s, args)
96
- end
97
-
98
- def create_intersection(key, keys, opts = {})
99
- client.zinterstore(key.to_s, keys, **opts)
100
- end
101
-
102
- def create_combination(key, keys, opts = {})
103
- client.zunionstore(key.to_s, keys, **opts)
104
- end
105
-
106
- def increment(key, value, count)
107
- client.zincrby(key.to_s, count, value)
108
- end
109
-
110
- def decrement(key, value, count)
111
- client.zincrby(key.to_s, -count.abs, value)
112
- end
113
-
114
- def destroy(key, at)
115
- client.zrem(key.to_s, at)
116
- end
117
-
118
- def destroy_between(key, start, finish)
119
- client.zremrangebyrank(key.to_s, start - 1, finish - 1)
120
- end
121
-
122
- def destroy_scores(key, min, max)
123
- client.zremrangebyscore(key.to_s, min, max)
124
- end
125
-
126
- def destroy_lex(key, min, max, opts = {})
127
- client.zrevrangebylex(key.to_s, max, min, **opts)
128
- end
129
-
130
- def scan(key, cursor, opts = {})
131
- client.zscan(key.to_s, cursor, **opts)
132
- end
133
-
134
- end
135
- end
136
- end
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module StringHelper
6
-
7
- def find(key)
8
- client.get(key.to_s)
9
- end
10
-
11
- def find_each(*args)
12
- args = stringify_keys(*args)
13
- client.mget(args)
14
- end
15
-
16
- def length(key)
17
- client.strlen(key.to_s)
18
- end
19
-
20
- def split(key, start, finish)
21
- client.getrange(key.to_s, start, finish)
22
- end
23
-
24
- def create(key, value, opts = {})
25
- client.set(key.to_s, value, **opts)
26
- end
27
-
28
- def create!(key, value)
29
- client.setnx(key.to_s, value)
30
- end
31
-
32
- def create_each(*args)
33
- args = stringify_keys(*args)
34
- client.mset(args)
35
- end
36
-
37
- def create_each!(*args)
38
- args = stringify_keys(*args)
39
- client.msetnx(args)
40
- end
41
-
42
- def create_until(key, value, seconds, format = :seconds)
43
- if seconds?(format)
44
- client.setex(key.to_s, seconds, value)
45
- else
46
- client.psetex(key.to_s, seconds, value)
47
- end
48
- end
49
-
50
- def append(key, value)
51
- client.append(key.to_s, value)
52
- end
53
-
54
- def replace(key, value, offset)
55
- client.setrange(key.to_s, offset, value)
56
- end
57
-
58
- def decrement(key, value = 1)
59
- if value == 1
60
- client.decr(key.to_s)
61
- else
62
- client.decrby(key.to_s, value)
63
- end
64
- end
65
-
66
- def increment(key, value = 1)
67
- case value
68
- when Float then client.incrbyfloat(key.to_s, value)
69
- when 1 then client.incr(key.to_s)
70
- else client.incrby(key.to_s, value)
71
- end
72
- end
73
-
74
- def reset(key, value = 0)
75
- client.getset(key.to_s, value)
76
- end
77
-
78
- def bit_count(key, start = 0, finish = -1)
79
- client.bitcount(key.to_s, start, finish)
80
- end
81
-
82
- def bit_where(operation, key, *keys)
83
- client.bitop(operation, key, *keys)
84
- end
85
-
86
- def get_bit(key, offset)
87
- client.getbit(key.to_s, offset)
88
- end
89
-
90
- def set_bit(key, offset, bit)
91
- client.setbit(key.to_s, offset, bit)
92
- end
93
-
94
- end
95
- end
96
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Redis
5
- module TransactionHelper
6
-
7
- def discard
8
- client.discard
9
- end
10
-
11
- def exec
12
- client.exec
13
- end
14
-
15
- def multi(&block)
16
- client.multi(&block)
17
- end
18
-
19
- def watch(*args)
20
- client.watch(*args)
21
- end
22
-
23
- def unwatch
24
- client.unwatch
25
- end
26
-
27
- end
28
- end
29
- end