; ------------------------------------------------------------------- ; ; redis_manipulate.lisp ; ; Jan/08/2014 ; ------------------------------------------------------------------- (defun redis_socket_read_proc (stream key) (format stream "get ~a~c~c" key #\Cr #\Lf) (force-output stream) (let ( (line (read-line stream nil nil)) ) (if (string/= line "$-1" :start1 0 :end1 2 :start2 0 :end2 2) (progn (setf line (read-line stream nil nil)) (display_record_proc key line) ) ) ) ) ; ------------------------------------------------------------------- (defun redis_socket_write_proc (stream key json_str) ; (format t "~a~%" key) ; (format t "redis_socket_write_proc ~a~%" json_str) ; (format stream "*3~c~c" #\Cr #\Lf) (format stream "$3~c~c" #\Cr #\Lf) (format stream "set~c~c" #\Cr #\Lf) (format stream "$~a~c~c" (length key) #\Cr #\Lf) (format stream "~a~c~c" key #\Cr #\Lf) (format stream "$~a~c~c" (length json_str) #\Cr #\Lf) (format stream "~a~c~c" json_str #\Cr #\Lf) ) ; ------------------------------------------------------------------- (defun redis_socket_single_write_proc (stream key value) (let ( (name (gethash 'name value)) (population (gethash 'population value)) (date_mod (gethash 'date_mod value)) ) (let ( (unit_aa (make-hash-table)) ) (setf (gethash 'name unit_aa) name) (setf (gethash 'population unit_aa) population) (setf (gethash 'date_mod unit_aa) date_mod) (let ( (json_str_new (json:encode-json-to-string unit_aa)) ) ; (format t "~a~%" json_str_new) (redis_socket_write_proc stream key json_str_new) ) ) ) ) ; ------------------------------------------------------------------- ; [8-4-2]: (defun redis_update_exec_proc_s2 (stream key_in population_in str_json) (let ( (unit_aa (with-input-from-string (s str_json) (json:decode-json s))) ) (let ( (name (cdr (assoc :name unit_aa))) (population (cdr (assoc :population unit_aa))) (date_mod (cdr (assoc :date--mod unit_aa))) (today (get_current_date_proc)) ) (format t "~a ~a ~a ~a~%" key_in name population date_mod) (format t "~a ~a ~a ~a~%" key_in name population_in today) (setf (cdr (assoc :population unit_aa)) population_in) (setf (cdr (assoc :date--mod unit_aa)) today) (let ( (json_str_new (json:encode-json-to-string unit_aa)) ) (format t "redis_update_exec_proc_s2 ~a~%" json_str_new) (format t "~a~%" json_str_new) (redis_socket_write_proc stream key_in json_str_new) ) ) ) ) ; ------------------------------------------------------------------- ; [8-4]: (defun redis_update_exec_proc (stream key population line) (format t "redis_update_exec_proc ~a~%" line) (if (string/= line "VALUE" :start1 0 :end1 4 :start2 0 :end2 4) (redis_update_exec_proc_s2 stream key population line) ) ) ; ------------------------------------------------------------------- (defun redis_socket_update_proc (stream key population_in) (let ( (json_str "") ) (format stream "get ~a~c~c" key #\Cr #\Lf) (force-output stream) (let ( (line (read-line stream nil nil)) ) (if (string/= line "$-1" :start1 0 :end1 2 :start2 0 :end2 2) (progn (setf json_str (read-line stream nil nil)) (display_record_proc key json_str) (format t "*** check *** aaa ***~%") ; (redis_update_exec_proc stream key population_in json_str) ) ) ) (redis_update_exec_proc stream key population_in json_str) ; ) ) ; -------------------------------------------------------------------