valkey-objects 0.2.7 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/valkey/objects/version.rb +1 -1
- data/lib/valkey/objects.rb +30 -48
- data/valkey-objects.gemspec +1 -0
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c9ee2ffcc565ef127499ebbca13af2561bc8cf20b624d951b279f698ecd2363
|
4
|
+
data.tar.gz: 5408e161d38630e5d60eed393a4f053b57bb2bd4d9868fcb45792fb0f33f1683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 503fa253eb7d383b88d8aa4a9efca028f1a181e9c6aa14925ea4eefc99938538073a964c164e70832962a6b136294258abc8482029c04c1b9d9b4650047191fb
|
7
|
+
data.tar.gz: 7eebd37730a11425a5f1b3917492f9c5c437fc40c18f995a83c1d71555a47eee1bd00265a3e8bbeff51999e6b58883ef55e21297b02b32ee119702cc0c1453ef
|
data/lib/valkey/objects.rb
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative "objects/version"
|
4
4
|
|
5
|
-
require 'connection_pool'
|
5
|
+
#require 'connection_pool'
|
6
6
|
require 'redis-client'
|
7
7
|
require 'json'
|
8
|
-
require 'ruby-duration'
|
9
8
|
require 'amatch'
|
10
9
|
require 'ap'
|
10
|
+
require 'yaml'
|
11
|
+
|
11
12
|
module VK
|
12
13
|
|
13
14
|
@@XX = {}
|
@@ -183,57 +184,30 @@ module VK
|
|
183
184
|
@id
|
184
185
|
end
|
185
186
|
|
186
|
-
module AGO
|
187
|
-
class Error < StandardError; end
|
188
|
-
class Clock
|
189
|
-
def initialize t
|
190
|
-
@t = AGO.now
|
191
|
-
@s = @t.to_i - t.to_i
|
192
|
-
@t = Time.new(t.to_i).utc
|
193
|
-
@d = Duration.new(@s.abs)
|
194
|
-
end
|
195
|
-
def to_i
|
196
|
-
@s
|
197
|
-
end
|
198
|
-
def to_s *s
|
199
|
-
if s[0]
|
200
|
-
@d.format(s[0])
|
201
|
-
else
|
202
|
-
@d.format('%w %~w %d %~d %H:%M:%S')
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
def self.now
|
207
|
-
Time.now.utc
|
208
|
-
end
|
209
|
-
def self.[] k
|
210
|
-
Clock.new(k)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
187
|
def self.at epoch
|
215
188
|
Time.at epoch
|
216
189
|
end
|
217
190
|
|
218
191
|
def self.clock *t
|
219
192
|
if t[0]
|
220
|
-
|
193
|
+
Time.now.utc.to_i - t[0].to_i
|
221
194
|
else
|
222
|
-
|
195
|
+
Time.now.utc.to_i
|
223
196
|
end
|
224
197
|
end
|
225
198
|
|
226
199
|
def self.redis
|
227
|
-
|
200
|
+
#@redis ||= ConnectionPool::Wrapper.new do
|
228
201
|
RedisClient.config(host: "127.0.0.1", port: 6379, db: 0).new_client
|
229
|
-
end
|
202
|
+
#end
|
230
203
|
end
|
231
204
|
|
232
205
|
class O
|
233
206
|
attr_reader :key
|
234
207
|
def initialize k, h={}
|
235
208
|
@key = k
|
236
|
-
@opts = h
|
209
|
+
@opts = h
|
210
|
+
# puts %[VK #{@key} #{h}]
|
237
211
|
if @opts.has_key?(:ttl)
|
238
212
|
expire @opts[:ttl]
|
239
213
|
end
|
@@ -244,16 +218,16 @@ module VK
|
|
244
218
|
def expire sec
|
245
219
|
VK.redis.call("EXPIRE", key, sec);
|
246
220
|
end
|
247
|
-
end
|
248
|
-
|
249
|
-
class TIMESTAMP < O
|
250
221
|
def value
|
251
222
|
x = VK.redis.call("GET", key);
|
252
223
|
if @opts.has_key?(:flush) == true
|
253
224
|
delete!
|
254
225
|
end
|
255
226
|
return x
|
256
|
-
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
class TIMESTAMP < O
|
257
231
|
def value!
|
258
232
|
VK.redis.call("SET", key, "#{VK.clock.to_i}");
|
259
233
|
end
|
@@ -270,10 +244,11 @@ module VK
|
|
270
244
|
|
271
245
|
class TOGGLE < O
|
272
246
|
def value
|
273
|
-
VK.redis.call("GET", key) == 'true' ? true : false
|
247
|
+
x = VK.redis.call("GET", key) == 'true' ? true : false
|
274
248
|
if @opts.has_key?(:flush) == true
|
275
249
|
delete!
|
276
250
|
end
|
251
|
+
return x
|
277
252
|
end
|
278
253
|
def exist?
|
279
254
|
VK.redis.call("GET", key) ? true : false
|
@@ -282,7 +257,7 @@ module VK
|
|
282
257
|
VK.redis.call("SET", key, "#{x.to_s}")
|
283
258
|
end
|
284
259
|
def value!
|
285
|
-
if self.value
|
260
|
+
if self.value == true || self.value == nil
|
286
261
|
self.value = false
|
287
262
|
else
|
288
263
|
self.value = true
|
@@ -292,10 +267,11 @@ module VK
|
|
292
267
|
|
293
268
|
class VALUE < O
|
294
269
|
def value
|
295
|
-
VK.redis.call("GET", key)
|
270
|
+
x = VK.redis.call("GET", key)
|
296
271
|
if @opts.has_key?(:flush) == true
|
297
272
|
delete!
|
298
273
|
end
|
274
|
+
return x.to_f
|
299
275
|
end
|
300
276
|
def value= x
|
301
277
|
VK.redis.call("SET", key, x)
|
@@ -340,6 +316,11 @@ module VK
|
|
340
316
|
VK.redis.call("SET", kk, i);
|
341
317
|
VK.redis.call("RPUSH", key, kk)
|
342
318
|
end
|
319
|
+
def []= k,v
|
320
|
+
kk = %[#{@key}-#{k}]
|
321
|
+
VK.redis.call("SET", kk, v)
|
322
|
+
VK.redis.call("RPUSH", key, kk);
|
323
|
+
end
|
343
324
|
def nearest p
|
344
325
|
h = {}
|
345
326
|
value { |i,v|
|
@@ -361,22 +342,23 @@ module VK
|
|
361
342
|
|
362
343
|
class COUNTER < O
|
363
344
|
def incr n
|
364
|
-
VK.redis.call("SET", key, value + n.to_f)
|
345
|
+
VK.redis.call("SET", @key, value + n.to_f)
|
365
346
|
end
|
366
347
|
def decr n
|
367
|
-
VK.redis.call("SET", key, value + n.to_f)
|
348
|
+
VK.redis.call("SET", @key, value + n.to_f)
|
368
349
|
end
|
369
350
|
def value
|
370
|
-
VK.redis.call("GET", key).to_f
|
351
|
+
x = VK.redis.call("GET", @key).to_f
|
371
352
|
if @opts.has_key?(:flush) == true
|
372
353
|
delete!
|
373
|
-
end
|
354
|
+
end
|
355
|
+
return x
|
374
356
|
end
|
375
357
|
def value= n
|
376
|
-
VK.redis.call("SET", key, n.to_f)
|
358
|
+
VK.redis.call("SET", @key, n.to_f)
|
377
359
|
end
|
378
360
|
def exist?
|
379
|
-
VK.redis.call("GET", key) ? true : false
|
361
|
+
VK.redis.call("GET", @key) ? true : false
|
380
362
|
end
|
381
363
|
end
|
382
364
|
|
data/valkey-objects.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valkey-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Olson
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-
|
10
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: redis-client
|
@@ -117,7 +116,6 @@ metadata:
|
|
117
116
|
homepage_uri: https://github.com/xorgnak/valkey-client
|
118
117
|
source_code_uri: https://github.com/xorgnak/valkey-client
|
119
118
|
changelog_uri: https://github.com/xorgnak/valkey-client
|
120
|
-
post_install_message:
|
121
119
|
rdoc_options: []
|
122
120
|
require_paths:
|
123
121
|
- lib
|
@@ -132,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
130
|
- !ruby/object:Gem::Version
|
133
131
|
version: '0'
|
134
132
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
136
|
-
signing_key:
|
133
|
+
rubygems_version: 3.6.3
|
137
134
|
specification_version: 4
|
138
135
|
summary: A ruby valkey client inspired by the redis-objects gem.
|
139
136
|
test_files: []
|