1 package redis
2
3 import (
4 "context"
5 "strings"
6 "time"
7 )
8
9 type ListCmdable interface {
10 BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
11 BLMPop(ctx context.Context, timeout time.Duration, direction string, count int64, keys ...string) *KeyValuesCmd
12 BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
13 BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd
14 LIndex(ctx context.Context, key string, index int64) *StringCmd
15 LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd
16 LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd
17 LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd
18 LLen(ctx context.Context, key string) *IntCmd
19 LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd
20 LPop(ctx context.Context, key string) *StringCmd
21 LPopCount(ctx context.Context, key string, count int) *StringSliceCmd
22 LPos(ctx context.Context, key string, value string, args LPosArgs) *IntCmd
23 LPosCount(ctx context.Context, key string, value string, count int64, args LPosArgs) *IntSliceCmd
24 LPush(ctx context.Context, key string, values ...interface{}) *IntCmd
25 LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
26 LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
27 LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd
28 LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd
29 LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
30 RPop(ctx context.Context, key string) *StringCmd
31 RPopCount(ctx context.Context, key string, count int) *StringSliceCmd
32 RPopLPush(ctx context.Context, source, destination string) *StringCmd
33 RPush(ctx context.Context, key string, values ...interface{}) *IntCmd
34 RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
35 LMove(ctx context.Context, source, destination, srcpos, destpos string) *StringCmd
36 BLMove(ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration) *StringCmd
37 }
38
39 func (c cmdable) BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd {
40 args := make([]interface{}, 1+len(keys)+1)
41 args[0] = "blpop"
42 for i, key := range keys {
43 args[1+i] = key
44 }
45 args[len(args)-1] = formatSec(ctx, timeout)
46 cmd := NewStringSliceCmd(ctx, args...)
47 cmd.setReadTimeout(timeout)
48 _ = c(ctx, cmd)
49 return cmd
50 }
51
52 func (c cmdable) BLMPop(ctx context.Context, timeout time.Duration, direction string, count int64, keys ...string) *KeyValuesCmd {
53 args := make([]interface{}, 3+len(keys), 6+len(keys))
54 args[0] = "blmpop"
55 args[1] = formatSec(ctx, timeout)
56 args[2] = len(keys)
57 for i, key := range keys {
58 args[3+i] = key
59 }
60 args = append(args, strings.ToLower(direction), "count", count)
61 cmd := NewKeyValuesCmd(ctx, args...)
62 cmd.setReadTimeout(timeout)
63 _ = c(ctx, cmd)
64 return cmd
65 }
66
67 func (c cmdable) BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd {
68 args := make([]interface{}, 1+len(keys)+1)
69 args[0] = "brpop"
70 for i, key := range keys {
71 args[1+i] = key
72 }
73 args[len(keys)+1] = formatSec(ctx, timeout)
74 cmd := NewStringSliceCmd(ctx, args...)
75 cmd.setReadTimeout(timeout)
76 _ = c(ctx, cmd)
77 return cmd
78 }
79
80 func (c cmdable) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd {
81 cmd := NewStringCmd(
82 ctx,
83 "brpoplpush",
84 source,
85 destination,
86 formatSec(ctx, timeout),
87 )
88 cmd.setReadTimeout(timeout)
89 _ = c(ctx, cmd)
90 return cmd
91 }
92
93 func (c cmdable) LIndex(ctx context.Context, key string, index int64) *StringCmd {
94 cmd := NewStringCmd(ctx, "lindex", key, index)
95 _ = c(ctx, cmd)
96 return cmd
97 }
98
99
100
101
102 func (c cmdable) LMPop(ctx context.Context, direction string, count int64, keys ...string) *KeyValuesCmd {
103 args := make([]interface{}, 2+len(keys), 5+len(keys))
104 args[0] = "lmpop"
105 args[1] = len(keys)
106 for i, key := range keys {
107 args[2+i] = key
108 }
109 args = append(args, strings.ToLower(direction), "count", count)
110 cmd := NewKeyValuesCmd(ctx, args...)
111 _ = c(ctx, cmd)
112 return cmd
113 }
114
115 func (c cmdable) LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd {
116 cmd := NewIntCmd(ctx, "linsert", key, op, pivot, value)
117 _ = c(ctx, cmd)
118 return cmd
119 }
120
121 func (c cmdable) LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd {
122 cmd := NewIntCmd(ctx, "linsert", key, "before", pivot, value)
123 _ = c(ctx, cmd)
124 return cmd
125 }
126
127 func (c cmdable) LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd {
128 cmd := NewIntCmd(ctx, "linsert", key, "after", pivot, value)
129 _ = c(ctx, cmd)
130 return cmd
131 }
132
133 func (c cmdable) LLen(ctx context.Context, key string) *IntCmd {
134 cmd := NewIntCmd(ctx, "llen", key)
135 _ = c(ctx, cmd)
136 return cmd
137 }
138
139 func (c cmdable) LPop(ctx context.Context, key string) *StringCmd {
140 cmd := NewStringCmd(ctx, "lpop", key)
141 _ = c(ctx, cmd)
142 return cmd
143 }
144
145 func (c cmdable) LPopCount(ctx context.Context, key string, count int) *StringSliceCmd {
146 cmd := NewStringSliceCmd(ctx, "lpop", key, count)
147 _ = c(ctx, cmd)
148 return cmd
149 }
150
151 type LPosArgs struct {
152 Rank, MaxLen int64
153 }
154
155 func (c cmdable) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd {
156 args := []interface{}{"lpos", key, value}
157 if a.Rank != 0 {
158 args = append(args, "rank", a.Rank)
159 }
160 if a.MaxLen != 0 {
161 args = append(args, "maxlen", a.MaxLen)
162 }
163
164 cmd := NewIntCmd(ctx, args...)
165 _ = c(ctx, cmd)
166 return cmd
167 }
168
169 func (c cmdable) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd {
170 args := []interface{}{"lpos", key, value, "count", count}
171 if a.Rank != 0 {
172 args = append(args, "rank", a.Rank)
173 }
174 if a.MaxLen != 0 {
175 args = append(args, "maxlen", a.MaxLen)
176 }
177 cmd := NewIntSliceCmd(ctx, args...)
178 _ = c(ctx, cmd)
179 return cmd
180 }
181
182 func (c cmdable) LPush(ctx context.Context, key string, values ...interface{}) *IntCmd {
183 args := make([]interface{}, 2, 2+len(values))
184 args[0] = "lpush"
185 args[1] = key
186 args = appendArgs(args, values)
187 cmd := NewIntCmd(ctx, args...)
188 _ = c(ctx, cmd)
189 return cmd
190 }
191
192 func (c cmdable) LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd {
193 args := make([]interface{}, 2, 2+len(values))
194 args[0] = "lpushx"
195 args[1] = key
196 args = appendArgs(args, values)
197 cmd := NewIntCmd(ctx, args...)
198 _ = c(ctx, cmd)
199 return cmd
200 }
201
202 func (c cmdable) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd {
203 cmd := NewStringSliceCmd(
204 ctx,
205 "lrange",
206 key,
207 start,
208 stop,
209 )
210 _ = c(ctx, cmd)
211 return cmd
212 }
213
214 func (c cmdable) LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd {
215 cmd := NewIntCmd(ctx, "lrem", key, count, value)
216 _ = c(ctx, cmd)
217 return cmd
218 }
219
220 func (c cmdable) LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd {
221 cmd := NewStatusCmd(ctx, "lset", key, index, value)
222 _ = c(ctx, cmd)
223 return cmd
224 }
225
226 func (c cmdable) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd {
227 cmd := NewStatusCmd(
228 ctx,
229 "ltrim",
230 key,
231 start,
232 stop,
233 )
234 _ = c(ctx, cmd)
235 return cmd
236 }
237
238 func (c cmdable) RPop(ctx context.Context, key string) *StringCmd {
239 cmd := NewStringCmd(ctx, "rpop", key)
240 _ = c(ctx, cmd)
241 return cmd
242 }
243
244 func (c cmdable) RPopCount(ctx context.Context, key string, count int) *StringSliceCmd {
245 cmd := NewStringSliceCmd(ctx, "rpop", key, count)
246 _ = c(ctx, cmd)
247 return cmd
248 }
249
250 func (c cmdable) RPopLPush(ctx context.Context, source, destination string) *StringCmd {
251 cmd := NewStringCmd(ctx, "rpoplpush", source, destination)
252 _ = c(ctx, cmd)
253 return cmd
254 }
255
256 func (c cmdable) RPush(ctx context.Context, key string, values ...interface{}) *IntCmd {
257 args := make([]interface{}, 2, 2+len(values))
258 args[0] = "rpush"
259 args[1] = key
260 args = appendArgs(args, values)
261 cmd := NewIntCmd(ctx, args...)
262 _ = c(ctx, cmd)
263 return cmd
264 }
265
266 func (c cmdable) RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd {
267 args := make([]interface{}, 2, 2+len(values))
268 args[0] = "rpushx"
269 args[1] = key
270 args = appendArgs(args, values)
271 cmd := NewIntCmd(ctx, args...)
272 _ = c(ctx, cmd)
273 return cmd
274 }
275
276 func (c cmdable) LMove(ctx context.Context, source, destination, srcpos, destpos string) *StringCmd {
277 cmd := NewStringCmd(ctx, "lmove", source, destination, srcpos, destpos)
278 _ = c(ctx, cmd)
279 return cmd
280 }
281
282 func (c cmdable) BLMove(
283 ctx context.Context, source, destination, srcpos, destpos string, timeout time.Duration,
284 ) *StringCmd {
285 cmd := NewStringCmd(ctx, "blmove", source, destination, srcpos, destpos, formatSec(ctx, timeout))
286 cmd.setReadTimeout(timeout)
287 _ = c(ctx, cmd)
288 return cmd
289 }
290
View as plain text