MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / RPushs

Method RPushs

structure/list.go:129–168  ·  view source on GitHub ↗

RPushs appends one or more values to the right side of a list associated with a key. If the key does not exist, it will be created.

(key string, ttl int64, values ...interface{})

Source from the content-addressed store, hash-verified

127// RPushs appends one or more values to the right side of a list associated with a key.
128// If the key does not exist, it will be created.
129func (l *ListStructure) RPushs(key string, ttl int64, values ...interface{}) error {
130 // Check if values are valid
131 if len(values) == 0 {
132 return ErrInvalidArgs
133 }
134
135 // Get the list
136 lst, _, err := l.getListFromDB(key, true)
137 if err != nil {
138 return err
139 }
140 var expirationTime time.Duration
141 // Find the last node
142 var lastNode *listNode
143 if lst.Length == 0 {
144 lastNode = nil
145 } else {
146 lastNode = lst.Head
147 for lastNode.Next != nil {
148 lastNode = lastNode.Next
149 }
150 }
151
152 for _, value := range values {
153 newNode := &listNode{
154 Value: value,
155 Next: nil,
156 }
157 if lastNode == nil {
158 lst.Head = newNode
159 } else {
160 lastNode.Next = newNode
161 }
162 lastNode = newNode
163 lst.Length++
164 }
165 expirationTime = time.Duration(ttl) * time.Second
166 // Store to db
167 return l.setListToDB(key, lst, expirationTime)
168}
169
170// LPop returns and removes the leftmost value of a list associated with a key.
171// If the key does not exist, an error is returned.

Callers

nothing calls this directly

Calls 2

getListFromDBMethod · 0.95
setListToDBMethod · 0.95

Tested by

no test coverage detected