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

Method RPush

structure/list.go:94–125  ·  view source on GitHub ↗

RPush adds a value to the right of the list corresponding to the key If the key does not exist, it will create the key

(key string, value interface{}, ttl int64)

Source from the content-addressed store, hash-verified

92// RPush adds a value to the right of the list corresponding to the key
93// If the key does not exist, it will create the key
94func (l *ListStructure) RPush(key string, value interface{}, ttl int64) error {
95 // Check if value is empty
96 if value == nil {
97 return ErrInvalidValue
98 }
99
100 // Get the list
101 lst, _, err := l.getListFromDB(key, true)
102 if err != nil {
103 return err
104 }
105 var expirationTime time.Duration
106 // Append the new data to the end
107 newNode := &listNode{
108 Value: value,
109 Next: nil,
110 }
111 if lst.Length == 0 {
112 lst.Head = newNode
113 } else {
114 // Find the last node
115 lastNode := lst.Head
116 for lastNode.Next != nil {
117 lastNode = lastNode.Next
118 }
119 lastNode.Next = newNode
120 }
121 lst.Length++
122 expirationTime = time.Duration(ttl) * time.Second
123 // Store to db
124 return l.setListToDB(key, lst, expirationTime)
125}
126
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.

Callers

nothing calls this directly

Calls 2

getListFromDBMethod · 0.95
setListToDBMethod · 0.95

Tested by

no test coverage detected