-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathkv.rb
More file actions
45 lines (34 loc) · 1.02 KB
/
Copy pathkv.rb
File metadata and controls
45 lines (34 loc) · 1.02 KB
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
require File.expand_path("../example_setup", __FILE__)
require "github/kv"
# Create new instance using ActiveRecord's default connection.
kv = GitHub::KV.new { ActiveRecord::Base.connection }
# Get a key.
pp kv.get("foo")
#<GitHub::Result:0x3fd88cd3ea9c value: nil>
# Set a key.
kv.set("foo", "bar")
# nil
# Get the key again.
pp kv.get("foo")
#<GitHub::Result:0x3fe810d06e4c value: "bar">
# Get multiple keys at once.
pp kv.mget(["foo", "bar"])
#<GitHub::Result:0x3fccccd1b57c value: ["bar", nil]>
# Check for existence of a key.
pp kv.exists("foo")
#<GitHub::Result:0x3fd4ae55ce8c value: true>
# Check for existence of key that does not exist.
pp kv.exists("bar")
#<GitHub::Result:0x3fd4ae55c554 value: false>
# Check for existence of multiple keys at once.
pp kv.mexists(["foo", "bar"])
#<GitHub::Result:0x3ff1e98e18e8 value: [true, false]>
# Set a key's value if the key does not already exist.
pp kv.setnx("foo", "bar")
# false
# Delete a key.
pp kv.del("bar")
# nil
# Delete multiple keys at once.
pp kv.mdel(["foo", "bar"])
# nil