-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb_redis.rb
59 lines (50 loc) · 1.11 KB
/
pb_redis.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# encoding 'utf-8'
require 'redis'
require_relative 'pb_scrape'
require 'yaml'
class PBRedis
def initialize
path = __dir__
yml_path = path + '/config.yml'
config = YAML.load_file(yml_path)
@r_host = config['redis_host']
@redis = Redis.new(host: @r_host)
end
def check_redis(key, expire)
r_key_ex = @redis.exists(key)
if r_key_ex == false
@redis.setex(key, expire, 1)
@redis.disconnect!
@redis.quit
@res = false
else
# indicator that the key already exists in Redis
@redis.disconnect!
@redis.quit
@res = true
end
end
def quit_redis
@redis.quit
end
def redis_update
@to_write_array
end
def go
k = 'pastebin_key' # key
k_val = 1 # key value
ex = 20 # expire
@redis.setex(k, ex, k_val)
if @redis.exists(k)
puts("Key exists, move along as it's already been downloaded.")
end
sleep(10)
puts(@redis.exists(k))
sleep(10)
puts(@redis.exists(k))
sleep(10)
if @redis.exists(k) == false
puts('Key no longer exists, download from PB and insert key.')
end
end
end