Skip to content

Commit

Permalink
Merge pull request #60 from mumez/feature/more-list-support
Browse files Browse the repository at this point in the history
More list API support
  • Loading branch information
mumez authored Jan 25, 2025
2 parents b732df9 + a26ca12 commit b93d9cb
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lInsert: aKey value: aValue after: pivot
^ self unifiedCommand: {
'LINSERT'.
aKey.
'AFTER'.
pivot.
aValue }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lInsert: aKey value: aValue before: pivot
^ self unifiedCommand: {
'LINSERT'.
aKey.
'BEFORE'.
pivot.
aValue }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
commands-lists
lMoveFrom: source removing: srcFromRightOrLeft to: destination adding: destToRightOrLeft
| srcRightOrLeft destRightOrLeft |
srcRightOrLeft := srcFromRightOrLeft
ifNil: [ 'RIGHT' ]
ifNotNil: [ srcFromRightOrLeft ]. "RIGHT or LEFT"
destRightOrLeft := destToRightOrLeft
ifNil: [ 'LEFT' ]
ifNotNil: [ destToRightOrLeft ]. "RIGHT or LEFT"
^ self unifiedCommand: {
'LMOVE'.
source.
destination.
srcRightOrLeft.
destRightOrLeft }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
commands-lists
lMoveFrom: source to: destination
^ self
lMoveFrom: source
removing: 'RIGHT'
to: destination
adding: 'LEFT'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
commands-lists
lPop: aKey count: count
^ self unifiedCommand: {
'LPOP'.
aKey.
count }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lPos: aKey value: value
^ self
lPos: aKey
value: value
rank: nil
count: nil
maxlen: nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lPos: aKey value: value count: count
^ self
lPos: aKey
value: value
rank: nil
count: count
maxlen: nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lPos: aKey value: value maxlen: maxlen
^ self
lPos: aKey
value: value
rank: nil
count: nil
maxlen: maxlen
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lPos: aKey value: value rank: rank
^ self
lPos: aKey
value: value
rank: rank
count: nil
maxlen: nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
commands-lists
lPos: aKey value: value rank: rank count: count maxlen: maxlen
| args |
args := {
'LPOS'.
aKey.
value } asOrderedCollection.
rank ifNotNil: [
args addAll: {
'RANK'.
rank } ].
count ifNotNil: [
args addAll: {
'COUNT'.
count } ].
maxlen ifNotNil: [
args addAll: {
'MAXLEN'.
maxlen } ].

^ self unifiedCommand: args
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
commands-lists
lPosBackward: aKey value: value maxlen: maxlen
^ self
lPos: aKey
value: value
rank: -1
count: nil
maxlen: maxlen
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
commands-lists
lPushx: aKey value: aValue
^ self
unifiedCommand: { 'LPUSHX'
. aKey
. aValue}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SystemOrganization addCategory: #'RediStick-Core'!
self packageOrganizer ensurePackage: #'RediStick-Core' withTags: #()!
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests
testLIndex
| listName elem |
listName := 'testLIndex'.
0 to: 4 do: [ :idx |
stick endpoint rPush: listName value: idx.
].

elem := stick endpoint lIndex: listName value: 2.
self assert: elem equals: '2'.

elem := stick endpoint lIndex: listName value: 4.
self assert: elem equals: '4'.

elem := stick endpoint lIndex: listName value: 10.
self assert: elem equals: nil.


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests
testLInsert
| listName elems1 elems2 |
listName := 'testLInsert'.
#('one' 'two' 'three') do: [ :each |
stick endpoint rPush: listName value: each.
].

stick endpoint lInsert: listName value: 'val1' after: 'two'.
elems1 := stick endpoint lRange: listName start: 0 end: -1.

self assertCollection: elems1 asArray equals: #('one' 'two' 'val1' 'three').

stick endpoint lInsert: listName value: 'val2' before: 'two'.
elems2 := stick endpoint lRange: listName start: 0 end: -1.

self assertCollection: elems2 asArray equals: #('one' 'val2' 'two' 'val1' 'three')

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tests
testLMove
| listName1 listName2 elems1 elems2 |
listName1 := 'testLMove1'.
1 to: 3 do: [ :idx |
stick endpoint rPush: listName1 value: idx.
].
listName2 := 'testLMove2'.
1 to: 3 do: [ :idx |
stick endpoint rPush: listName2 value: idx*10.
].

stick endpoint lMoveFrom: listName1 to: listName2.

elems1 := stick endpoint lRange: listName1 start: 0 end: -1.
elems2 := stick endpoint lRange: listName2 start: 0 end: -1.

self assertCollection: elems1 asArray equals: #('1' '2').
self assertCollection: elems2 asArray equals: #('3' '10' '20' '30').

stick endpoint lMoveFrom: listName2 removing: 'LEFT' to: listName1 adding: 'RIGHT'.

elems1 := stick endpoint lRange: listName1 start: 0 end: -1.
elems2 := stick endpoint lRange: listName2 start: 0 end: -1.

self assertCollection: elems1 asArray equals: #('1' '2' '3').
self assertCollection: elems2 asArray equals: #('10' '20' '30').
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
tests
testLPos
| listName pos positions |
listName := 'testLPos'.
0 to: 10 do: [ :idx |
stick endpoint rPush: listName value: idx.
].
0 to: 10 do: [ :idx |
stick endpoint rPush: listName value: idx.
].

pos := stick endpoint lPos: listName value: '2'.
self assert: pos equals: 2.

pos := stick endpoint lPosBackward: listName value: '2' maxlen: 10.
self assert: pos equals: 13.

pos := stick endpoint lPosBackward: listName value: '2' maxlen: 5.
self assert: pos isNil.

positions := stick endpoint lPos: listName value: '2' count: 0.
self assertCollection: positions asArray equals: #(2 13)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests
testLPushPop
| listName elem elems |
listName := 'testLPushPop'.
stick endpoint lPush: listName value: 'val1'.
stick endpoint lPush: listName value: 'val2'.
stick endpoint lPush: listName value: 'val3'.
elem := stick endpoint lPop: listName.
self assert: elem equals: 'val3'.

elems := stick endpoint lPop: listName count: 2.
self assertCollection: elems asArray equals: #('val2' 'val1').
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SystemOrganization addCategory: #'RediStick-Tests'!
self packageOrganizer ensurePackage: #'RediStick-Tests' withTags: #()!

0 comments on commit b93d9cb

Please sign in to comment.