Mercurial > demo / examples/db/cl-simple-example.lisp
changeset 37: |
c6d0a37a046a |
parent: |
0f678bfd8699
|
child: |
8259376eee11 |
author: |
ellis <ellis@rwest.io> |
date: |
Sun, 24 Dec 2023 19:24:39 -0500 |
permissions: |
-rw-r--r-- |
description: |
mini-redis and vegadat |
1 ;;; cl-simple-example.lisp --- Common Lisp port of rocksdb/examples/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 25 gcc -lrocksdb c_simple_example.c -oc_simple_example 27 time ./c_simple_example 35 (defpackage :examples/cl-simple-example 36 (:use :cl :std :cli :rdb :sb-alien :rocksdb) 39 (in-package :exmaples/cl-simple-example) 40 (declaim (optimize (speed 3))) 42 (defvar *num-cpus* (alien-funcall (extern-alien "sysconf" (function int int)) sb-unix:sc-nprocessors-onln) 45 (defparameter *db-path* "/tmp/rocksdb-cl-simple-example") 47 (defparameter *db-backup-path* "/tmp/rocksdb-cl-simple-example-backup") 50 ;; open Backup Engine that we will use for backing up our database 51 (let ((options (make-rocksdb-options 53 (rocksdb-options-increase-parallelism opt *num-cpus*) ;; set # of online cores 54 (rocksdb-options-optimize-level-style-compaction opt 0) 55 (rocksdb-options-set-create-if-missing opt 1))))) 56 (with-open-backup-engine-raw (be *db-backup-path* options) 58 (with-open-db-raw (db *db-path* options) 60 (put-kv-str-raw db "key" "value") 62 (string= (get-kv-str-raw db "key") "value") 63 ;; create new backup in a directory specified by *db-backup-path* 64 (create-new-backup-raw be db)) 65 ;; if something is wrong, you might want to restore data from last backup 66 (restore-from-latest-backup-raw be *db-path* *db-backup-path*))))