Mercurial > demo / examples/db/cl-simple-example.lisp
changeset 35: |
f54f7cc7458b |
child: |
0f678bfd8699 |
author: |
ellis <ellis@rwest.io> |
date: |
Tue, 19 Dec 2023 16:46:55 -0500 |
permissions: |
-rw-r--r-- |
description: |
cl-simple-example implemented, init db/tao.lisp |
1 ;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/example/c_simple_example.c 3 ;; ref: https://github.com/facebook/rocksdb/blob/main/examples/c_simple_example.c 7 ;; To compile and run from the shell: 9 sbcl --eval '(ql:quickload :rdb)' \ 10 --eval '(ql:quickload :cli)' \ 11 --eval '(compile-file "cl-simple-example.lisp")' \ 12 --eval '(load "cl-simple-example.fasl")' \ 13 --eval "(sb-ext:save-lisp-and-die \"cl-simple-example\" :toplevel #'cl-simple-example::main :executable t)" 15 time ./cl-simple-example 21 gcc -lrocksdb c_simple_example.c -oc_simple_example 23 time ./c_simple_example 27 (defpackage :examples/rdb/cl-simple-example 28 (:nicknames :cl-simple-example) 29 (:use :cl :std :cli :rdb :sb-alien :rocksdb) 32 (rocksdb:load-rocksdb :save t) 34 (in-package :cl-simple-example) 38 (defvar *num-cpus* (alien-funcall (extern-alien "sysconf" (function long integer)) sb-unix:sc-nprocessors-onln) 41 (defparameter *db-path* "/tmp/rocksdb-cl-simple-example") 43 (defparameter *db-backup-path* "/tmp/rocksdb-cl-simple-example-backup") 46 ;; open Backup Engine that we will use for backing up our database 50 (rocksdb-options-increase-parallelism opt *num-cpus*) ;; set # of online cores 51 (rocksdb-options-optimize-level-style-compaction opt 0) 52 (rocksdb-options-set-create-if-missing opt 1))))) 53 (with-open-backup-engine-raw (be *db-backup-path* options) 55 (with-open-db-raw (db *db-path* options) 57 (put-kv-str-raw db "key" "value") 59 (string= (get-kv-str-raw db "key") "value") 60 ;; create new backup in a directory specified by *db-backup-path* 61 (create-new-backup-raw be db)) 62 ;; if something is wrong, you might want to restore data from last backup 63 (restore-from-latest-backup-raw be *db-path* *db-backup-path*))))