Running pub sub using node and Redis

Running pub and sub using node with Redis as backend

https://gist.github.com/jignesh88/db0229865ad124c13891bd9fe9c34f1a.js

https://gist.github.com/jignesh88/9ea69cfdbba14157421f0b58ad555f31.js

Advertisements

Running rabbitMQ docker container

docker run -d –hostname my-rabbit –name rabbitmq -p 8080:15672 -p 5672:5672 rabbitmq:3-management

–host name – name of host

–name – name of container

— p – forward port from docker container to local machine

using reabbimq:3-management to access web console to manage rabbitMQ console

Running redis using docker container

docker run -it -d –name redis -p 6379:6379 -v $PWD/data:/data redis redis-server –appendonly yes

-v – to map local volume to container for persistence
–appendonly – for persistance

accessing container

docker exec -it redis /bin/bash

Few commands to run Docker containers

Installing docker on MAC

brew install docker

Get docker info

Docker info

Run Container with docker “hello world!”

docker run hello-world

docker run -it alpine  – run alpine distro of linux

docker run -it ubuntu – run ubuntu distro of Linux

Pull docker image from hub repository

docker pull [image name]:[tag]

docker pull [private registry url]/[image name]:tag – to pull from private docker registry

Login/logout from docker repository

Docker login – to login default repository

docker login URL – to login to private repository

docker logout – to logout

Docker image commands

FROM – Create docker image from base Docker image

RUN – run command in a docker container

WORKDIR – setup working directory

COPY – copy local content to docker image

LABEL – Add metadata to docker image, such as maintainer, version etc.

CMD – run Command when the docker image is built

Building docker image

docker image build . -t [image name]

docker image inspect [image name]

Push docker image to a registry

docker image push [image name]

Run docker container

Docker container run -it -p [localport]:[container port] -e [parameter name]=[param value] –rm –name [container name] -d –restart on-failure -v [local volume]:[container volume] -w [working directory inside container] [docker image name]

-it = enable to

-p = port two port separated by column localport:container port

-e = environment variable

–rm = remove inactive container

–name = [name] name the container

-d – detached mode

–restart on-failure – docker container restart automatically on failure

–env-file list – environment file list

-h –hostname container hostname

-i –interactive – keep STDIN open even if not attached

-l –label-list – set meta data on a container

 –label-file set

-m –memory memory limit

-P – published all exposed port to random ports

-u –user user name or UID

-v –volume bind mount a volume

-w –workdir working directory inside the container

List of docker images and container

docker images – to get a list of images

docker container ls – to get a list of containers

docker volumes ls – to get a list of volume

docker network ls – get a list of networks

Shrink docker container size

docker system prune – to remove unused containers

docker system prune -a – to remove containers as well as not used images

 

 

Filtering docker images

docker images | grep [filter]

docker images -f

-f, --filter value    Filter output based on conditions provided (default [])
                        - dangling=(true|false)
                        - label=<key> or label=<key>=<value>
                        - before=(<image-name>[:tag]|<image-id>|<image@digest>)
                        - since=(<image-name>[:tag]|<image-id>|<image@digest>)
                        - reference=(pattern of an image reference)

Adding existing directory to git

steps to add an existing directory to git

cd c:\directory
git init
git add .
git commit -m “init commit”
git remote add origin git@bitbucket.org:gitprojectname/reponame
git push origin master

Sequence with TSQL

We keep an unique column in every table in the database to have primary key clustered index created on it and mostly they are IDENTITY or ROWGUID. Have you ever faced a situation where you need to update a column with sequence number in an existing table or temp table? I will explain 4 different methods here to achieve the same.

SETUP:

CREATE TABLE #Employee
(Name varchar(100)
,Hiredate datetime
,Stat varchar(10))
INSERT INTO #Employee (Name, Hiredate, Stat)
VALUES ('Adams  Alex', '2001-01-01 00:00:00.000', 'Active')
, ('Brown   Barry', '2000-01-01 00:00:00.000', 'On Leave')
, ('Osako   Lee', '2009-06-11 00:00:00.000', 'Active')
, ('Kennson David', '1996-03-16 00:00:00.000', 'Has Tenure  ')
, ('Haire   Terry', '2001-11-15 00:00:00.000', 'On Leave')
, ('Smith   Sally', '1989-04-01 00:00:00.000', 'Active')
Method 01: (Using IDENTITY)

ALTER TABLE #Employee
ADD ID INT IDENTITY(1,1)
GO
SELECT * FROM #Employee
GO
--Droping the column for next examples
ALTER TABLE #Employee
drop column ID
Method 02: (Using local variable)

ALTER TABLE #Employee
ADD ID INT
GO
DECLARE @i INT = 0
UPDATE #Employee
SET @i = ID = @i + 1
SELECT * FROM #Employee
--OR--
GO
DECLARE @i INT = 0
UPDATE #Employee SET ID = NULL
UPDATE #Employee SET Id = @i , @i = @i + 1
SELECT * FROM #Employee
Method 03: (Using CTE)

UPDATE #Employee SET ID = NULL
;WITH CTE AS (
SELECT ROW_NUMBER() OVER(ORDER BY Hiredate) AS ID, Name FROM #Employee
)
UPDATE a
SET ID = b.ID
FROM #Employee a
INNER JOIN CTE b ON a.Name = b.name
SELECT * FROM #Employee
Method 04: (Using SEQUENCE)

UPDATE #Employee SET ID = NULL
GO
CREATE SEQUENCE idnum
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO CYCLE
GO
UPDATE #Employee
SET id = NEXT value FOR idnum
SELECT * FROM #Employee
GO
DROP SEQUENCE idnum --Droping the sequence