List (2)

이번 포스팅에서는 간략하게 레디스에 어떠한 타입이 있고 어떤 명령어로 해당 타입의 값을 추가 또는 조회하는 지 등의 예제를 보여드릴 겁니다.

레디스는 String, Hash, List, Set, Sorted Set 등의 데이터 타입을 지원합니다.


Strings (스트링)

레디스 스트링은 순차적인 바이트들입니다. 레디스에서 스트링은 binary safe한데 이것은 스트링이 알수있는 길이를 가지고 있고 어떤 특별한 종료문자에 의해 종료되지 않는 다는 것을 의미합니다. 따라서, 한 스트링당 최대 512MB 길이의 값을 저장할 수 있습니다.

Example (예제)

redis 127.0.0.1:6379> SET name "keichee" OK redis 127.0.0.1:6379> GET name "keichee"

위 예제에서 사용된 SET과 GET명령어는 데이터를 저장하거나 조회할 때 사용되는 명령어입니다.

그리고 name은 레디스에 저장할 때 키 값을 의미하며 "keichee"는 name이라는 키에 대응해서 저장될 값을 의미합니다.


Hashes (해쉬)

레디스 해쉬는 키-값 페어의 컬렉션입니다. 스트링 필드와 스트링 값을 매핑해주기 때문에 객체를 표현할 때 자주 사용됩니다.

Example

redis 127.0.0.1:6379> HMSET user:1 wow awesome keichee handsome blah handsome
OK
redis 127.0.0.1:6379> HGETALL user:1

1) "wow"
2) "awesome"
3) "keichee"
4) "handsome"
5) "blah"
6) "handsome"

위 예제에서 user:1 이라는 키에 wow, awesome, keichee, handsome, blah, handsome 이라는 값을 세팅하고 있습니다. 여기서 HMSET은 해쉬에 저장할 때, HGETALL 은 해쉬에 저장된 데이터를 조회할 때 사용되는 명령어입니다.

해쉬에 저장할 수 있는 키-값 페어의 개수는 총 (2^32) - 1 개 입니다.


Lists (리스트)

리스트는 목록형태의 데이터 타입을 말합니다. 스트링 목록을 말하며 삽입한 순서대로 정렬되어 저장됩니다. 

레디스 리스트는 제일 앞에 추가하는 것과 제일 마지막에 추가하는 명령어가 있습니다..

Example

redis 127.0.0.1:6379> lpush dblist redis
(integer) 1
redis 127.0.0.1:6379> lpush dblist mongodb
(integer) 2 redis 127.0.0.1:6379> lpush dblist rabitmq
(integer) 3 redis 127.0.0.1:6379> lrange dblist 0 10
1) "rabitmq" 2) "mongodb" 3) "redis"

리스트의 최대 길이는 (2^32) - 1 개 입니다. (총 4294967295 개).

lpush는 리스트의 제일 앞에 데이터를 추가하고자 할 때 사용하는 명령어입니다. 

lpush dblist redis 명령어는 dblist라는 이름의 리스트에 redis라는 값을 저장하라는 것을 의미합니다.

위 예제에서는 redis, mongodb, rabitmq를 dblist라는 리스트에 저장한 뒤 lrange 명령어를 이용하여 0부터 10까지의 데이터를 조회하고 있습니다.


Sets (집합)

레디스에서 집합은 정렬되지 않은 스트링 목록을 말합니다. 

세트는 추가, 삭제, 그리고 존재여부를 확인하는 명령어를 O(1) 시간복잡도로 제공합니다.

Example

redis 127.0.0.1:6379> sadd dbset redis
(integer) 1 redis 127.0.0.1:6379> sadd dbset mongodb (integer) 1 redis 127.0.0.1:6379> sadd dbset rabitmq (integer) 1 redis 127.0.0.1:6379> sadd dbset rabitmq (integer) 0 redis 127.0.0.1:6379> smembers dbset 1) "rabitmq" 2) "mongodb" 3) "redis"

NOTE: 위 예제에서 rabitmq는 두 번 추가가 되었지만 세트의 기본 속성인 유니크 속성 때문에 하나의 rabitmq만 저장됩니다.

sadd는 집합에 데이터를 추가할 때 쓰이는 명령어이며, 집합을 조회할 때에는 smembers 명령어를 사용하시면 됩니다.

조회되는 데이터는 집합에 추가된 순서와는 관계없이 랜덤하게 조회가 됩니다. 즉, 순서를 보장하지 않습니다.

set에 저장할 수 있는 데이터 개수 역시 (2^32) - 1 개입니다. 


Sorted Sets (정렬 집합)

정렬된 집합은 말그대로 집합인데 정렬된 것을 말합니다. 유니크 속성 역시 그대로 가지고 있으며. 일반 집합과의 차이점은 정렬을 위한 score 값을 가지고 있다는 것입니다.

Example

redis 127.0.0.1:6379> zadd sorted 0 redis (integer) 1 redis 127.0.0.1:6379> zadd sorted 0 mongodb (integer) 1 redis 127.0.0.1:6379> zadd sorted 0 rabitmq (integer) 1 redis 127.0.0.1:6379> zadd sorted 0 rabitmq (integer) 0 redis 127.0.0.1:6379> ZRANGEBYSCORE sorted 0 1000 1) "redis" 2) "mongodb" 3) "rabitmq"

위 예제에서 처럼 정렬집합에 데이터를 넣을때는 zadd 명령어를 사용하며 집합명 다음에 score(점수)를 명시해주는데,


이 점수는 각 데이터 마다 중복하여 사용될 수 있으며 중복된 점수를 갖는 데이터는 조회 시 순서가 보장되지 않습니다.


ZRANGEBYSCORE 명령어는 점수를 기준으로 집합을 조회 하라는 의미입니다.




이 외에도 스트링 기반의 비트맵(Bitmap)이나 하이퍼로그로그스(HyperLogLogs)와 같은 데이터 타입도 지원하고 있습니다. 


이러한 타입에 대해서 레디스 공식 문서에는 아래와 같이 설명을 하고 있습니다.

  • Bit arrays (or simply bitmaps): it is possible, using special commands, to handle String values like an array of bits: you can set and clear individual bits, count all the bits set to 1, find the first set or unset bit, and so forth.
스트링 값을 비트의 배열로 다루기 위한 특별한 명령어를 제공한다고 합니다. 각각의 비트를 세팅하거나 1로 세팅된 모든 비트의 개수를 구하거나 하는 등등의 기능을 제공합니다.
  • HyperLogLogs: this is a probabilistic data structure which is used in order to estimate the cardinality of a set. Don't be scared, it is simpler than it seems... See later in the HyperLogLog section of this tutorial.

통계학적 데이타 구조로 집합의 카디날리티를 측정하기 위해서 사용된다고 합니다. 생각보다 쉬우니까 사용하기를 두려워하지 말라고 하네요 ㅋㅋ


자세한 내용은 각각의 데이터 타입에 대한 개별 포스팅에서 확인하시기 바랍니다. ^-^


이상 케이치였습니다.


즐겁고 행복한 하루 되세요~



💻 Programming/CSS

[CSS] 14. Lists ( 리스트, 목록 )

이번에는 목록과 관련된 CSS속성에 대해서 알아보도록 하겠습니다. 

우선 어떤 속성들이 있는지 그놈들의 이름부터 한번 살펴봅시다. 

  • list-style-type 이건 목록 스타일, 예를 들면 숫자, 영문, 동그라미, 사각형 , 뭐 이런 것들을 설정하는 속성입니다. 

  • list-style-position 이건 목록이 인덴트 되어야 하는지를 결정하는 속성입니다. 하위 목록이냐 아니냐 뭐 이런거죠. 

  • list-style-image 목록 앞에 이미지를 보여주겠다는 겁니다. 단순한 숫자목록이나 기호목록이 싫다면 이걸 쓸 수도 있겠네요.

  • list-style 목록 관련 스타일을 한꺼번에 정의할 수 있게 해주는 속성이죠.

  • marker-offset 목록에서 마커(숫자, 동글라미 등등)와 텍스트 사이의 간격을 결정짓는 속성입니다.

이제 각 속성들을 어떻게 사용하는지 예제를 한번 볼까요?? 


The list-style-type Property:

list-style-type 속성은 뭐 목록에 보여지는 마커의 스타일을 변경하기위한 속성입니다. 

목록에는 크게 순서있는 목록과 순서없는 목록이 있죠.

 

다음은 순서없는 목록에서 사용할 수 있는 list-style-type의 속성값입니다. 

ValueDescription
noneNA
disc (default)A filled-in circle
circleAn empty circle
squareA filled-in square

 

다음은 순서있는 목록에서 사용되는 속성값입니다. 

ValueDescriptionExample
decimalNumber1,2,3,4,5
decimal-leading-zero0 before the number01, 02, 03, 04, 05
lower-alphaLowercase alphanumeric charactersa, b, c, d, e
upper-alphaUppercase alphanumeric charactersA, B, C, D, E
lower-romanLowercase Roman numeralsi, ii, iii, iv, v
upper-roman Uppercase Roman numeralsI, II, III, IV, V
lower-greek The marker is lower-greek alpha, beta, gamma
lower-latin The marker is lower-latin a, b, c, d, e
upper-latin The marker is upper-latin A, B, C, D, E
hebrew The marker is traditional Hebrew numbering  
armenian The marker is traditional Armenian numbering  
georgian The marker is traditional Georgian numbering  
cjk-ideographicThe marker is plain ideographic numbers 
hiraganaThe marker is hiraganaa, i, u, e, o, ka, ki
katakanaThe marker is katakanaA, I, U, E, O, KA, KI
hiragana-irohaThe marker is hiragana-irohai, ro, ha, ni, ho, he, to
katakana-irohaThe marker is katakana-irohaI, RO, HA, NI, HO, HE, TO

 

 

예제를 한번 볼까요. 

<ul style="list-style-type:circle;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ul style="list-style-type:square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style-type:decimal;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

<ol style="list-style-type:lower-alpha;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

<ol style="list-style-type:lower-roman;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

결과는 아래와 같습니다. 

  • Maths
  • Social Science
  • Physics
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics
  1. Maths
  2. Social Science
  3. Physics
  1. Maths
  2. Social Science
  3. Physics

 


The list-style-position Property:

list-style-position 속성은 bullet point를 포함하는 박스의 내부 또는 외부의 위치를 지정하는 속성입니다.

ValueDescription
noneNA
insideIf the text goes onto a second line, the text will wrap underneath the marker. It will also appear indented to where the text would have started if the list had a value of outside.
outsideIf the text goes onto a second line, the text will be aligned with the start of the first line (to the right of the bullet).

 

다음 예제를 보시죠.

<ul style="list-style-type:circle; list-stlye-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ul style="list-style-type:square;list-style-position:inside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style-type:decimal;list-stlye-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

<ol style="list-style-type:lower-alpha;list-style-position:inside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

결과는 아래와 같습니다.

  • Maths
  • Social Science
  • Physics
  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics
  1. Maths
  2. Social Science
  3. Physics

 


The list-style-image Property:

list-style-image 속성은 위에서 말씀드린 것처럼 이미지 파일을 소스로 지정하여 목록의 마커로 사용할 수 있게끔 해주는 속성입니다.  

 

다음 예제를 보시죠.

<ul>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol>
<li style="list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

결과는 아래와 같습니다. ( url에 어떤 이미지 소스의 경로가 들어가느냐에 따라 달라지는 결과입니다. ) 

  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics

 


The list-style Property:

다음 예제를 보시죠. 

<ul style="list-style: inside square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style: outside upper-alpha;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

결과는 아래와 같습니다.

  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics

 


The marker-offset Property:

이 속성은 IE 6, Netscape 7 이하에서는 지원하지 않는다는군요.

예제를 봅시다. 

<ul style="list-style: inside square; marker-offset:2em;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>

<ol style="list-style: outside upper-alpha; marker-offset:2cm;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>

 

결과는 아래와 같습니다.

  • Maths
  • Social Science
  • Physics
  1. Maths
  2. Social Science
  3. Physics

 

 

 

 

 

Reference : http://www.tutorialspoint.com/css/css_lists.htm