Skip to content

Commit c6a9001

Browse files
author
Michael Hoisie
committed
Added basic commands
1 parent b6646df commit c6a9001

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

redis.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,89 @@ func (client *Client) Exists(key string) (bool, os.Error) {
282282
return res.(int) == 1, nil
283283
}
284284

285+
func (client *Client) Rename(src string, dst string) os.Error {
286+
cmd := fmt.Sprintf("RENAME %s %s\r\n", src, dst)
287+
288+
_, err := client.sendCommand(cmd)
289+
if err != nil {
290+
return err
291+
}
292+
return nil
293+
}
294+
295+
func (client *Client) Renamenx(src string, dst string) (bool, os.Error) {
296+
cmd := fmt.Sprintf("RENAMENX %s %s\r\n", src, dst)
297+
298+
res, err := client.sendCommand(cmd)
299+
if err != nil {
300+
return false, err
301+
}
302+
return res.(int) == 1, nil
303+
}
304+
305+
func (client *Client) Randomkey() (string, os.Error) {
306+
res, err := client.sendCommand("RANDOMKEY\r\n")
307+
if err != nil {
308+
return "", err
309+
}
310+
return res.(string), nil
311+
}
312+
313+
func (client *Client) Dbsize() (int64, os.Error) {
314+
res, err := client.sendCommand("DBSIZE\r\n")
315+
if err != nil {
316+
return -1, err
317+
}
318+
319+
return res.(int64), nil
320+
}
321+
322+
func (client *Client) Expire(key string, time int64) (bool, os.Error) {
323+
cmd := fmt.Sprintf("EXPIRE %s %d\r\n", key, time)
324+
res, err := client.sendCommand(cmd)
325+
326+
if err != nil {
327+
return false, err
328+
}
329+
330+
return res.(int64) == 1, nil
331+
}
332+
333+
func (client *Client) Ttl(key string) (int64, os.Error) {
334+
cmd := fmt.Sprintf("TTL %s\r\n", key)
335+
res, err := client.sendCommand(cmd)
336+
if err != nil {
337+
return -1, err
338+
}
339+
340+
return res.(int64), nil
341+
}
342+
343+
func (client *Client) Move(key string, dbnum int) (bool, os.Error) {
344+
cmd := fmt.Sprintf("MOVE %s %d\r\n", key, dbnum)
345+
res, err := client.sendCommand(cmd)
346+
347+
if err != nil {
348+
return false, err
349+
}
350+
351+
return res.(int) == 1, nil
352+
}
353+
354+
func (client *Client) Flush(all bool) os.Error {
355+
var cmd string
356+
if all {
357+
cmd = "FLUSHALL\r\n"
358+
} else {
359+
cmd = "FLUSHDB\r\n"
360+
}
361+
_, err := client.sendCommand(cmd)
362+
if err != nil {
363+
return err
364+
}
365+
return nil
366+
}
367+
285368
func (client *Client) Llen(name string) (int, os.Error) {
286369
cmd := fmt.Sprintf("LLEN %s\r\n", name)
287370
res, err := client.sendCommand(cmd)

0 commit comments

Comments
 (0)