Skip to content

Instantly share code, notes, and snippets.

View bateloche's full-sized avatar

João Bateloche bateloche

View GitHub Profile
@bateloche
bateloche / Program_Filter.cs
Created July 26, 2017 21:22
Program.cs with filter implementation
using System;
namespace RedisPublisher
{
class Program
{
private static RedisPubSub _pubSub;
private static string _channelName;
static void Main(string[] args)
@bateloche
bateloche / RedisPubSub.cs
Created July 26, 2017 21:16
PubSub connector with filters
using System;
using StackExchange.Redis;
using static StackExchange.Redis.RedisChannel;
namespace RedisPublisher
{
public class RedisPubSub
{
private readonly ConnectionMultiplexer _redis;
private readonly ISubscriber _subscriber;
@bateloche
bateloche / Program_PubSub.cs
Created July 26, 2017 20:24
PubSub example
using System;
namespace RedisPublisher
{
class Program
{
private static RedisPubSub _pubSub;
private static string _channelName;
static void Main(string[] args)
@bateloche
bateloche / SubscribeMethod.cs
Created July 26, 2017 19:22
Method to subscribe on Redis Channel
public void Subscribe(string channelName, Action<string, string> callback)
{
_subscriber.Subscribe(channelName,(channel, value)=>{
callback(channel.ToString(), value.ToString());
});
}
@bateloche
bateloche / RedisPublisher.cs
Created July 26, 2017 18:00
Publisher for Redis
using System;
namespace RedisPublisher
{
class Program
{
private static RedisPubSub _pubSub;
private static string _channelName;
static void Main(string[] args)
@bateloche
bateloche / RedisPubSub.cs
Created July 26, 2017 17:42
Abstraction for simple publishing on Redis
using System;
using StackExchange.Redis;
namespace RedisPublisher
{
public class RedisPubSub
{
private readonly ConnectionMultiplexer _redis;
private readonly ISubscriber _subscriber;
@bateloche
bateloche / Pessoa.cs
Created December 16, 2016 18:58
Entidade pessoa sem SRP
public class Pessoa
{
public string Nome {get; private set;}
public string Cpf {get; private set;}
public Pessoa(string nome, string cpf)
{
Nome = nome;
Cpf = cpf;
}
{
$lookup:
{
from: "Nome da coleção",
localField: "Nome do campo da coleção atual",
foreignField: "Campo de identificação na coleção do lookup",
as: "Nome do campo de saída"
}
}
db.Students.aggregate([{
$lookup: {
from: "Scores",
localField: "_id",
foreignField: "student",
as: "scores"
}
},{
$project: {
_id: false,
var scores = db.Scores.aggregate([
{ $group : { _id: "$student", finalScore: { $avg: "$score" } } },
{ $project: { average: { $avg: "$finalScore" } } }
]);
scores.forEach(function(score){
print({ student: db.Students.findOne({_id: score._id}).name, grade: score.average });
});