Skip to content

Commit 6e4f77c

Browse files
lewispbjeremy
authored andcommitted
Add kredis_ordered_set for OrderedSet usage in models
1 parent 92cd3d4 commit 6e4f77c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/kredis/attributes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def kredis_unique_list(name, limit: nil, key: nil, typed: :string, config: :shar
5050
kredis_connection_with __method__, name, key, limit: limit, typed: typed, config: config, after_change: after_change
5151
end
5252

53+
def kredis_ordered_set(name, limit: nil, key: nil, typed: :string, config: :shared, after_change: nil)
54+
kredis_connection_with __method__, name, key, limit: limit, typed: typed, config: config, after_change: after_change
55+
end
56+
5357
def kredis_set(name, key: nil, typed: :string, config: :shared, after_change: nil)
5458
kredis_connection_with __method__, name, key, typed: typed, config: config, after_change: after_change
5559
end

test/attributes_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Person
1111
kredis_list :names_with_custom_key_via_lambda, key: ->(p) { "person:#{p.id}:names_customized" }
1212
kredis_list :names_with_custom_key_via_method, key: :generate_key
1313
kredis_unique_list :skills, limit: 2
14+
kredis_ordered_set :reading_list, limit: 2
1415
kredis_flag :special
1516
kredis_flag :temporary_special, expires_in: 1.second
1617
kredis_string :address
@@ -90,6 +91,11 @@ class AttributesTest < ActiveSupport::TestCase
9091
assert_equal %w[ racing photography ], @person.skills.elements
9192
end
9293

94+
test "ordered set" do
95+
@person.reading_list.prepend(%w[ rework shapeup remote ])
96+
assert_equal %w[ remote shapeup ], @person.reading_list.elements
97+
end
98+
9399
test "flag" do
94100
assert_not @person.special?
95101

0 commit comments

Comments
 (0)