1 module redis.commands.key;
2 
3 mixin template keyCommands()
4 {
5 	/*
6 	 * Removes the specified keys.
7 	 * @return The number of keys that were removed.
8 	 */
9 	int del(string...)(string args)
10 	{
11 		auto result = send!(int)("DEL",args);	
12 		return result;
13 	}
14 	/*
15 	 * Serialize the value stored at key in a Redis-specific format and return it to the user. 
16 	 * @return the serialized value.
17 	 */
18 	void dump(string key)
19 	{
20 		auto result = send("DUMP",key);
21 		//return null;
22 	}
23 	/*
24 	 * @return Returns if key exists.
25 	 */
26 	bool exists(string key)
27 	{
28 		auto result = send!(bool)("EXISTS",key);
29 		return result;
30 	}
31 	/*
32 	 * Set a timeout on key.
33 	 * @return
34 	 * 1 if the timeout was set.
35 	 * 0 if key does not exist or the timeout could not be set.
36 	 */
37 	int expire(string key,int timeout)
38 	{
39 		auto result = send!(int)("EXPIRE",key,timeout);
40 		return result;
41 	}
42 	/*
43 	 * Set a unixtime timeout on key.
44 	 * @return
45 	 * 1 if the timeout was set.
46 	 * 0 if key does not exist or the timeout could not be set.
47 	 */
48 	int expireat(string key,int timeout)
49 	{
50 		auto result = send!(int)("EXPIREAT",key,timeout);
51 		return result;
52 	}
53 	/*
54 	 * @return Returns all keys matching pattern.
55 	 */
56 	string[] keys(string pattern)
57 	{
58 		auto result = send("KEYS",pattern);
59 		//return result;
60 		debug(redis) { writeln(typeid(result),result,"type : ",result.type," value : ",result.value,);}
61 		return result.toStringArray;
62 	}
63 	/*
64 	 * Atomically transfer a key from a source Redis instance to a destination Redis instance. 
65 	 * @return The command returns OK on success, or NOKEY if no keys were found in the source instance.
66 	 */
67 	bool migrate(string...)(string host,string port,string args)
68 	{
69 		auto result = send!(bool)("MIGRATE",host,port,args);
70 		return result;
71 	}
72 	/*
73 	 * @return TTL in seconds, or a negative value in order to signal an error (see the description above).
74 	 */
75 	int ttl(string key)
76 	{
77 		auto result = send!(int)("TTL",key);
78 		return result;
79 	}
80 }