1. Redis List 데이터 사용 샘플소스
- <?php
- $redis = new Redis();
- try {
- $redis->connect('127.0.0.1', 6379, 2.5);//2.5 sec timeout
- //Auth Password(redis.conf requirepass)
- //$redis->auth('foobared');
- } catch (Exception $e) {
- exit( "Cannot connect to redis server : ".$e->getMessage() );
- }
- // //DB Select
- if ( !$redis->select(0) ){
- exit( "NOT DB Select");
- }
- $redis->delete('weblog:ws1');
- //rPush 맨아래 배열로 입력
- $redis->rPush('weblog:ws1', 'log1');
- $redis->rPush('weblog:ws1', 'log2');
- $redis->rPush('weblog:ws1', 'log3');
- $redis->rPush('weblog:ws1', 'log4');
- //lPush 첫번째 배열로 입력
- $redis->lPush('weblog:ws1', 'log5');
- //0~2번까지배열 가져오기
- var_dump($redis->lRange('weblog:ws1', 0, 2));
- //전체배열데이터 가져오기
- var_dump($redis->lRange('weblog:ws1', 0, -1));
- ?>
2. Redis 들어있는 데이터
3. 추가명령어 메뉴얼참조
- https://github.com/nicolasff/phpredis#lists
blPop, brPop - Remove and get the first/last element in a list
brpoplpush - Pop a value from a list, push it to another list and return it
lIndex, lGet - Get an element from a list by its index
lInsert - Insert an element before or after another element in a list
lLen, lSize - Get the length/size of a list
lPop - Remove and get the first element in a list
lPush - Prepend one or multiple values to a list
lPushx - Prepend a value to a list, only if the list exists
lRange, lGetRange - Get a range of elements from a list
lRem, lRemove - Remove elements from a list
lSet - Set the value of an element in a list by its index
lTrim, listTrim - Trim a list to the specified range
rPop - Remove and get the last element in a list
rpoplpush - Remove the last element in a list, append it to another list and return it (redis >= 1.1)
rPush - Append one or multiple values to a list
rPushx - Append a value to a list, only if the list exists