I have the CLI open and a .NET dummy solution open. I would like to create a user and insert some data in one go. How in the CLI/REPL i wrote this
redis 127.0.0.1:6379> incr userCount
(integer) 1
redis 127.0.0.1:6379> set user:1:name acid
OK
redis 127.0.0.1:6379> set user:1:pw zombie
OK
Thats all fine but how do i do this in one go? It would be nice if i could get the userid at the end of the operation but really i don't need it for this example and i'd like to pipeline the 3 commands at once. How do i do that? Also maybe i should be doing it in a transaction? Also i probably should check if the name exist before inserting but I havent gotten that far yet.
using BookSleeve;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RedisEx
{
class Program
{
static void Main(string[] args)
{
using (var conn = new RedisConnection("localhost"))
{
conn.Open();
var userC = conn.Strings.Increment(1, "userCount");
var userid = conn.Wait(userC);
if (userid > 1)
{
var sz = conn.Wait(conn.Strings.GetString(1, string.Format("user:{0}:name", userid - 1)));
Console.WriteLine(sz);
}
conn.Strings.Set(1, string.Format("user:{0}:name", userid), "acid");
conn.Strings.Set(1, string.Format("user:{0}:pw", userid), "zombie");
}
}
}
}