redcord 0.0.1.alpha → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redcord.rb +30 -2
- data/lib/redcord.rbi +0 -16
- data/lib/redcord/actions.rb +171 -40
- data/lib/redcord/attribute.rb +126 -21
- data/lib/redcord/base.rb +15 -0
- data/lib/redcord/configurations.rb +4 -0
- data/lib/redcord/logger.rb +1 -1
- data/lib/redcord/lua_script_reader.rb +16 -5
- data/lib/redcord/migration.rb +2 -0
- data/lib/redcord/migration/index.rb +57 -0
- data/lib/redcord/migration/migrator.rb +1 -1
- data/lib/redcord/migration/ttl.rb +9 -4
- data/lib/redcord/migration/version.rb +3 -0
- data/lib/redcord/railtie.rb +18 -0
- data/lib/redcord/redis.rb +200 -0
- data/lib/redcord/redis_connection.rb +38 -29
- data/lib/redcord/relation.rb +214 -38
- data/lib/redcord/serializer.rb +147 -49
- data/lib/redcord/server_scripts/create_hash.erb.lua +81 -0
- data/lib/redcord/server_scripts/delete_hash.erb.lua +17 -8
- data/lib/redcord/server_scripts/find_by_attr.erb.lua +50 -16
- data/lib/redcord/server_scripts/find_by_attr_count.erb.lua +45 -14
- data/lib/redcord/server_scripts/shared/index_helper_methods.erb.lua +45 -16
- data/lib/redcord/server_scripts/shared/lua_helper_methods.erb.lua +20 -4
- data/lib/redcord/server_scripts/shared/query_helper_methods.erb.lua +86 -14
- data/lib/redcord/server_scripts/update_hash.erb.lua +40 -26
- data/lib/redcord/tasks/redis.rake +15 -0
- data/lib/redcord/tracer.rb +48 -0
- data/lib/redcord/vacuum_helper.rb +90 -0
- metadata +13 -11
- data/lib/redcord/prepared_redis.rb +0 -18
- data/lib/redcord/server_scripts.rb +0 -78
- data/lib/redcord/server_scripts/create_hash_returning_id.erb.lua +0 -68
@@ -1,68 +0,0 @@
|
|
1
|
-
--[[
|
2
|
-
EVALSHA SHA1(__FILE__) [field value ...]
|
3
|
-
> Time complexity: O(N) where N is the number of fields being set.
|
4
|
-
|
5
|
-
Create a hash with the specified fields to their respective values stored at
|
6
|
-
key when key does not exist.
|
7
|
-
|
8
|
-
# Return value
|
9
|
-
The id of the created hash as a string.
|
10
|
-
--]]
|
11
|
-
|
12
|
-
-- The arguments can be accessed by Lua using the KEYS global variable in the
|
13
|
-
-- form of a one-based array (so KEYS[1], KEYS[2], ...).
|
14
|
-
-- All the additional arguments should not represent key names and can be
|
15
|
-
-- accessed by Lua using the ARGV global variable, very similarly to what
|
16
|
-
-- happens with keys (so ARGV[1], ARGV[2], ...).
|
17
|
-
|
18
|
-
-- KEYS[1] = Model.name
|
19
|
-
-- ARGV[1...2N] = attr_key attr_val [attr_key attr_val ..]
|
20
|
-
<%= include_lua 'shared/lua_helper_methods' %>
|
21
|
-
<%= include_lua 'shared/index_helper_methods' %>
|
22
|
-
|
23
|
-
-- Validate input to script before making Redis db calls
|
24
|
-
if #KEYS ~= 1 then
|
25
|
-
error('Expected keys to be of size 1')
|
26
|
-
end
|
27
|
-
if #ARGV % 2 ~= 0 then
|
28
|
-
error('Expected an even number of arguments')
|
29
|
-
end
|
30
|
-
|
31
|
-
local model = KEYS[1]
|
32
|
-
|
33
|
-
-- Call the Redis command: INCR "#{Model.name}:id_seq". If "#{Model.name}:id_seq" does
|
34
|
-
-- not exist, the command returns 0. It errors if the id_seq overflows a 64 bit
|
35
|
-
-- signed integer.
|
36
|
-
redis.call('incr', model .. ':id_seq')
|
37
|
-
|
38
|
-
-- The Lua version used by Redis does not support 64 bit integers:
|
39
|
-
-- https://github.com/antirez/redis/issues/5261
|
40
|
-
-- We ignore the integer response from INCR and use the string response from
|
41
|
-
-- the GET/MGET command.
|
42
|
-
local id, ttl = unpack(redis.call('mget', model .. ':id_seq', model .. ':ttl'))
|
43
|
-
local key = model .. ':id:' .. id
|
44
|
-
|
45
|
-
-- Forward the script arguments to the Redis command HSET.
|
46
|
-
-- Call the Redis command: HSET "#{Model.name}:id:#{id}" field value ...
|
47
|
-
redis.call('hset', key, unpack(ARGV))
|
48
|
-
|
49
|
-
-- Set TTL on key
|
50
|
-
if ttl and ttl ~= '-1' then
|
51
|
-
redis.call('expire', key, ttl)
|
52
|
-
end
|
53
|
-
|
54
|
-
-- Add id value for any index and range index attributes
|
55
|
-
local attrs_hash = to_hash(ARGV)
|
56
|
-
local index_attr_keys = redis.call('smembers', model .. ':index_attrs')
|
57
|
-
if #index_attr_keys > 0 then
|
58
|
-
for _, attr_key in ipairs(index_attr_keys) do
|
59
|
-
add_id_to_index_attr(model, attr_key, attrs_hash[attr_key], id)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
local range_index_attr_keys = redis.call('smembers', model .. ':range_index_attrs')
|
63
|
-
if #range_index_attr_keys > 0 then
|
64
|
-
for _, attr_key in ipairs(range_index_attr_keys) do
|
65
|
-
add_id_to_range_index_attr(model, attr_key, attrs_hash[attr_key], id)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
return id
|